Skip to content

Commit 8b123b3

Browse files
committed
Fix presenting duplicate metrics
If the collection takes too long, a new collection can occur before the preivous has finished. This causes duplicate metrics to be presented to Prometheus. Fix this by introducing a semaphore for collection.
1 parent db99971 commit 8b123b3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

radosgw_usage_exporter.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(
3333
self.store = store
3434
self.insecure = insecure
3535
self.timeout = timeout
36+
self.collect_semaphore = False
3637

3738
# helpers for default schema
3839
if not self.host.startswith("http"):
@@ -53,6 +54,12 @@ def collect(self):
5354
http://docs.ceph.com/docs/master/radosgw/adminops/#get-bucket-info
5455
"""
5556

57+
if self.collect_semaphore:
58+
logging.debug("Previous collection still in progress at time "
59+
f"{time.time()}, cancelling collection.")
60+
return
61+
self.collect_semaphore = True
62+
5663
start = time.time()
5764
# setup empty prometheus metrics
5865
self._setup_empty_prometheus_metrics()
@@ -84,6 +91,8 @@ def collect(self):
8491
for metric in list(self._prometheus_metrics.values()):
8592
yield metric
8693

94+
self.collect_semaphore = False
95+
8796
def _session(self):
8897
"""
8998
Setup Requests connection settings.

0 commit comments

Comments
 (0)