diff options
author | reivilibre <oliverw@matrix.org> | 2022-09-14 15:29:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-14 15:29:05 +0000 |
commit | cf65433de26ecce551c64e56d9ee8435c99defab (patch) | |
tree | d849f60cd2df2660ced4818c43cc1c0ae6d008b6 /synapse/util/metrics.py | |
parent | Remove unused method in `synapse.api.auth.Auth`. (#13795) (diff) | |
download | synapse-cf65433de26ecce551c64e56d9ee8435c99defab.tar.xz |
Fix a memory leak when running the unit tests. (#13798)
Diffstat (limited to '')
-rw-r--r-- | synapse/util/metrics.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/synapse/util/metrics.py b/synapse/util/metrics.py index 9687120ebf..165480bdbe 100644 --- a/synapse/util/metrics.py +++ b/synapse/util/metrics.py @@ -15,7 +15,7 @@ import logging from functools import wraps from types import TracebackType -from typing import Awaitable, Callable, Generator, List, Optional, Type, TypeVar +from typing import Awaitable, Callable, Dict, Generator, Optional, Type, TypeVar from prometheus_client import CollectorRegistry, Counter, Metric from typing_extensions import Concatenate, ParamSpec, Protocol @@ -220,21 +220,21 @@ class DynamicCollectorRegistry(CollectorRegistry): def __init__(self) -> None: super().__init__() - self._pre_update_hooks: List[Callable[[], None]] = [] + self._pre_update_hooks: Dict[str, Callable[[], None]] = {} def collect(self) -> Generator[Metric, None, None]: """ Collects metrics, calling pre-update hooks first. """ - for pre_update_hook in self._pre_update_hooks: + for pre_update_hook in self._pre_update_hooks.values(): pre_update_hook() yield from super().collect() - def register_hook(self, hook: Callable[[], None]) -> None: + def register_hook(self, metric_name: str, hook: Callable[[], None]) -> None: """ Registers a hook that is called before metric collection. """ - self._pre_update_hooks.append(hook) + self._pre_update_hooks[metric_name] = hook |