From 0db3d1dd75ec06ac7c9ce2ce20dc5d76c89db3c2 Mon Sep 17 00:00:00 2001 From: r-vasquez Date: Fri, 1 Nov 2024 10:09:06 -0700 Subject: [PATCH] rpk: add `rpk debug remote bundle` Fixes DEVEX-44 This commit introduces the rpk debug remote bundle command, which allows the user to request a debug bundle using the Admin API. --- MODULE.bazel | 1 + src/go/rpk/go.mod | 2 +- src/go/rpk/pkg/cli/debug/BUILD | 1 + src/go/rpk/pkg/cli/debug/bundle/bundle.go | 2 +- src/go/rpk/pkg/cli/debug/common/BUILD | 9 + src/go/rpk/pkg/cli/debug/common/common.go | 18 +- src/go/rpk/pkg/cli/debug/debug.go | 2 + src/go/rpk/pkg/cli/debug/remotebundle/BUILD | 27 +++ .../rpk/pkg/cli/debug/remotebundle/cancel.go | 121 ++++++++++ .../pkg/cli/debug/remotebundle/download.go | 216 +++++++++++++++++ .../rpk/pkg/cli/debug/remotebundle/remote.go | 67 ++++++ .../rpk/pkg/cli/debug/remotebundle/start.go | 217 ++++++++++++++++++ .../rpk/pkg/cli/debug/remotebundle/status.go | 148 ++++++++++++ 13 files changed, 820 insertions(+), 11 deletions(-) create mode 100644 src/go/rpk/pkg/cli/debug/common/BUILD create mode 100644 src/go/rpk/pkg/cli/debug/remotebundle/BUILD create mode 100644 src/go/rpk/pkg/cli/debug/remotebundle/cancel.go create mode 100644 src/go/rpk/pkg/cli/debug/remotebundle/download.go create mode 100644 src/go/rpk/pkg/cli/debug/remotebundle/remote.go create mode 100644 src/go/rpk/pkg/cli/debug/remotebundle/start.go create mode 100644 src/go/rpk/pkg/cli/debug/remotebundle/status.go diff --git a/MODULE.bazel b/MODULE.bazel index 30196e7f31172..6f17614fc24e8 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 6eac1aa8d03cd..2382d2292a4c3 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/cli/debug/BUILD b/src/go/rpk/pkg/cli/debug/BUILD index f939904cb81f1..5626b2b1ca1f6 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/bundle.go b/src/go/rpk/pkg/cli/debug/bundle/bundle.go index 00b2ca7180b3b..922cbf70ca9bf 100644 --- a/src/go/rpk/pkg/cli/debug/bundle/bundle.go +++ b/src/go/rpk/pkg/cli/debug/bundle/bundle.go @@ -155,7 +155,7 @@ 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(&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") // Debug bundle options. opts.InstallFlags(f) diff --git a/src/go/rpk/pkg/cli/debug/common/BUILD b/src/go/rpk/pkg/cli/debug/common/BUILD new file mode 100644 index 0000000000000..42a44d5843310 --- /dev/null +++ b/src/go/rpk/pkg/cli/debug/common/BUILD @@ -0,0 +1,9 @@ +load("@rules_go//go:def.bzl", "go_library") + +go_library( + name = "common", + srcs = ["common.go"], + importpath = "github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/debug/common", + visibility = ["//visibility:public"], + deps = ["@com_github_spf13_pflag//:pflag"], +) diff --git a/src/go/rpk/pkg/cli/debug/common/common.go b/src/go/rpk/pkg/cli/debug/common/common.go index 97d8113cea813..920b4f938530e 100644 --- a/src/go/rpk/pkg/cli/debug/common/common.go +++ b/src/go/rpk/pkg/cli/debug/common/common.go @@ -25,16 +25,16 @@ type DebugBundleSharedOptions struct { // InstallFlags installs the debug bundle flags that fills the debug bundle // options. func (o *DebugBundleSharedOptions) InstallFlags(f *pflag.FlagSet) { - f.StringVar(&o.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(&o.CPUProfilerWait, "cpu-profiler-wait", 30*time.Second, "For how long to collect samples for the CPU profiler (e.g. 30s, 1.5m). Must be higher than 15s") - f.StringVar(&o.LogsSizeLimit, "logs-size-limit", "100MiB", "Read the logs until the given size is reached (e.g. 3MB, 1GiB)") - f.StringVar(&o.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(&o.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.DurationVar(&o.MetricsInterval, "metrics-interval", 10*time.Second, "Interval between metrics snapshots (e.g. 30s, 1.5m)") + f.StringVar(&o.ControllerLogsSizeLimit, "controller-logs-size-limit", "132MB", "The size limit of the controller logs that can be stored in the bundle. For example: 3MB, 1GiB") + f.DurationVar(&o.CPUProfilerWait, "cpu-profiler-wait", 30*time.Second, "How long to collect samples for the CPU profiler. For example: 30s, 1.5m. Must be higher than 15s") + f.StringVar(&o.LogsSizeLimit, "logs-size-limit", "100MiB", "Read the logs until the given size is reached. For example: 3MB, 1GiB") + f.StringVar(&o.LogsSince, "logs-since", "yesterday", "Include logs dated from specified date onward; (journalctl date format: YYYY-MM-DD, 'yesterday', or 'today'). See the journalctl documentation for more options") + f.StringVar(&o.LogsUntil, "logs-until", "", "Include logs older than the specified date; (journalctl date format: YYYY-MM-DD, 'yesterday', or 'today'). See the journalctl documentation for more options") + f.DurationVar(&o.MetricsInterval, "metrics-interval", 10*time.Second, "Interval between metrics snapshots. For example: 30s, 1.5m") f.IntVar(&o.MetricsSampleCount, "metrics-samples", 2, "Number of metrics samples to take (at the interval of --metrics-interval). Must be >= 2") - f.StringArrayVarP(&o.PartitionFlag, "partition", "p", nil, "Comma-separated partition IDs; when provided, rpk saves extra admin API requests for those partitions. Check help for extended usage") - f.StringVarP(&o.Namespace, "namespace", "n", "redpanda", "The namespace to use to collect the resources from (k8s only)") - f.StringArrayVarP(&o.LabelSelector, "label-selector", "l", []string{"app.kubernetes.io/name=redpanda"}, "Comma-separated label selectors to filter your resources. e.g: