Skip to content

fix(server): initialize prometheus headers map to avoid nil map panic#820

Open
SAY-5 wants to merge 1 commit into
slok:mainfrom
SAY-5:fix/server-prometheus-header-nil-map-panic
Open

fix(server): initialize prometheus headers map to avoid nil map panic#820
SAY-5 wants to merge 1 commit into
slok:mainfrom
SAY-5:fix/server-prometheus-header-nil-map-panic

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 12, 2026

Fixes #819.

sloth server --prometheus-header='k=v' panicked with assignment to entry in nil map because serverCommand.prometheus.headers was passed to StringMapVar while still nil. The equivalent --extra-labels flag in generate/validate/k8scontroller works because those commands initialize the map (&generateCommand{extraLabels: map[string]string{}}); server did not.

Initializes the map in NewServerCommand and adds a regression test that parses server --prometheus-header=... and asserts no panic (fails before the fix, passes after). go build ./..., go vet ./cmd/... and the new test pass locally.

The server command's --prometheus-header flag panicked with
"assignment to entry in nil map" because the backing map was never
initialized, unlike the equivalent --extra-labels flag in other
commands. Initialize it in NewServerCommand and add a regression test.
@SAY-5 SAY-5 requested a review from slok as a code owner May 12, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic when setting headers via --prometheus-header

1 participant