flags: respect explicit --listen when metrics-endpoint is set#332
Open
gecube wants to merge 1 commit into
Open
flags: respect explicit --listen when metrics-endpoint is set#332gecube wants to merge 1 commit into
gecube wants to merge 1 commit into
Conversation
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 coroot#258 Signed-off-by: Gaál György <gb12335@gmail.com>
Author
Local build & test reportBuilt and tested in a Debian bullseye container (matching the project Build Vet Tests All packages build and pass; Note: the |
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.
Problem
Fixes #258.
When a metrics endpoint is configured — either directly via
--metrics-endpoint/METRICS_ENDPOINT, or derived from--collector-endpoint—flags/init()unconditionally overwrites the listen address:This binds the built-in HTTP server to loopback and silently discards any user-provided
--listen/LISTEN. As a result you cannot scrape/metricsdirectly from the agent while it is also remote-writing, even if you explicitly ask for a routable listen address.Change
Only apply the loopback default when the listen address is still at its compiled-in default:
--listenset → unchanged behavior: loopback (127.0.0.1:10300) in remote-write mode.--listen/LISTENset explicitly → honored, so/metricscan be scraped alongside remote write.Why this is safe
*flags.ListenAddressis consumed only by the HTTP server (main.go, and the Windows agent). The remote-write path gathers metrics in-process viaregistry.Gather()(prom/remote_writer.go) — it does not scrape its own socket — so honoring--listencannot affect the remote-write pipeline. On WindowsdefaultListenAddressis already127.0.0.1:10300, so the default-mode behavior there is unchanged too, and an explicit--listenis now honored on Windows as well.Builds cleanly for
GOOS=linuxandGOOS=windows;go vet ./flags/is clean.