Skip to content

fix(metrics): use ServeMux route pattern as label, not raw URL - #57

Open
samcm wants to merge 4 commits into
masterfrom
worktree-fix-metrics-cardinality
Open

fix(metrics): use ServeMux route pattern as label, not raw URL#57
samcm wants to merge 4 commits into
masterfrom
worktree-fix-metrics-cardinality

Conversation

@samcm

@samcm samcm commented May 13, 2026

Copy link
Copy Markdown
Member

The Metrics middleware labels http_requests_total, http_request_duration_seconds, http_request_size_bytes, and http_response_size_bytes with r.URL.Path — so every unique URL (vuln-scanner probes like /.env, /wp-login.php, and per-network proxy paths) becomes a permanent series in the metrics store. Production VictoriaMetrics observed ~48k distinct path label values from this app alone.

This switches the label to r.Pattern (set by net/http.ServeMux after routing) with an unmatched sentinel as a defensive fallback; the label name stays path for dashboard compatibility but values are now bounded by the registered route count.

The Metrics middleware was labeling http_requests_total,
http_request_duration_seconds, http_request_size_bytes, and
http_response_size_bytes with r.URL.Path. Every unique URL — including
vulnerability-scanner probes (/.env, /wp-login.php) and per-network proxy
paths (/api/v1/<network>/...) — became a permanent metric series in
indexdb. Production VictoriaMetrics observed ~48k distinct path values
from this app alone.

Use r.Pattern (set by net/http.ServeMux after routing) instead, with an
"unmatched" sentinel as a defensive fallback. The path label name is
preserved for dashboard compatibility but its values are now bounded by
the number of registered routes.
@samcm
samcm requested a review from mattevans as a code owner May 13, 2026 04:12
samcm added 3 commits May 13, 2026 14:13
The workflow used 'version: latest' which broke CI when a newer
golangci-lint release tightened goconst/wsl rules and started flagging
pre-existing strings across the repo. v2.11.4 is the version that ran on
the last green master build (#55, 2026-04-24).
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.

2 participants