-
Notifications
You must be signed in to change notification settings - Fork 847
plugins(stats_over_http): Add Prometheus v2 output with metric labels #12792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 pull request adds a new Prometheus v2 output format for the stats_over_http plugin that transforms flat ATS metric names into labeled metrics for better aggregation in Prometheus/Grafana. The new format can be accessed via /_stats/prometheus_v2 endpoint or by passing Accept: text/plain; version=2.0.0 header.
Key changes:
- Implements metric name parsing logic to extract labels (status codes, HTTP methods, cache results, volume/thread indices, time buckets) from flat metric names
- Adds deduplication of HELP/TYPE metadata lines for metrics sharing the same base name
- Includes compile-time unit tests and comprehensive AuTests for validation
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/stats_over_http/stats_over_http.cc | Core implementation: adds parse_metric_v2 function, prometheus_v2_out_stat callback, new output format enum, HTTP headers, routing logic, and compile-time tests |
| tests/gold_tests/pluginTest/stats_over_http/stats_over_http.test.py | Adds test cases for Prometheus v2 format via both endpoint path and Accept header, with assertions validating label extraction |
| tests/gold_tests/pluginTest/stats_over_http/gold/stats_over_http_prometheus_v2_stderr.gold | Gold file for expected stderr output when accessing /_stats/prometheus_v2 endpoint |
| tests/gold_tests/pluginTest/stats_over_http/gold/stats_over_http_prometheus_v2_accept_stderr.gold | Gold file for expected stderr output when using Accept header for Prometheus v2 |
| doc/admin-guide/plugins/stats_over_http.en.rst | Documentation updates explaining the new v2 format, endpoints, and content-type headers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The current Prometheus output in stats_over_http dumps flattened metric names (e.g., proxy.process.http.200_responses), which makes it difficult to aggregate data in Grafana or Prometheus. This adds a new "v2" output format that parses these names into proper labels like status="200" or method="GET". The new format can be accessed via /_stats/prometheus_v2 or by passing an Accept header with version=2.0.0. To keep this efficient, the parsing uses swoc::TextView for a zero- allocation approach. It recognizes common ATS patterns such as status codes, HTTP methods, cache results, and thread/volume indices. I've also added deduplication for the HELP and TYPE metadata lines, so that metrics sharing the same base name (but different labels) are grouped correctly in the output. Includes compile-time unit tests (static_assert) to verify the parsing logic and updated AuTests for the new endpoint.
| p.Streams.stdout += Testers.ContainsExpression( | ||
| 'proxy_process_http_requests{method="completed"}', | ||
| "Verify that method labels are extracted correctly.", | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad you added this test.
method="completed"
completed isn't a method, POST, GET, PUT, etc., are methods. It seems like having completed would be misleading for users viewing this data.
|
In case it's helpful, here's the fedora build failure: |
The current Prometheus output in stats_over_http dumps flattened metric names (e.g.,
proxy.process.http.200_responses), which makes it difficult to aggregate data in Grafana or Prometheus. This adds a new "v2" output format that parses these names into labels likestatus="200"ormethod="GET".The new format can be accessed via /_stats/prometheus_v2 or by passing an Accept header with version=2.0.0.
To keep this efficient, the parsing uses
swoc::TextViewfor a zero- allocation approach. It recognizes common ATS patterns such as status codes, HTTP methods, cache results, and thread/volume indices. I've also added deduplication for the HELP and TYPE metadata lines, so that metrics sharing the same base name (but different labels) are grouped correctly in the output.Includes compile-time unit tests (static_assert) to verify the parsing logic and updated AuTests for the new endpoint.
Related issue: #12778