Skip to content

Fix nil-request panic, startup log, and metric naming#19

Merged
jenting merged 1 commit into
mainfrom
fix/webhook-robustness-and-metrics
Jun 10, 2026
Merged

Fix nil-request panic, startup log, and metric naming#19
jenting merged 1 commit into
mainfrom
fix/webhook-robustness-and-metrics

Conversation

@jenting

@jenting jenting commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

Fixes several correctness and consistency issues found in the webhook.

# Location Issue Fix
1 main.go Panic risk: a body that unmarshals without a request field leaves AdmissionReview.Request nil; accessing .UID crashes the server Guard for nil Request, return 400 Bad Request
2 main.go Startup log hardcodes :8443, ignoring the --port flag Log the actual configured addr
3 main.go Metric help says "milliseconds" but the code records .Seconds() Rename metric to ..._request_duration_seconds and fix help text
4 README.md Typo "frequet" "frequent"

Added TestHandleAdmissionReview_NilRequest to lock in the panic fix.

⚠️ Breaking change note

Item 3 renames the Prometheus metric from grafana_operator_webhook_request_duration to grafana_operator_webhook_request_duration_seconds to follow Prometheus naming conventions. Any existing Grafana dashboards or alerts referencing the old name must be updated.

Test plan

  • go build ./...
  • go vet ./...
  • go test ./... (all pass, including new test)

🤖 Generated with Claude Code

- Guard against nil AdmissionReview.Request to prevent server panic on
  malformed bodies; return 400 instead
- Log the actual configured port instead of hardcoded :8443
- Rename request duration metric to _seconds and fix help text to match
  the seconds value actually recorded
- Fix "frequet" typo in README
- Add test covering the nil-request path

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jenting jenting merged commit f066d76 into main Jun 10, 2026
6 of 7 checks passed
@jenting jenting deleted the fix/webhook-robustness-and-metrics branch June 10, 2026 15:37
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.

1 participant