Skip to content

Commit

Permalink
fix: Add nil check to support bundle printer that prints remotecfg & …
Browse files Browse the repository at this point in the history
…local sources (#2355)

* Add nil check to support bundle printer that prints remotecfg & local sources

* Remove public preview requirement from support bundle
  • Loading branch information
dehaansa authored Jan 9, 2025
1 parent ea7c8a0 commit bd20017
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
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

0 comments on commit bd20017

Please sign in to comment.