Skip to content

bootstrap: apply --web.max-requests, allow opting routes in - #447

Merged
ArthurSens merged 2 commits into
prometheus:masterfrom
nicolastakashi:nicolastakashi/max-web-request-opt-in
Sep 21, 2026
Merged

ArthurSens merged 2 commits into
prometheus:masterfrom
nicolastakashi:nicolastakashi/max-web-request-opt-in

Conversation

@nicolastakashi

Copy link
Copy Markdown
Contributor

--web.max-requests is parsed but never enforced, and routes like postgres_exporter's /probe get no concurrency protection at all (see prometheus-community/postgres_exporter#1368).

This binds the metrics endpoint to the flag, and adds Bootstrap.MaxRequestsHandler so other scrape-shaped routes can opt in too. Health checks stay unbounded by default.

--web.max-requests was registered, parsed, validated and stored, and then
nothing acted on it. Wrap the metrics handler in a concurrency limiter that
answers overflow with 503 instead of queuing, so a scrape that can't be
served fails fast instead of piling up behind the ones already running.
Rejections are logged at a bounded rate to avoid flooding logs when the
endpoint is saturated.

A limit of 0 disables the bound, as the flag help already says.

Signed-off-by: Nicolas Takashi <nicolas.takashi@dash0.com>
The metrics endpoint is bound by --web.max-requests, but routes an exporter
registers through Bootstrap.Handle/HandleFunc are not — deliberately, since a
health or readiness check should stay responsive while a bounded endpoint is
saturated. Some exporters register routes that are themselves scrape
endpoints (postgres_exporter's /probe, for example) and currently get no
concurrency protection from the toolkit at all.

Export the metrics endpoint's own limiter as Bootstrap.MaxRequestsHandler so
a caller can wrap a route in it before registering it, opting that specific
route into the same bound, same 503 behavior, and same rate-limited
rejection log — without forcing it onto every route.

Signed-off-by: Nicolas Takashi <nicolas.takashi@dash0.com>
@nicolastakashi
nicolastakashi force-pushed the nicolastakashi/max-web-request-opt-in branch from 1488fc7 to aebd3f3 Compare September 18, 2026 19:01
@nicolastakashi
nicolastakashi marked this pull request as ready for review September 18, 2026 19:04

@ArthurSens ArthurSens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread bootstrap/bootstrap.go
Comment on lines -67 to +69
// DisableExporterMetrics reports whether exporter self-metrics should be disabled.
// DisableExporterMetrics is the parsed value of --web.disable-exporter-metrics.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is out of scope for this PR, but I'd love to see exporter-toolkit owning a Registry and this boolean would handle registering VersionCollector, GoCollector and HTTP metrics in the future :)

It sounds a bit weird to have this boolean here and then have an exporter miss it by accident.

@ArthurSens
ArthurSens merged commit e828bf7 into prometheus:master Sep 21, 2026
6 checks passed
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.

2 participants