Fix issue with duplicate prometheus HELP/TYPE lines - #772
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
Pull request overview
Fixes invalid Prometheus text exposition for /api/v2/metrics by ensuring shared “operational” metrics are emitted with a single # HELP/# TYPE header across namespaces, while still including per-namespace samples via the subsystem label.
Changes:
- Refactors metric rendering to separate header emission from sample emission (
include_header,prometheus_header) and aggregates operational metric samples across namespaces. - Adds
OPERATIONAL_FIELDSto centrally define which metrics must be grouped/deduped. - Adds a unit test to verify Prometheus parsing and prevent duplicate
HELP/TYPEoutput regressions.
File summaries
| File | Description |
|---|---|
awx/main/analytics/subsystem_metrics.py |
Aggregates operational metric samples and emits a single header per metric to avoid duplicate HELP/TYPE lines. |
awx/main/tests/unit/analytics/test_subsystem_metrics.py |
Adds a regression test ensuring /api/v2/metrics output is parseable and does not duplicate declarations. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
awx/main/analytics/subsystem_metrics.py:186
HistogramM.to_prometheus()assumesinstance_data[instance][self.field]is always present. In mixed-version clusters or after upgrades, stale instances can lack newer metrics;BaseM.to_prometheus()already guards against this, butHistogramMwill raise aKeyErrorand break the entire/api/v2/metricsresponse.
for instance in instance_data:
# Build label string
node_label = f'node="{instance}"'
subsystem_label = f',subsystem="{namespace}"' if namespace else ''
for i, b in enumerate(self.buckets):
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
TheWitness
approved these changes
Aug 31, 2026
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.
Resolves #766