From 9c77959e86cdd06c1dc00dc2028c5aff69b67fd7 Mon Sep 17 00:00:00 2001 From: FadingFog Date: Fri, 8 May 2026 00:55:46 +0300 Subject: [PATCH 1/2] Fixed prometheus multiprocessing registry --- taskiq/middlewares/prometheus_middleware.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/taskiq/middlewares/prometheus_middleware.py b/taskiq/middlewares/prometheus_middleware.py index 01f14867..189d62b2 100644 --- a/taskiq/middlewares/prometheus_middleware.py +++ b/taskiq/middlewares/prometheus_middleware.py @@ -84,17 +84,19 @@ def startup(self) -> None: This function starts prometheus server. It starts it only in case if it's a worker process. """ - from prometheus_client import REGISTRY, start_http_server # noqa: PLC0415 + from prometheus_client import CollectorRegistry, start_http_server # noqa: PLC0415 from prometheus_client.multiprocess import ( # noqa: PLC0415 MultiProcessCollector, ) if self.broker.is_worker_process: try: - MultiProcessCollector(REGISTRY) + registry = CollectorRegistry() + MultiProcessCollector(registry) start_http_server( port=self.server_port, addr=self.server_addr, + registry=registry, ) except OSError as exc: logger.debug("Cannot start prometheus server: %s", exc) From 7e30af26f45fd89756531949c82178dc591e1793 Mon Sep 17 00:00:00 2001 From: FadingFog Date: Fri, 8 May 2026 10:06:23 +0300 Subject: [PATCH 2/2] Refactored via pre-commit --- taskiq/middlewares/prometheus_middleware.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/taskiq/middlewares/prometheus_middleware.py b/taskiq/middlewares/prometheus_middleware.py index 189d62b2..56837cf3 100644 --- a/taskiq/middlewares/prometheus_middleware.py +++ b/taskiq/middlewares/prometheus_middleware.py @@ -84,7 +84,10 @@ def startup(self) -> None: This function starts prometheus server. It starts it only in case if it's a worker process. """ - from prometheus_client import CollectorRegistry, start_http_server # noqa: PLC0415 + from prometheus_client import ( # noqa: PLC0415 + CollectorRegistry, + start_http_server, + ) from prometheus_client.multiprocess import ( # noqa: PLC0415 MultiProcessCollector, )