Skip to content

Do not log client scrape disconnects as errors#331

Open
gecube wants to merge 1 commit into
coroot:mainfrom
gecube:fix_289_scrape_disconnect_noise
Open

Do not log client scrape disconnects as errors#331
gecube wants to merge 1 commit into
coroot:mainfrom
gecube:fix_289_scrape_disconnect_noise

Conversation

@gecube

@gecube gecube commented Jul 6, 2026

Copy link
Copy Markdown

Problem

When a scraper (e.g. Prometheus) closes the /metrics connection before the response is fully written, promhttp invokes the configured ErrorLog once per metric family. A single benign event — a scrape timeout or the scraper restarting — floods the log with dozens of identical lines:

E... main.go:...] error encoding and sending metric family: write tcp 10.244.2.225:80->10.244.0.63:47976: write: broken pipe
E... main.go:...] error encoding and sending metric family: write tcp 10.244.2.225:80->10.244.0.63:47976: write: broken pipe
...

This is a client-side disconnect (the agent is being scraped and the peer went away mid-response), not an agent fault, but it is reported at error level and is easily mistaken for a real failure. See #289.

Change

Detect EPIPE/ECONNRESET in the promhttp error logger and log those at V(1) instead of the error stream. Genuine encoding/gathering errors continue to be logged as errors.

When a scraper (e.g. Prometheus) closes the connection before the
/metrics response is fully written, promhttp calls the configured
ErrorLog once per metric family, flooding the log with
"error encoding and sending metric family: ... write: broken pipe"
lines for a single benign event (a scrape timeout or the scraper
restarting).

Detect EPIPE/ECONNRESET in the promhttp error logger and log those at
V(1) instead of the error stream. Genuine encoding/gathering errors are
still logged as errors.

Signed-off-by: Gaál György <gb12335@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants