Skip to content

fix: chi route pattern for metric cardinality protection#15

Merged
sethgrid merged 1 commit into
mainfrom
fix/metric-cardinality-status-zero
Apr 12, 2026
Merged

fix: chi route pattern for metric cardinality protection#15
sethgrid merged 1 commit into
mainfrom
fix/metric-cardinality-status-zero

Conversation

@sethgrid
Copy link
Copy Markdown
Owner

Summary

  • Replaces the status-code heuristic (status == 404 || status == 0) with chi.RouteContext().RoutePattern() as the Prometheus endpoint label
  • Unregistered routes (empty pattern or /*) map to "other"; registered routes use their exact pattern
  • This catches 403/405 responses from scanner traffic that slipped past the old check (e.g. POST /form/admin/import → 405 from a catch-all file server)
  • Logs the real path as path_high_cardinality for debugging without polluting metric labels
  • Updates logger unit test to drive requests through a chi router so route patterns are populated

Test plan

  • go test ./logger/...TestMiddlewareCardinalityProtection passes with chi router providing route context
  • CI passes

🤖 Generated with Claude Code

Replace the status-code heuristic (treating 404/0 as high-cardinality) with
chi.RouteContext().RoutePattern(). Empty pattern or "/*" (unregistered routes,
scanner traffic) map to "other"; registered routes use their pattern directly.
This catches 403/405 scanner responses that slipped past the old check.

Update logger_test to drive requests through a chi router so route patterns
are populated, and drop the "redacted for cardinality protection" string check.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sethgrid sethgrid force-pushed the fix/metric-cardinality-status-zero branch from 4ffbd6f to 0082d00 Compare April 12, 2026 13:11
@sethgrid sethgrid merged commit 95e8e91 into main Apr 12, 2026
4 checks passed
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