diff --git a/cmd/src/debug_compose.go b/cmd/src/debug_compose.go index 9fb764f78a..8bc3b01095 100644 --- a/cmd/src/debug_compose.go +++ b/cmd/src/debug_compose.go @@ -9,12 +9,11 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "github.com/sourcegraph/sourcegraph/lib/errors" - "golang.org/x/sync/errgroup" - "golang.org/x/sync/semaphore" ) @@ -42,9 +41,9 @@ Examples: flagSet := flag.NewFlagSet("compose", flag.ExitOnError) var base string - var noConfigs bool + var excludeConfigs bool flagSet.StringVar(&base, "o", "debug.zip", "The name of the output zip archive") - flagSet.BoolVar(&noConfigs, "no-configs", false, "If true include Sourcegraph configuration files. Default value true.") + flagSet.BoolVar(&excludeConfigs, "no-configs", false, "If true, exclude Sourcegraph configuration files. Defaults to false.") handler := func(args []string) error { if err := flagSet.Parse(args); err != nil { @@ -81,7 +80,7 @@ Examples: return nil } - err = archiveCompose(ctx, zw, *verbose, noConfigs, baseDir) + err = archiveCompose(ctx, zw, *verbose, !excludeConfigs, baseDir) if err != nil { return err } @@ -98,7 +97,7 @@ Examples: } // writes archive of common docker cli commands -func archiveCompose(ctx context.Context, zw *zip.Writer, verbose, noConfigs bool, baseDir string) error { +func archiveCompose(ctx context.Context, zw *zip.Writer, verbose, archiveConfigs bool, baseDir string) error { ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -114,7 +113,7 @@ func archiveCompose(ctx context.Context, zw *zip.Writer, verbose, noConfigs bool // setup channel for slice of archive function outputs ch := make(chan *archiveFile) g, ctx := errgroup.WithContext(ctx) - semaphore := semaphore.NewWeighted(8) + semaphore := semaphore.NewWeighted(int64(runtime.GOMAXPROCS(0))) run := func(f func() *archiveFile) { g.Go(func() error { @@ -150,7 +149,7 @@ func archiveCompose(ctx context.Context, zw *zip.Writer, verbose, noConfigs bool } // start goroutine to get configs - if !noConfigs { + if archiveConfigs { run(func() *archiveFile { return getExternalServicesConfig(ctx, baseDir) }) run(func() *archiveFile { return getSiteConfig(ctx, baseDir) }) diff --git a/cmd/src/debug_kube.go b/cmd/src/debug_kube.go index 9e3dfdaf7e..69af7571e9 100644 --- a/cmd/src/debug_kube.go +++ b/cmd/src/debug_kube.go @@ -10,18 +10,19 @@ import ( "log" "os" "path/filepath" + "runtime" + "github.com/sourcegraph/sourcegraph/lib/errors" "golang.org/x/sync/errgroup" - "golang.org/x/sync/semaphore" - "github.com/sourcegraph/sourcegraph/lib/errors" "github.com/sourcegraph/src-cli/internal/exec" ) func init() { usage := ` 'src debug kube' invokes kubectl diagnostic commands targeting kubectl's current-context, writing returns to an archive. + Usage: src debug kube [command options] @@ -45,10 +46,10 @@ Examples: flagSet := flag.NewFlagSet("kube", flag.ExitOnError) var base string var namespace string - var noConfigs bool + var excludeConfigs bool flagSet.StringVar(&base, "o", "debug.zip", "The name of the output zip archive") flagSet.StringVar(&namespace, "n", "default", "The namespace passed to kubectl commands, if not specified the 'default' namespace is used") - flagSet.BoolVar(&noConfigs, "no-configs", false, "If true include Sourcegraph configuration files. Default value true.") + flagSet.BoolVar(&excludeConfigs, "no-configs", false, "If true, exclude Sourcegraph configuration files. Defaults to false.") handler := func(args []string) error { if err := flagSet.Parse(args); err != nil { @@ -88,7 +89,7 @@ Examples: return nil } - err = archiveKube(ctx, zw, *verbose, noConfigs, namespace, baseDir, pods) + err = archiveKube(ctx, zw, *verbose, !excludeConfigs, namespace, baseDir, pods) if err != nil { return err } @@ -118,7 +119,7 @@ type podList struct { } // Runs common kubectl functions and archive results to zip file -func archiveKube(ctx context.Context, zw *zip.Writer, verbose, noConfigs bool, namespace, baseDir string, pods podList) error { +func archiveKube(ctx context.Context, zw *zip.Writer, verbose, archiveConfigs bool, namespace, baseDir string, pods podList) error { // Create a context with a cancel function that we call when returning // from archiveKube. This ensures we close all pending go-routines when returning // early because of an error. @@ -128,7 +129,7 @@ func archiveKube(ctx context.Context, zw *zip.Writer, verbose, noConfigs bool, n // setup channel for slice of archive function outputs, as well as throttling semaphore ch := make(chan *archiveFile) g, ctx := errgroup.WithContext(ctx) - semaphore := semaphore.NewWeighted(8) + semaphore := semaphore.NewWeighted(int64(runtime.GOMAXPROCS(0))) run := func(f func() *archiveFile) { g.Go(func() error { @@ -198,7 +199,7 @@ func archiveKube(ctx context.Context, zw *zip.Writer, verbose, noConfigs bool, n } // start goroutine to get external service config - if !noConfigs { + if archiveConfigs { run(func() *archiveFile { return getExternalServicesConfig(ctx, baseDir) }) run(func() *archiveFile { return getSiteConfig(ctx, baseDir) }) diff --git a/cmd/src/debug_server.go b/cmd/src/debug_server.go index 4705ce2c1e..8ef59fc02a 100644 --- a/cmd/src/debug_server.go +++ b/cmd/src/debug_server.go @@ -8,11 +8,11 @@ import ( "log" "os" "path/filepath" + "runtime" + "github.com/sourcegraph/sourcegraph/lib/errors" "golang.org/x/sync/errgroup" "golang.org/x/sync/semaphore" - - "github.com/sourcegraph/sourcegraph/lib/errors" ) func init() { @@ -40,10 +40,10 @@ Examples: flagSet := flag.NewFlagSet("server", flag.ExitOnError) var base string var container string - var noConfigs bool + var excludeConfigs bool flagSet.StringVar(&base, "o", "debug.zip", "The name of the output zip archive") flagSet.StringVar(&container, "c", "", "The container to target") - flagSet.BoolVar(&noConfigs, "no-configs", false, "If true include Sourcegraph configuration files. Default value true.") + flagSet.BoolVar(&excludeConfigs, "no-configs", false, "If true, exclude Sourcegraph configuration files. Defaults to false.") handler := func(args []string) error { if err := flagSet.Parse(args); err != nil { @@ -77,7 +77,7 @@ Examples: return nil } - err = archiveServ(ctx, zw, *verbose, noConfigs, container, baseDir) + err = archiveServ(ctx, zw, *verbose, !excludeConfigs, container, baseDir) if err != nil { return err } @@ -94,14 +94,14 @@ Examples: } // Runs common docker cli commands on a single container -func archiveServ(ctx context.Context, zw *zip.Writer, verbose, noConfigs bool, container, baseDir string) error { +func archiveServ(ctx context.Context, zw *zip.Writer, verbose, archiveConfigs bool, container, baseDir string) error { ctx, cancel := context.WithCancel(ctx) defer cancel() // setup channel for slice of archive function outputs ch := make(chan *archiveFile) g, ctx := errgroup.WithContext(ctx) - semaphore := semaphore.NewWeighted(8) + semaphore := semaphore.NewWeighted(int64(runtime.GOMAXPROCS(0))) run := func(f func() *archiveFile) { g.Go(func() error { @@ -128,7 +128,7 @@ func archiveServ(ctx context.Context, zw *zip.Writer, verbose, noConfigs bool, c run(func() *archiveFile { return getServTop(ctx, container, baseDir) }) // start goroutine to get configs - if !noConfigs { + if archiveConfigs { run(func() *archiveFile { return getExternalServicesConfig(ctx, baseDir) }) run(func() *archiveFile { return getSiteConfig(ctx, baseDir) })