Skip to content

Commit 1ce17eb

Browse files
add comment to explain the need to access private prometheus_client attributes
1 parent c24234d commit 1ce17eb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/service/prometheus/prometheus_publisher.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ def remove_gauge(self, name: str, id: uuid.UUID) -> None:
6262

6363
if full_name in self._gauges:
6464
gauge = self._gauges[full_name]
65+
66+
# IMPORTANT: Accessing private attributes of prometheus_client.Gauge
67+
# This is necessary because the prometheus_client library does not provide
68+
# public methods to:
69+
# 1. List existing metrics with their labels (_metrics.items())
70+
# 2. Access label names for a gauge (_labelnames)
71+
# We need this functionality to selectively remove gauge metrics
72+
# based on the "request" label matching the provided ID.
73+
# If prometheus_client adds public APIs for this in the future,
74+
# this should be refactored to use those instead.
6575
for labels, _ in gauge._metrics.items():
6676
labels_dict = dict(zip(gauge._labelnames, labels))
6777
if labels_dict.get("request") == str(id):

0 commit comments

Comments
 (0)