Skip to content

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

Open
SAY-5 wants to merge 2 commits 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 2 commits into
slok:mainfrom
SAY-5:fix/server-prometheus-header-nil-map-panic

Conversation

@SAY-5

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

Copy link
Copy Markdown

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
…us-header-nil-map-panic

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>

# Conflicts:
#	CHANGELOG.md
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 31.54%. Comparing base (8a3be4f) to head (c5345f1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #820      +/-   ##
==========================================
+ Coverage   31.30%   31.54%   +0.23%     
==========================================
  Files         149      149              
  Lines        9228     9229       +1     
==========================================
+ Hits         2889     2911      +22     
+ Misses       6088     6067      -21     
  Partials      251      251              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

3 participants