diff --git a/MODULE.bazel b/MODULE.bazel index ad3dff060d94..1377d9cddc80 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -185,6 +185,7 @@ use_repo( "com_github_docker_go_connections", "com_github_docker_go_units", "com_github_fatih_color", + "com_github_google_uuid", "com_github_hamba_avro", "com_github_hamba_avro_v2", "com_github_hashicorp_go_multierror", diff --git a/src/go/rpk/go.mod b/src/go/rpk/go.mod index 62668de279bd..70f6c177b64c 100644 --- a/src/go/rpk/go.mod +++ b/src/go/rpk/go.mod @@ -23,6 +23,7 @@ require ( github.com/docker/go-connections v0.5.0 github.com/docker/go-units v0.5.0 github.com/fatih/color v1.18.0 + github.com/google/uuid v1.6.0 github.com/hamba/avro/v2 v2.27.0 github.com/hashicorp/go-multierror v1.1.1 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 @@ -94,7 +95,6 @@ require ( github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect diff --git a/src/go/rpk/pkg/adminapi/admin.go b/src/go/rpk/pkg/adminapi/admin.go index 8c67799a932e..2fa82f9ae41f 100644 --- a/src/go/rpk/pkg/adminapi/admin.go +++ b/src/go/rpk/pkg/adminapi/admin.go @@ -21,14 +21,12 @@ import ( "github.com/kr/text" mTerm "github.com/moby/term" - - "go.uber.org/zap" - "github.com/redpanda-data/common-go/rpadmin" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/oauth/providers/auth0" "github.com/spf13/afero" + "go.uber.org/zap" ) // GenericErrorBody is the JSON decodable body that is produced by generic error diff --git a/src/go/rpk/pkg/cli/debug/BUILD b/src/go/rpk/pkg/cli/debug/BUILD index f939904cb81f..5626b2b1ca1f 100644 --- a/src/go/rpk/pkg/cli/debug/BUILD +++ b/src/go/rpk/pkg/cli/debug/BUILD @@ -10,6 +10,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//src/go/rpk/pkg/cli/debug/bundle", + "//src/go/rpk/pkg/cli/debug/remotebundle", "//src/go/rpk/pkg/config", "@com_github_spf13_afero//:afero", "@com_github_spf13_cobra//:cobra", diff --git a/src/go/rpk/pkg/cli/debug/bundle/BUILD b/src/go/rpk/pkg/cli/debug/bundle/BUILD index 47f47f7a8eab..569dd675b2bd 100644 --- a/src/go/rpk/pkg/cli/debug/bundle/BUILD +++ b/src/go/rpk/pkg/cli/debug/bundle/BUILD @@ -11,6 +11,7 @@ go_library( importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/bundle", visibility = ["//visibility:public"], deps = [ + "//src/go/rpk/pkg/cli/debug/common", "//src/go/rpk/pkg/config", "//src/go/rpk/pkg/httpapi", "//src/go/rpk/pkg/kafka", diff --git a/src/go/rpk/pkg/cli/debug/bundle/bundle.go b/src/go/rpk/pkg/cli/debug/bundle/bundle.go index d58d545d4825..922cbf70ca9b 100644 --- a/src/go/rpk/pkg/cli/debug/bundle/bundle.go +++ b/src/go/rpk/pkg/cli/debug/bundle/bundle.go @@ -18,6 +18,7 @@ import ( "time" "github.com/docker/go-units" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/common" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/httpapi" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/kafka" @@ -59,20 +60,8 @@ func NewCommand(fs afero.Fs, p *config.Params) *cobra.Command { var ( outFile string uploadURL string - - logsSince string - logsUntil string - logsSizeLimit string - - controllerLogsSizeLimit string - namespace string - labelSelector []string - partitionFlag []string - - timeout time.Duration - metricsInterval time.Duration - metricsSampleCount int - cpuProfilerWait time.Duration + timeout time.Duration + opts common.DebugBundleSharedOptions ) cmd := &cobra.Command{ Use: "bundle", @@ -83,11 +72,11 @@ func NewCommand(fs afero.Fs, p *config.Params) *cobra.Command { // Redpanda queries for samples from Seastar every ~13 seconds by // default. Setting wait_ms to anything less than 13 seconds will // result in no samples being returned. - if cpuProfilerWait < 15*time.Second { + if opts.CPUProfilerWait < 15*time.Second { out.Die("--cpu-profiler-wait must be higher than 15 seconds") } - if metricsSampleCount < 2 { + if opts.MetricsSampleCount < 2 { out.Die("--metrics-samples must be 2 or higher") } @@ -108,17 +97,17 @@ func NewCommand(fs afero.Fs, p *config.Params) *cobra.Command { path, err := determineFilepath(fs, yActual, outFile, cmd.Flags().Changed(outputFlag)) out.MaybeDie(err, "unable to determine filepath %q: %v", outFile, err) - partitions, err := parsePartitionFlag(partitionFlag) - out.MaybeDie(err, "unable to parse partition flag %v: %v", partitionFlag, err) + partitions, err := parsePartitionFlag(opts.PartitionFlag) + out.MaybeDie(err, "unable to parse partition flag %v: %v", opts.PartitionFlag, err) cl, err := kafka.NewFranzClient(fs, p) out.MaybeDie(err, "unable to initialize kafka client: %v", err) defer cl.Close() - logsLimit, err := units.FromHumanSize(logsSizeLimit) + logsLimit, err := units.FromHumanSize(opts.LogsSizeLimit) out.MaybeDie(err, "unable to parse --logs-size-limit: %v", err) - controllerLogsLimit, err := units.FromHumanSize(controllerLogsSizeLimit) + controllerLogsLimit, err := units.FromHumanSize(opts.ControllerLogsSizeLimit) out.MaybeDie(err, "unable to parse --controller-logs-size-limit: %v", err) bp := bundleParams{ fs: fs, @@ -126,20 +115,20 @@ func NewCommand(fs afero.Fs, p *config.Params) *cobra.Command { y: y, yActual: yActual, cl: cl, - logsSince: logsSince, - logsUntil: logsUntil, path: path, - namespace: namespace, logsLimitBytes: int(logsLimit), controllerLogLimitBytes: int(controllerLogsLimit), timeout: timeout, - metricsInterval: metricsInterval, - metricsSampleCount: metricsSampleCount, partitions: partitions, - cpuProfilerWait: cpuProfilerWait, + namespace: opts.Namespace, + logsSince: opts.LogsSince, + logsUntil: opts.LogsUntil, + metricsInterval: opts.MetricsInterval, + metricsSampleCount: opts.MetricsSampleCount, + cpuProfilerWait: opts.CPUProfilerWait, } - if len(labelSelector) > 0 { - labelsMap, err := labels.ConvertSelectorToLabelsMap(strings.Join(labelSelector, ",")) + if len(opts.LabelSelector) > 0 { + labelsMap, err := labels.ConvertSelectorToLabelsMap(strings.Join(opts.LabelSelector, ",")) out.MaybeDie(err, "unable to parse label-selector flag: %v", err) bp.labelSelector = labelsMap } @@ -166,18 +155,10 @@ func NewCommand(fs afero.Fs, p *config.Params) *cobra.Command { f := cmd.Flags() f.StringVarP(&outFile, outputFlag, "o", "", "The file path where the debug file will be written (default ./-bundle.zip)") - f.DurationVar(&timeout, "timeout", 31*time.Second, "How long to wait for child commands to execute (e.g. 30s, 1.5m)") - f.DurationVar(&metricsInterval, "metrics-interval", 10*time.Second, "Interval between metrics snapshots (e.g. 30s, 1.5m)") - f.IntVar(&metricsSampleCount, "metrics-samples", 2, "Number of metrics samples to take (at the interval of --metrics-interval). Must be >= 2") - f.StringVar(&logsSince, "logs-since", "yesterday", "Include logs dated from specified date onward; (journalctl date format: YYYY-MM-DD, 'yesterday', or 'today'). Refer to journalctl documentation for more options") - f.StringVar(&logsUntil, "logs-until", "", "Include logs older than the specified date; (journalctl date format: YYYY-MM-DD, 'yesterday', or 'today'). Refer to journalctl documentation for more options") - f.StringVar(&logsSizeLimit, "logs-size-limit", "100MiB", "Read the logs until the given size is reached (e.g. 3MB, 1GiB)") - f.StringVar(&controllerLogsSizeLimit, "controller-logs-size-limit", "132MB", "The size limit of the controller logs that can be stored in the bundle (e.g. 3MB, 1GiB)") + f.DurationVar(&timeout, "timeout", 31*time.Second, "How long to wait for child commands to execute. For example: 30s, 1.5m") f.StringVar(&uploadURL, "upload-url", "", "If provided, where to upload the bundle in addition to creating a copy on disk") - f.StringVarP(&namespace, "namespace", "n", "redpanda", "The namespace to use to collect the resources from (k8s only)") - f.StringArrayVarP(&labelSelector, "label-selector", "l", []string{"app.kubernetes.io/name=redpanda"}, "Comma-separated label selectors to filter your resources. e.g: