Skip to content

refactor: use custom registry instead of defaults, fix filteredTargets mutations#916

Merged
burningalchemist merged 2 commits intomasterfrom
fix/customregistry
Mar 2, 2026
Merged

refactor: use custom registry instead of defaults, fix filteredTargets mutations#916
burningalchemist merged 2 commits intomasterfrom
fix/customregistry

Conversation

@burningalchemist
Copy link
Owner

This pull request refactors how Prometheus registries are handled in the SQL exporter application. The main change is to make the registry used for metrics collection configurable, rather than relying on a global default. This improves flexibility and testability by allowing custom registries to be injected where needed.

Registry handling improvements:

  • Updated the Exporter interface and its implementation in exporter.go to use a custom Prometheus registry instead of the default global registry, including changes to the constructor and context-handling methods. [1] [2] [3] [4]
  • Modified the registerScrapeErrorMetric function to accept a registry parameter and register the scrape error metric with the provided registry instead of the global one.

Application and HTTP handler updates:

  • Changed the instantiation of the exporter in main.go to pass in the registry explicitly, and updated HTTP handler setup to use the custom registry for metric instrumentation. [1] [2]
  • Refactored the ExporterHandlerFor function in promhttp.go to accept a registry parameter and use it when gathering metrics, improving handler flexibility. [1] [2]

@burningalchemist burningalchemist changed the title refactor: use custom registry instead of default global registry refactor: use custom registry instead of defaults, fix filteredTargets mutations Mar 2, 2026
@burningalchemist burningalchemist merged commit d7a8069 into master Mar 2, 2026
4 checks passed
@burningalchemist burningalchemist deleted the fix/customregistry branch March 2, 2026 23:13
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