From 8daf73bdf24efd571b358497320083c9985eebd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Thu, 16 Jan 2025 12:14:44 +0100 Subject: [PATCH] Remove spamming trace on Redis broadcast for Prometheus --- c2cwsgiutils/prometheus.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/c2cwsgiutils/prometheus.py b/c2cwsgiutils/prometheus.py index 5b654eade..b51e43c29 100644 --- a/c2cwsgiutils/prometheus.py +++ b/c2cwsgiutils/prometheus.py @@ -1,5 +1,6 @@ """Every thing we needs to have the metrics in Prometheus.""" +import logging import os import re from collections.abc import Generator, Iterable @@ -11,10 +12,12 @@ import prometheus_client.multiprocess import prometheus_client.registry import pyramid.config +import redis.exceptions from c2cwsgiutils import broadcast, redis_utils from c2cwsgiutils.debug.utils import dump_memory_maps +_LOG = logging.getLogger(__name__) _NUMBER_RE = re.compile(r"^[0-9]+$") MULTI_PROCESS_COLLECTOR_BROADCAST_CHANNELS = [ "c2cwsgiutils_prometheus_collector_gc", @@ -117,9 +120,12 @@ class MultiProcessCustomCollector(prometheus_client.registry.Collector): def collect(self) -> Generator[prometheus_client.core.Metric, None, None]: results: list[list[SerializedMetric]] = [] for channel in MULTI_PROCESS_COLLECTOR_BROADCAST_CHANNELS: - result = broadcast.broadcast(channel, expect_answers=True) - if result is not None: - results.extend(cast(Iterable[list[SerializedMetric]], result)) + try: + result = broadcast.broadcast(channel, expect_answers=True) + if result is not None: + results.extend(cast(Iterable[list[SerializedMetric]], result)) + except redis.exceptions.ConnectionError: + _LOG.error("Failed to get the metrics from the other processes") return _deserialize_collected_data(results)