Skip to content

Commit

Permalink
Remove spamming trace on Redis broadcast for Prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jan 16, 2025
1 parent 50cb844 commit 8daf73b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions c2cwsgiutils/prometheus.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit 8daf73b

Please sign in to comment.