Skip to content

bootstrap: allow exporters to add routes - #430

Open
nicolastakashi wants to merge 3 commits into
prometheus:masterfrom
nicolastakashi:bootstrap-extra-routes
Open

bootstrap: allow exporters to add routes#430
nicolastakashi wants to merge 3 commits into
prometheus:masterfrom
nicolastakashi:bootstrap-extra-routes

Conversation

@nicolastakashi

@nicolastakashi nicolastakashi commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Problem

bootstrap builds the exporter's HTTP mux itself: Run() registers the metrics handler at --web.telemetry-path and the landing page at /, and nothing else can be added to it.

That is enough for node_exporter, but it blocks exporters that serve more than those two endpoints. postgres_exporter is the immediate case:

  • it serves the multi-target /probe endpoint, which is the documented way to scrape remote instances via auth_modules
  • it exposes the net/http/pprof handlers

Adopting bootstrap as it stands would silently 404 both, so the exporter cannot move onto the shared startup path without a user-visible regression. Any exporter with a second endpoint hits the same wall, which pushes them back to hand-rolled main() blocks — the duplication bootstrap exists to remove.

A second constraint is when those handlers can be built. postgres_exporter's probe handler needs the logger and the loaded config file, neither of which exists until flags are parsed, so a static list of routes on Config is not sufficient.

Follow-up

Consumed by prometheus-community/postgres_exporter#1368, which moves postgres_exporter onto bootstrap while keeping /probe and pprof working. That PR needs a release of this one before it builds.

Note: an earlier revision of this PR also let exporters back --web.telemetry-path with a custom env var, to preserve postgres_exporter's PG_EXPORTER_WEB_TELEMETRY_PATH. Per @ArthurSens's review, that's dropped — new env-var-backed flags shouldn't be added, existing ones should be deprecated/removed instead. The follow-up postgres_exporter PR will need to handle that separately.

The bootstrap package builds its own mux, so an exporter that serves more
than /metrics and the landing page cannot adopt it. postgres_exporter, for
example, serves the multi-target /probe endpoint and the net/http/pprof
handlers, and node_exporter-style adoption would silently drop both.

Give Bootstrap a Handle/HandleFunc pair. Routes registered from the metrics
handler factory are applied to the mux next to the metrics endpoint, which
keeps them constructible from state that only exists after flags are
parsed, such as the logger and the loaded config.

Exporters that shipped --web.telemetry-path with an environment variable
also cannot keep that behavior once bootstrap owns the flag, so allow the
envar name to be configured.

Signed-off-by: Nicolas Takashi <nicolas.tcs@hotmail.com>
@nicolastakashi
nicolastakashi force-pushed the bootstrap-extra-routes branch from e9cdc36 to 1518a47 Compare August 18, 2026 20:00
@nicolastakashi
nicolastakashi marked this pull request as ready for review August 18, 2026 20:01

@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.

I don't think we want to continue using env vars in exporters. It would be better to deprecate and remove this functionality from existing exporters rather than continue building on top of it

nicolastakashi added a commit to nicolastakashi/exporter-toolkit that referenced this pull request Aug 21, 2026
Per review feedback on prometheus#430, exporters should not
gain new env-var-backed flags; existing env var support should be deprecated
and removed rather than extended.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QwjFhjwbakiAgUbfnmfJLc
@nicolastakashi nicolastakashi changed the title bootstrap: allow exporters to add routes and a metrics path envar bootstrap: allow exporters to add routes Aug 21, 2026
@nicolastakashi

Copy link
Copy Markdown
Contributor Author

I don't think we want to continue using env vars in exporters. It would be better to deprecate and remove this functionality from existing exporters rather than continue building on top of it

Remove the env var support in here.

nicolastakashi and others added 2 commits August 21, 2026 20:50
Per review feedback on prometheus#430, exporters should not
gain new env-var-backed flags; existing env var support should be deprecated
and removed rather than extended.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QwjFhjwbakiAgUbfnmfJLc
Signed-off-by: Nicolas Takashi <nicolas.tcs@hotmail.com>
The metricsPathFlag helper only existed to branch on MetricsPathEnvar,
which was dropped in a3566c1. With no branching left, the extraction
added nothing.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QwjFhjwbakiAgUbfnmfJLc
Signed-off-by: Nicolas Takashi <nicolas.tcs@hotmail.com>
@nicolastakashi
nicolastakashi force-pushed the bootstrap-extra-routes branch from 8ed863e to 58bf611 Compare August 21, 2026 19:50

@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.

What happens if someone adds a new route that conflicts with / or /metrics? Should we provide guardrails against that?

What ever we decide, it would also be nice to have a test that confirms the behavior we want

@ArthurSens

Copy link
Copy Markdown
Member

Could update your node/postgres PRs with a replace in go mod, just so we can see how these changes look like downstream before we merge?

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