collector: use the shared exporter-toolkit collector registry (PoC) - #1366
Draft
nicolastakashi wants to merge 1 commit into
Draft
collector: use the shared exporter-toolkit collector registry (PoC)#1366nicolastakashi wants to merge 1 commit into
nicolastakashi wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-toolkitagainst 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'sfactories/collectorState/forcedCollectors/initiatedCollectorsmaps, and the flag registration, forced-state tracking, filtering and lazy instantiation around them, are near-verbatim copies of node_exporter's. They're replaced bytoolkit.Registry, which is generic over the collector interface — soUpdate(ctx, instance, ch)is untouched, andregisterCollectorkeeps its signature. None of the ~26 per-collector files needed changes for the refactor itself.probe.gohad a third partial copy of the instantiate-and-cache loop, carrying a// TODO: Handle filtersthat 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
RegisterCollectorWithMetadatato record operator preconditions — thepg_stat_statementsandpg_buffercacheextensions, minimum server versions: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.listemits 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-defaultscomes for free from the registry (DisableDefaultCollectorsis 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.--no-collector.X/--collector.Xbehave exactly as before, and the full suite passes (107 tests).