grafana-agent: honor prometheus.io/port and prometheus.io/path#42
Merged
Conversation
The flow-mode relabel kept scrape=true pods but ignored the port/path annotations, so an annotated pod was scraped only on its discovered container port at /metrics. Adds the two canonical relabel rules: prometheus.io/path overrides __metrics_path__, and prometheus.io/port rewrites __address__ to the pod IP plus the annotated port. Both are no-ops for pods without the annotations (the port rule's regex requires a port digit), so existing scrape targets are unaffected. Lets a workload publish metrics on a non-default port — e.g. the portal worker on its 8081 health port.
CI Results
All validations passed. |
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
discovery.relabel "pods"block keeps pods annotatedprometheus.io/scrape=trueand stamps namespace/pod/container labels, but never readprometheus.io/portorprometheus.io/path. So an annotated workload was scraped on whatever container port discovery found, at the default/metrics— a pod publishing metrics on a non-default port (e.g. portal's worker on:8081) was scraped on the wrong port or missed.Adds two River rules in the same relabel block:
prometheus.io/path→__metrics_path__(regex(.+), default replace).[__address__, prometheus.io/port]→__address__rewrite (([^:]+)(?::\d+)?;(\d+)→$1:$2), host:discovered-port → host:annotated-port.Both are no-ops when the annotation is absent (the port regex requires a trailing digit; the path regex requires a value), so existing scrape targets are unaffected. Wire-compatible with Grafana Alloy's
discovery.relabelif/when this addon migrates off Flow mode.Validation: statically verified — correct River/Flow dialect (chart grafana-agent 0.44.2,
agent.mode: flow), regex semantics and no-op safety confirmed, and the rules match portal's server (:8080) and worker (:8081) pod annotations. yamllint clean. Not yet exercised against a live scrape; that confirms on the next cluster run.