Skip to content

main: start the exporter through the toolkit bootstrap package - #1368

Open
nicolastakashi wants to merge 1 commit into
prometheus-community:masterfrom
nicolastakashi:bootstrap-runner
Open

main: start the exporter through the toolkit bootstrap package#1368
nicolastakashi wants to merge 1 commit into
prometheus-community:masterfrom
nicolastakashi:bootstrap-runner

Conversation

@nicolastakashi

@nicolastakashi nicolastakashi commented Aug 18, 2026

Copy link
Copy Markdown

Summary

Starts postgres_exporter on the shared exporter startup path by replacing the hand-rolled main() block with exporter-toolkit/bootstrap, mirroring prometheus/node_exporter#3660.

The entrypoint currently reimplements what bootstrap provides: the --web.telemetry-path flag, kingpinflag/promslog wiring, version output, landing page construction, and the web.ListenAndServe call. Keeping a private copy is how exporters drift apart in flags and startup behavior.

Two notes for review:

  • --dumpmaps exits from inside the handler factory, since it is an early-exit path and bootstrap has no pre-serve hook
  • CloseServers() now runs after Run() returns instead of via defer; the old defer never actually ran, because every exit path went through os.Exit

Comment thread cmd/postgres_exporter/main.go Outdated
@nicolastakashi
nicolastakashi marked this pull request as ready for review August 27, 2026 19:56
The entrypoint hand-rolls what exporter-toolkit/bootstrap now provides:
the web.telemetry-path / web.listen-address flags, promslog flag wiring,
version output, the landing page, and the ListenAndServe call. Keeping a
private copy is how exporters drift apart in flags and startup behavior.

Move exporter construction into a metrics handler factory, which runs
after flags are parsed, and register the multi-target /probe endpoint
and the net/http/pprof and expvar (/debug/) handlers as bootstrap
routes so they keep working on the mux bootstrap owns.

Two flags come with bootstrap and are wired to real behavior here:
--web.max-requests limits in-flight scrapes, and
--web.disable-exporter-metrics drops the Go and process collectors.

exporter-toolkit is bumped to v0.19.0, which ships the route-registration
support this depends on (prometheus/exporter-toolkit#430).
PG_EXPORTER_WEB_TELEMETRY_PATH keeps working, but bootstrap dropped
env-var support for --web.telemetry-path, so instead of relocating the
metrics endpoint the handler is additionally served at the env var's
path (with a deprecation warning) for a compatibility window.

Fatal startup errors are logged through the configured logger once one
exists, falling back to stderr only for pre-parse failures. --dumpmaps
and runtime shutdown are handled from main rather than exiting from
inside the bootstrap callback.

Signed-off-by: Nicolas Takashi <nicolas.tcs@hotmail.com>

@ArthurSens ArthurSens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is also a great opportunity to add a big warning in the changelog about the deprecation of env vars!

Comment on lines +224 to +229
if !b.DisableExporterMetrics {
registry.MustRegister(
prometheuscollectors.NewGoCollector(),
prometheuscollectors.NewProcessCollector(prometheuscollectors.ProcessCollectorOpts{}),
)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmmm, I'm just seeing this now. It looks weird that Bootstrap owns the self-metrics toggle but has absolutely no control over it. I wonder if this even is something that the exporter toolkit can control 🤔

If we compare what this boolean does here with what it does in node exporter, in node exporter we also have HTTP metrics since it uses promhttp.InstrumentMetricsHander

Version collector is also about the exporter itself and is not gated by the boolean

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yup good catch, I moved version collector under the flag for now. Longer term I think this belongs in bootstrap itself, it owns the registry and gates self-metrics directly instead of just handing exporters a bool, happy to open that as a follow-up on exporter-toolkit if you're up for it wdyt?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know if that's possible though. If it is, then great...let's do it

}
http.Handle("/", landingPage)
}
b.HandleFunc("/probe", handleProbe(logger, authHandler, cfg))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

--web.max-requests works for /metrics but doesn't wrap /probe

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, makes sense, maybe we should have exporter toolkit enforce web.max-requests on every route, wdyt? if you agree I'd make it on the exporter instead of rebuilding it here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think for now we can just do it here. I'm not sure if it's safe to do that, we can make this move later :)

Comment on lines +236 to +237
// net/http/pprof and the transitively-imported "expvar" package both
// register handlers under /debug/ on the default mux.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this comment seems unnecessary

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.

3 participants