Skip to content

Conversation

@umputun
Copy link
Owner

@umputun umputun commented Dec 11, 2025

Summary

  • Add --mgmt.low-cardinality flag to use route patterns instead of raw paths for http_response_time_seconds histogram labels
  • Reduces metrics cardinality when proxying services with dynamic URLs (e.g., /api/users/123 becomes ^/api/users/(.*))
  • Falls back to [unmatched] for requests that don't match any route

Closes #160

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
Copilot AI review requested due to automatic review settings December 11, 2025 09:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MetricsConfig struct with LowCardinality option to control metrics label behavior
  • Updated NewMetrics to accept configuration and use route patterns from request context when enabled
  • Added --mgmt.low-cardinality CLI 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.

@umputun umputun merged commit e264a6e into master Dec 11, 2025
10 checks passed
@umputun umputun deleted the feat/low-cardinality-metrics branch December 11, 2025 09:07
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.

Reduce the metrics cardinality

2 participants