Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add nil check to support bundle printer that prints remotecfg & local sources #2355

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/sources/troubleshoot/support_bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ menuTitle: Generate a support bundle
weight: 300
---

<span class="badge docs-labels__stage docs-labels__item">Public preview</span>

# Generate a support bundle

{{< docs/public-preview product="Generate support bundle" >}}

The `/-/support?duration=N` endpoint returns a support bundle, a compressed file that contains information
about a running {{< param "PRODUCT_NAME" >}} instance, and can be used as a baseline of information when trying
to debug an [issue][alloy-repo].
Expand Down
12 changes: 4 additions & 8 deletions internal/service/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,6 @@ func (s *Service) generateSupportBundleHandler(host service.Host) func(rw http.R
s.supportBundleMut.Lock()
defer s.supportBundleMut.Unlock()

// TODO(dehaansa) remove this check once the support bundle is generally available
if !s.opts.MinStability.Permits(featuregate.StabilityPublicPreview) {
rw.WriteHeader(http.StatusForbidden)
_, _ = rw.Write([]byte("support bundle generation is only available in public preview. Use" +
" --stability.level command-line flag to enable public-preview features"))
return
}

if s.opts.BundleContext.DisableSupportBundle {
rw.WriteHeader(http.StatusForbidden)
_, _ = rw.Write([]byte("support bundle generation is disabled; it can be re-enabled by removing the --disable-support-bundle flag"))
Expand Down Expand Up @@ -661,6 +653,10 @@ func remoteCfgRedactedCachedConfig(host service.Host) ([]byte, error) {
}

func printFileRedacted(f *ast.File) ([]byte, error) {
if f == nil {
return []byte{}, nil
}

c := printer.Config{
RedactSecrets: true,
}
Expand Down
31 changes: 17 additions & 14 deletions internal/service/http/supportbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,23 @@ func ServeSupportBundle(rw http.ResponseWriter, b *Bundle, logsBuf *bytes.Buffer
rw.Header().Set("Content-Disposition", "attachment; filename=\"alloy-support-bundle.zip\"")

zipStructure := map[string][]byte{
"alloy-metadata.yaml": b.meta,
"alloy-components.json": b.components,
"alloy-peers.json": b.peers,
"alloy-metrics-sample-start.txt": b.alloyMetricsStart,
"alloy-metrics-sample-end.txt": b.alloyMetricsEnd,
"alloy-runtime-flags.txt": b.runtimeFlags,
"alloy-environment.txt": b.environmentVariables,
"alloy-logs.txt": logsBuf.Bytes(),
"sources/remote-config/remote.alloy": b.remoteCfg,
"pprof/cpu.pprof": b.cpuBuf.Bytes(),
"pprof/heap.pprof": b.heapBuf.Bytes(),
"pprof/goroutine.pprof": b.goroutineBuf.Bytes(),
"pprof/mutex.pprof": b.mutexBuf.Bytes(),
"pprof/block.pprof": b.blockBuf.Bytes(),
"alloy-metadata.yaml": b.meta,
"alloy-components.json": b.components,
"alloy-peers.json": b.peers,
"alloy-metrics-sample-start.txt": b.alloyMetricsStart,
"alloy-metrics-sample-end.txt": b.alloyMetricsEnd,
"alloy-runtime-flags.txt": b.runtimeFlags,
"alloy-environment.txt": b.environmentVariables,
"alloy-logs.txt": logsBuf.Bytes(),
"pprof/cpu.pprof": b.cpuBuf.Bytes(),
"pprof/heap.pprof": b.heapBuf.Bytes(),
"pprof/goroutine.pprof": b.goroutineBuf.Bytes(),
"pprof/mutex.pprof": b.mutexBuf.Bytes(),
"pprof/block.pprof": b.blockBuf.Bytes(),
}

if len(b.remoteCfg) > 0 {
zipStructure["sources/remote-config/remote.alloy"] = b.remoteCfg
}

for p, s := range b.sources {
Expand Down
Loading