File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed
Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change 11import importlib
2- import typing
32
43import prometheus_client
54from django .conf import settings
65from prometheus_client .metrics import MetricWrapperBase
76from prometheus_client .multiprocess import MultiProcessCollector
87
9- T = typing .TypeVar ("T" , bound = MetricWrapperBase )
10-
118
129class Histogram (prometheus_client .Histogram ):
1310 DEFAULT_BUCKETS = settings .PROMETHEUS_HISTOGRAM_BUCKETS
@@ -28,15 +25,15 @@ def reload_metrics(*metric_module_names: str) -> None:
2825 when needed.
2926 """
3027
28+ registry = prometheus_client .REGISTRY
29+
3130 for module_name in metric_module_names :
3231 metrics_module = importlib .import_module (module_name )
3332
34- _collectors = metrics_module .__dict__ .values ()
35-
36- for collector in [
37- * (registry := prometheus_client .REGISTRY )._collector_to_names
38- ]:
39- if collector in _collectors :
40- registry .unregister (collector )
33+ for module_attr in vars (metrics_module ).values ():
34+ if isinstance (module_attr , MetricWrapperBase ):
35+ # Unregister the collector from the registry
36+ print ("unregistering" , module_attr )
37+ registry .unregister (module_attr )
4138
4239 importlib .reload (metrics_module )
You can’t perform that action at this time.
0 commit comments