From 62592f5e99603017a90ff537e1d2130f454fc6f0 Mon Sep 17 00:00:00 2001 From: stxkxs Date: Sun, 14 Jun 2026 12:43:52 -0700 Subject: [PATCH] grafana-agent: honor prometheus.io/port and prometheus.io/path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- addons/observability/grafana-agent/values.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addons/observability/grafana-agent/values.yaml b/addons/observability/grafana-agent/values.yaml index d1ab2ce..32ad4f4 100644 --- a/addons/observability/grafana-agent/values.yaml +++ b/addons/observability/grafana-agent/values.yaml @@ -40,6 +40,22 @@ agent: source_labels = ["__meta_kubernetes_pod_container_name"] target_label = "container" } + // Honor prometheus.io/path — override the scrape path when annotated + // (no-op for pods without the annotation; default stays /metrics). + rule { + source_labels = ["__meta_kubernetes_pod_annotation_prometheus_io_path"] + regex = "(.+)" + target_label = "__metrics_path__" + } + // Honor prometheus.io/port — rewrite the target to pod IP : annotated + // port so a workload can publish metrics on a non-default port. No-op + // when the annotation is absent (the regex requires a port digit). + rule { + source_labels = ["__address__", "__meta_kubernetes_pod_annotation_prometheus_io_port"] + regex = "([^:]+)(?::\\d+)?;(\\d+)" + replacement = "$1:$2" + target_label = "__address__" + } } // ────────────────────────────── Metrics → AMP ──────────────────────────