Skip to content

Commit 86e05f0

Browse files
committed
fix: support timestamps in prometheus 0.19
prometheus/client_python#967 jiggers with the format of multiprocess metrics in a way that broke our custom aggregation.
1 parent 876ed0f commit 86e05f0

File tree

3 files changed

+133
-131
lines changed

3 files changed

+133
-131
lines changed

ampel/metrics/prometheus.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ def write_metrics(metrics: Collection[Metric], histogram_file: str, counter_file
142142
continue
143143

144144
for sample in metric.samples:
145-
# prometheus_client 0.4+ adds extra fields
146-
name, labels, value = sample[:3]
147145
key = mmap_dict.mmap_key(
148-
metric.name, name, list(labels.keys()), list(labels.values()), metric.documentation,
146+
metric.name, sample.name, list(sample.labels.keys()), list(sample.labels.values()), metric.documentation,
149147
)
150-
sink.write_value(key, value)
148+
# prometheus_client 0.19.0 adds timestamps, but only for MultiProcessValues
149+
if hasattr(sample, "timestamp"):
150+
sink.write_value(key, sample.value, sample.timestamp or 0.0)
151+
else:
152+
sink.write_value(key, sample.value)
151153
finally:
152154
histograms.close()
153155
counters.close()

ampel/test/test_concurrent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ async def test_multiprocess_metrics(prometheus_multiproc_dir):
174174
if sample
175175
}
176176
read_mmap = lambda fname: {
177-
k: v
178-
for k, v, p in mmap_dict.MmapedDict.read_all_values_from_file(
177+
item[0]: item[1]
178+
for item in mmap_dict.MmapedDict.read_all_values_from_file(
179179
prometheus_multiproc_dir / fname
180180
)
181181
}

0 commit comments

Comments
 (0)