From 706a3b7f0d39c1c38b51f2f76c3a598523dee069 Mon Sep 17 00:00:00 2001 From: r-vasquez Date: Fri, 10 Jan 2025 12:28:17 -0800 Subject: [PATCH] rpk: save startup_log to debug bundle if present If not we just warn that we skipped the collection but the bundle will still be completed --- .../pkg/cli/debug/bundle/bundle_k8s_linux.go | 1 + .../rpk/pkg/cli/debug/bundle/bundle_linux.go | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/go/rpk/pkg/cli/debug/bundle/bundle_k8s_linux.go b/src/go/rpk/pkg/cli/debug/bundle/bundle_k8s_linux.go index b67d8a477a50c..cfb1aa410d230 100644 --- a/src/go/rpk/pkg/cli/debug/bundle/bundle_k8s_linux.go +++ b/src/go/rpk/pkg/cli/debug/bundle/bundle_k8s_linux.go @@ -79,6 +79,7 @@ func executeK8SBundle(ctx context.Context, bp bundleParams) error { saveMountedFilesystems(ps), saveNTPDrift(ps), saveResourceUsageData(ps, bp.y), + saveStartupLog(ps, bp.y), saveSlabInfo(ps), saveUname(ctx, ps), } diff --git a/src/go/rpk/pkg/cli/debug/bundle/bundle_linux.go b/src/go/rpk/pkg/cli/debug/bundle/bundle_linux.go index d108ede6e33f2..2ae0986683b58 100644 --- a/src/go/rpk/pkg/cli/debug/bundle/bundle_linux.go +++ b/src/go/rpk/pkg/cli/debug/bundle/bundle_linux.go @@ -152,6 +152,7 @@ func executeBundle(ctx context.Context, bp bundleParams) error { saveResourceUsageData(ps, bp.y), saveSingleAdminAPICalls(ctx, ps, bp.fs, bp.p, addrs, bp.cpuProfilerWait), saveMetricsAPICalls(ctx, ps, bp.fs, bp.p, addrs, bp.metricsInterval, bp.metricsSampleCount), + saveStartupLog(ps, bp.y), saveSlabInfo(ps), saveSocketData(ctx, ps), saveSysctl(ctx, ps), @@ -1021,6 +1022,31 @@ func saveControllerLogDir(ps *stepParams, y *config.RedpandaYaml, logLimitBytes } } +func saveStartupLog(ps *stepParams, y *config.RedpandaYaml) step { + return func() error { + if y.Redpanda.Directory == "" { + return fmt.Errorf("failed to save startup_log: 'redpanda.data_directory' is empty on the provided configuration file") + } + path := filepath.Join(y.Redpanda.Directory, "startup_log") + exists, err := afero.Exists(ps.fs, path) + if err != nil { + return fmt.Errorf("failed to save startup_log: unable to check existence of startup_log: %v", err) + } + if !exists { + return fmt.Errorf("skipping startup_log collection: unable to find file %q", path) + } + content, err := afero.ReadFile(ps.fs, path) + if err != nil { + return fmt.Errorf("failed to save startup_log: unable to read startup_log: %v", err) + } + err = writeFileToZip(ps, "startup_log", content) + if err != nil { + return fmt.Errorf("failed to save startup_log: %v", err) + } + return nil + } +} + func walkDir(root string, files map[string]*fileInfo) error { return filepath.WalkDir( root,