Skip to content

bootstrap: apply --web.max-requests - #441

Open
mrueg wants to merge 1 commit into
prometheus:masterfrom
mrueg:fix/bootstrap-max-requests-inert
Open

bootstrap: apply --web.max-requests#441
mrueg wants to merge 1 commit into
prometheus:masterfrom
mrueg:fix/bootstrap-max-requests-inert

Conversation

@mrueg

@mrueg mrueg commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

--web.max-requests is registered, parsed, validated and stored, and then nothing acts on it. An exporter that supplies Config.MetricsHandler gets a --web.max-requests=40 default in its help output that limits nothing.

Change

Bound the metrics handler with it. Requests arriving while the limit is reached are answered with 503 rather than queued, so a scrape that cannot be served fails quickly instead of piling up behind the ones already running — matching what promhttp does for the same setting. A limit of 0 leaves the handler unwrapped, as the flag help says.

The bound applies to the metrics endpoint only. Routes registered by a MetricsHandlerFactory are not covered, because the flag describes parallel scrape requests and a health endpoint should still answer while the metrics endpoint is saturated. There is a test for that.

This deliberately does not pull in client_golang as a direct dependency — the limiter is a few lines of chan struct{}.

--web.disable-exporter-metrics

This one cannot be applied the same way: only the metrics handler knows which collectors it gathers, and bootstrap is given that handler already built. It is reported to a MetricsHandlerFactory as Bootstrap.DisableExporterMetrics, so this says that in the flag help rather than leaving it looking like something bootstrap acts on. Happy to take a different approach if you would rather it did something more.

Tests

Three tests: the limit is enforced, 0 disables it, and other routes are unaffected. The first hangs against master, since without the bound the second request enters the handler instead of being turned away.

🤖 Generated with Claude Code

The flag was registered, parsed, validated and stored, and then nothing
acted on it. An exporter that supplies Config.MetricsHandler got a
--web.max-requests=40 default in its help output that limited nothing.

Bound the metrics handler with it. Requests arriving while the limit is
reached are answered with 503 rather than queued, so a scrape that cannot
be served fails quickly instead of piling up behind the ones already
running, which matches what promhttp does for the same setting. A limit of
zero leaves the handler unwrapped, as the flag help says.

The bound is applied to the metrics endpoint only. Routes registered by a
MetricsHandlerFactory are not covered, because the flag describes parallel
scrape requests, and a health endpoint should still answer while the
metrics endpoint is saturated.

--web.disable-exporter-metrics cannot be applied the same way: only the
metrics handler knows which collectors it gathers, and bootstrap is given
that handler already built. It is reported to a MetricsHandlerFactory as
Bootstrap.DisableExporterMetrics, so say that in the flag help rather than
leaving it looking like something bootstrap acts on.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
@mrueg
mrueg force-pushed the fix/bootstrap-max-requests-inert branch from ca97f74 to e0d6023 Compare September 2, 2026 13:44
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