Skip to content

Commit

Permalink
Reinitialize metrics on plugin initialize to ease testing
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Oct 30, 2024
1 parent 876b1c9 commit 01b9f23
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions kinto/plugins/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,15 @@ def includeme(config):
config.add_route("prometheus_metrics", "/__metrics__")
config.add_view(metrics_view, route_name="prometheus_metrics")

# Reinitialize the registry on initialization.
# This is mainly useful in tests, where we plugins is included
# several times with different settings.
registry = get_registry()
for collector in _METRICS.values():
try:
registry.unregister(collector)
except KeyError: # pragma: no cover
pass
_METRICS.clear()

config.registry.registerUtility(PrometheusService(), metrics.IMetricsService)

0 comments on commit 01b9f23

Please sign in to comment.