From 2a6b431580f05c94d10c2256e407a841150f00b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A1l=20Gy=C3=B6rgy?= Date: Mon, 6 Jul 2026 22:15:08 +0200 Subject: [PATCH] flags: respect explicit --listen when metrics-endpoint is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a metrics endpoint is configured (directly or derived from --collector-endpoint), the listen address was unconditionally overwritten to 127.0.0.1:10300, which made it impossible to scrape /metrics from the agent while it also remote-writes metrics. Only apply the loopback default when the listen address is still at its compiled-in default, so an explicitly configured --listen / LISTEN is honored. This keeps the previous behavior (loopback in remote-write mode) for everyone who does not set --listen. Fixes #258 Signed-off-by: Gaál György --- flags/flags.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/flags/flags.go b/flags/flags.go index cffea3b..fd29fd5 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -83,7 +83,11 @@ func init() { platformEndpoints(u) } - if *MetricsEndpoint != nil { + if *MetricsEndpoint != nil && *ListenAddress == defaultListenAddress { + // In remote-write mode the built-in HTTP server is only needed for the + // agent's own metrics, so bind it to loopback by default. Respect an + // explicitly configured --listen/LISTEN so /metrics can also be scraped + // directly (e.g. by an external Prometheus alongside remote write). *ListenAddress = "127.0.0.1:10300" } }