feat(metrics): add low-cardinality mode for prometheus metrics#239
Merged
feat(metrics): add low-cardinality mode for prometheus metrics#239
Conversation
add --mgmt.low-cardinality flag to use route patterns instead of raw paths for http_response_time_seconds histogram labels. this reduces metrics cardinality when proxying services with dynamic URLs. Closes #160
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a low-cardinality mode for Prometheus metrics to reduce metric explosion when proxying services with dynamic URLs. The feature is opt-in via the --mgmt.low-cardinality flag, which switches the http_response_time_seconds histogram from using raw request paths (e.g., /api/users/123) to route patterns (e.g., ^/api/users/(.*)) as labels.
Key Changes
- Added
MetricsConfigstruct withLowCardinalityoption to control metrics label behavior - Updated
NewMetricsto accept configuration and use route patterns from request context when enabled - Added
--mgmt.low-cardinalityCLI flag to enable the feature
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| app/mgmt/metrics.go | Core implementation: added MetricsConfig, updated NewMetrics signature, added getRoutePattern helper to extract route patterns from context |
| app/mgmt/server_test.go | Added comprehensive tests for low-cardinality mode and updated existing tests to use new NewMetrics signature |
| app/proxy/proxy_test.go | Updated all test cases to pass empty MetricsConfig{} to NewMetrics |
| app/proxy/health_test.go | Updated test cases to pass empty MetricsConfig{} to NewMetrics |
| app/main.go | Added LowCardinality flag to management options and wired it to metrics initialization |
| README.md | Added documentation explaining the low-cardinality feature and its benefits |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
--mgmt.low-cardinalityflag to use route patterns instead of raw paths forhttp_response_time_secondshistogram labels/api/users/123becomes^/api/users/(.*))[unmatched]for requests that don't match any routeCloses #160