fix(metrics): use ServeMux route pattern as label, not raw URL - #57
Open
samcm wants to merge 4 commits into
Open
fix(metrics): use ServeMux route pattern as label, not raw URL#57samcm wants to merge 4 commits into
samcm wants to merge 4 commits into
Conversation
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.
mattevans
approved these changes
May 13, 2026
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Metrics middleware labels
http_requests_total,http_request_duration_seconds,http_request_size_bytes, andhttp_response_size_byteswithr.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 distinctpathlabel values from this app alone.This switches the label to
r.Pattern(set bynet/http.ServeMuxafter routing) with anunmatchedsentinel as a defensive fallback; the label name stayspathfor dashboard compatibility but values are now bounded by the registered route count.