Skip to content

collector: use the shared exporter-toolkit collector registry (PoC) - #1366

Draft
nicolastakashi wants to merge 1 commit into
prometheus-community:masterfrom
nicolastakashi:poc/toolkit-collector-registry
Draft

collector: use the shared exporter-toolkit collector registry (PoC)#1366
nicolastakashi wants to merge 1 commit into
prometheus-community:masterfrom
nicolastakashi:poc/toolkit-collector-registry

Conversation

@nicolastakashi

Copy link
Copy Markdown

Draft / proof of concept. Stacked on prometheus/exporter-toolkit#429 — CI will not build until that lands, since the toolkit package it imports is unreleased. To build locally: go mod edit -replace github.com/prometheus/exporter-toolkit=/path/to/exporter-toolkit against that branch.

Follow-up to @ArthurSens' question in #1361: could the collector enable/disable abstraction live in exporter-toolkit, and could the docs table be generated from it? This is what that looks like in practice.

What changed

collector/collector.go's factories / collectorState / forcedCollectors / initiatedCollectors maps, and the flag registration, forced-state tracking, filtering and lazy instantiation around them, are near-verbatim copies of node_exporter's. They're replaced by toolkit.Registry, which is generic over the collector interface — so Update(ctx, instance, ch) is untouched, and registerCollector keeps its signature. None of the ~26 per-collector files needed changes for the refactor itself.

probe.go had a third partial copy of the instantiate-and-cache loop, carrying a // TODO: Handle filters that node_exporter's copy had already solved. It now shares the registry, so that divergence is gone.

Net −117/+113 including the new flags and metadata.

The docs table becomes generated

Four collectors move to RegisterCollectorWithMetadata to record operator preconditions — the pg_stat_statements and pg_buffercache extensions, minimum server versions:

$ postgres_exporter --collector.list.markdown
| Collector | Default | Notes |
|---|---|---|
| `buffercache_summary` | disabled | Shared buffer cache summary; requires the `pg_buffercache` extension, PostgreSQL 16+ |
| `database` | enabled |  |
...
| `stat_statements` | disabled | Statement execution statistics; requires the `pg_stat_statements` extension |

This reproduces all 26 rows of the hand-written table in #1361, defaults included — which is a good sign for that table, it's accurate today. The point is that it stays accurate. --collector.list emits the same inventory as JSON for mdox or a CI drift check.

Runtime introspection

pg_collector_enabled{collector="..."} is now exposed, so which collectors an exporter actually has enabled is answerable from Prometheus across a fleet, rather than only by inspecting a process's command line.

Notes

  • --collector.disable-defaults comes for free from the registry (DisableDefaultCollectors is exported) but I left it unwired — adding a flag postgres_exporter doesn't have today is a UX call for maintainers, not part of a refactor.
  • Verified: --no-collector.X / --collector.X behave exactly as before, and the full suite passes (107 tests).
  • I'd suggest not blocking Create user facing documentation #1361 on this. Ship the hand-written table now; a slightly stale table is a much smaller problem than no docs, and this can replace it later.

Replaces the collector registry in this package with the one proposed in
prometheus/exporter-toolkit#429. The maps this file carried --
factories, collectorState, forcedCollectors, initiatedCollectors -- and
the flag registration, forced-state tracking, filtering and lazy
instantiation around them were near-verbatim copies of node_exporter's.

probe.go had a third partial copy of the instantiate-and-cache loop,
including a "TODO: Handle filters" that node_exporter's copy had already
solved. It now goes through the same registry, so that drift is gone.

registerCollector keeps its signature, so the per-collector files are
unchanged. Four collectors move to RegisterCollectorWithMetadata to
record what an operator needs for them to return data (the
pg_stat_statements and pg_buffercache extensions, minimum server
versions). That metadata is what makes the collector table in
docs/configuration.md generable rather than hand-maintained:

  postgres_exporter --collector.list.markdown

reproduces the table from prometheus-community#1361 exactly, and --collector.list emits the
same inventory as JSON for mdox or a CI drift check.

pg_collector_enabled is now exposed per collector, so which collectors a
running exporter has enabled is answerable from Prometheus rather than
only from the process's command line.

Signed-off-by: Nicolas Takashi <nicolastakashicavalcante@gmail.com>
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