From 461ad1c5b8f1c63846b55705b9f273da68ab57a7 Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Fri, 13 May 2022 14:08:48 -0500 Subject: [PATCH 1/5] Make boolean flag consistent. --- cmd/src/debug_compose.go | 10 +++++----- cmd/src/debug_kube.go | 10 +++++----- cmd/src/debug_server.go | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cmd/src/debug_compose.go b/cmd/src/debug_compose.go index 9fb764f78a..fc905ec8a5 100644 --- a/cmd/src/debug_compose.go +++ b/cmd/src/debug_compose.go @@ -42,9 +42,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, include Sourcegraph configuration files. Defaults to false.") handler := func(args []string) error { if err := flagSet.Parse(args); err != nil { @@ -81,7 +81,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 +98,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() @@ -150,7 +150,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..6f6057e18c 100644 --- a/cmd/src/debug_kube.go +++ b/cmd/src/debug_kube.go @@ -45,10 +45,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, include Sourcegraph configuration files. Defaults to false.") handler := func(args []string) error { if err := flagSet.Parse(args); err != nil { @@ -88,7 +88,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 +118,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. @@ -198,7 +198,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..9b3100f86c 100644 --- a/cmd/src/debug_server.go +++ b/cmd/src/debug_server.go @@ -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, include 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,7 +94,7 @@ 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() @@ -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) }) From 656391e9976b2d684cf1f8bc2a389f3074202345 Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Fri, 13 May 2022 14:09:13 -0500 Subject: [PATCH 2/5] Regroup imports. --- cmd/src/debug_compose.go | 2 -- cmd/src/debug_kube.go | 3 +-- cmd/src/debug_server.go | 3 +-- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/cmd/src/debug_compose.go b/cmd/src/debug_compose.go index fc905ec8a5..b409348549 100644 --- a/cmd/src/debug_compose.go +++ b/cmd/src/debug_compose.go @@ -12,9 +12,7 @@ import ( "strings" "github.com/sourcegraph/sourcegraph/lib/errors" - "golang.org/x/sync/errgroup" - "golang.org/x/sync/semaphore" ) diff --git a/cmd/src/debug_kube.go b/cmd/src/debug_kube.go index 6f6057e18c..6682aa83b1 100644 --- a/cmd/src/debug_kube.go +++ b/cmd/src/debug_kube.go @@ -11,11 +11,10 @@ import ( "os" "path/filepath" + "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" ) diff --git a/cmd/src/debug_server.go b/cmd/src/debug_server.go index 9b3100f86c..0e12956703 100644 --- a/cmd/src/debug_server.go +++ b/cmd/src/debug_server.go @@ -9,10 +9,9 @@ import ( "os" "path/filepath" + "github.com/sourcegraph/sourcegraph/lib/errors" "golang.org/x/sync/errgroup" "golang.org/x/sync/semaphore" - - "github.com/sourcegraph/sourcegraph/lib/errors" ) func init() { From 1b0836b8820a31284b6518e6017fff2c1e837cfb Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Fri, 13 May 2022 14:10:26 -0500 Subject: [PATCH 3/5] Fix docstring. --- cmd/src/debug_compose.go | 2 +- cmd/src/debug_kube.go | 2 +- cmd/src/debug_server.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/src/debug_compose.go b/cmd/src/debug_compose.go index b409348549..b6fb9aeee2 100644 --- a/cmd/src/debug_compose.go +++ b/cmd/src/debug_compose.go @@ -42,7 +42,7 @@ Examples: var base string var excludeConfigs bool flagSet.StringVar(&base, "o", "debug.zip", "The name of the output zip archive") - flagSet.BoolVar(&excludeConfigs, "no-configs", false, "If true, include Sourcegraph configuration files. Defaults to false.") + 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 { diff --git a/cmd/src/debug_kube.go b/cmd/src/debug_kube.go index 6682aa83b1..d507bee294 100644 --- a/cmd/src/debug_kube.go +++ b/cmd/src/debug_kube.go @@ -47,7 +47,7 @@ Examples: 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(&excludeConfigs, "no-configs", false, "If true, include Sourcegraph configuration files. Defaults to false.") + 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 { diff --git a/cmd/src/debug_server.go b/cmd/src/debug_server.go index 0e12956703..99f1c48e45 100644 --- a/cmd/src/debug_server.go +++ b/cmd/src/debug_server.go @@ -42,7 +42,7 @@ Examples: 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(&excludeConfigs, "no-configs", false, "If true, include Sourcegraph configuration files. Defaults to false.") + 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 { From df58c674d9f303e6852d077b9d38c3c62efb2d1b Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Fri, 13 May 2022 14:11:38 -0500 Subject: [PATCH 4/5] Update size of semaphores. --- cmd/src/debug_compose.go | 3 ++- cmd/src/debug_kube.go | 3 ++- cmd/src/debug_server.go | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/src/debug_compose.go b/cmd/src/debug_compose.go index b6fb9aeee2..8bc3b01095 100644 --- a/cmd/src/debug_compose.go +++ b/cmd/src/debug_compose.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "strings" "github.com/sourcegraph/sourcegraph/lib/errors" @@ -112,7 +113,7 @@ func archiveCompose(ctx context.Context, zw *zip.Writer, verbose, archiveConfigs // 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 { diff --git a/cmd/src/debug_kube.go b/cmd/src/debug_kube.go index d507bee294..a7cdb28c44 100644 --- a/cmd/src/debug_kube.go +++ b/cmd/src/debug_kube.go @@ -10,6 +10,7 @@ import ( "log" "os" "path/filepath" + "runtime" "github.com/sourcegraph/sourcegraph/lib/errors" "golang.org/x/sync/errgroup" @@ -127,7 +128,7 @@ func archiveKube(ctx context.Context, zw *zip.Writer, verbose, archiveConfigs bo // 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 { diff --git a/cmd/src/debug_server.go b/cmd/src/debug_server.go index 99f1c48e45..8ef59fc02a 100644 --- a/cmd/src/debug_server.go +++ b/cmd/src/debug_server.go @@ -8,6 +8,7 @@ import ( "log" "os" "path/filepath" + "runtime" "github.com/sourcegraph/sourcegraph/lib/errors" "golang.org/x/sync/errgroup" @@ -100,7 +101,7 @@ func archiveServ(ctx context.Context, zw *zip.Writer, verbose, archiveConfigs bo // 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 { From 83109fecd0478fd2cf3bb3c3b2fd3e48cb6d2c30 Mon Sep 17 00:00:00 2001 From: Eric Fritz Date: Fri, 13 May 2022 14:12:17 -0500 Subject: [PATCH 5/5] Add newline. --- cmd/src/debug_kube.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/src/debug_kube.go b/cmd/src/debug_kube.go index a7cdb28c44..69af7571e9 100644 --- a/cmd/src/debug_kube.go +++ b/cmd/src/debug_kube.go @@ -22,6 +22,7 @@ import ( 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]