From 76dd636151735671be74ba9d55f773e190e22827 Mon Sep 17 00:00:00 2001 From: Julien Moutinho Date: Fri, 13 May 2022 22:40:46 +0200 Subject: [PATCH core.sr.ht] Fix Unix socket support in RedisQueueCollector The broker URL is not necessarily in the format expected by Redis.from_url Especially, Redis.from_url supports this format for Unix sockets: unix:///run/redis-sourcehut-metasrht/redis.sock?db=0 See https://redis-py.readthedocs.io/en/stable/#redis.ConnectionPool.from_url Whereas Celery+Kombu support Redis but also other transports and thus expect another scheme: redis+socket:///run/redis-sourcehut-metasrht/redis.sock?virtual_host=1 See https://docs.celeryproject.org/en/stable/userguide/configuration.html#redis-backend-settings and https://github.com/celery/celery/blob/e5d99801e4b56a02af4a2e183879c767228d2817/celery/backends/redis.py#L299-L352 and https://github.com/celery/kombu/blob/master/kombu/utils/url.py --- srht/metrics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/srht/metrics.py b/srht/metrics.py index 68caf8e..2df5777 100644 --- a/srht/metrics.py +++ b/srht/metrics.py @@ -1,11 +1,12 @@ import time +from celery import Celery from prometheus_client.metrics_core import GaugeMetricFamily from redis import Redis, ResponseError class RedisQueueCollector: def __init__(self, broker, name, documentation, queue_name="celery"): - self.redis = Redis.from_url(broker) + self.redis = Celery("collector", broker=broker).connection_for_read().channel().client self.queue_name = queue_name self.name = name self.documentation = documentation -- 2.35.1