Skip to content

grafana-agent: honor prometheus.io/port and prometheus.io/path#42

Merged
stxkxs merged 1 commit into
mainfrom
grafana-agent-honor-prom-port
Jun 14, 2026
Merged

grafana-agent: honor prometheus.io/port and prometheus.io/path#42
stxkxs merged 1 commit into
mainfrom
grafana-agent-honor-prom-port

Conversation

@stxkxs

@stxkxs stxkxs commented Jun 14, 2026

Copy link
Copy Markdown
Member

The discovery.relabel "pods" block keeps pods annotated prometheus.io/scrape=true and stamps namespace/pod/container labels, but never read prometheus.io/port or prometheus.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.relabel if/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.

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.
@github-actions

Copy link
Copy Markdown

CI Results

Check Status
YAML Lint
Environment Kustomize Build
dev
staging
production

All validations passed.

@stxkxs stxkxs merged commit c5c500f into main Jun 14, 2026
5 checks passed
@stxkxs stxkxs deleted the grafana-agent-honor-prom-port branch June 14, 2026 21:48
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.

1 participant