Skip to content

Commit

Permalink
fix: support timestamps in prometheus 0.18
Browse files Browse the repository at this point in the history
prometheus/client_python#967 jiggers with
the format of multiprocess metrics in a way that broke our custom
aggregation.
  • Loading branch information
jvansanten committed Jan 8, 2024
1 parent 876ed0f commit e6a01dd
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 131 deletions.
10 changes: 6 additions & 4 deletions ampel/metrics/prometheus.py
Expand Up @@ -142,12 +142,14 @@ def write_metrics(metrics: Collection[Metric], histogram_file: str, counter_file
continue

for sample in metric.samples:
# prometheus_client 0.4+ adds extra fields
name, labels, value = sample[:3]
key = mmap_dict.mmap_key(
metric.name, name, list(labels.keys()), list(labels.values()), metric.documentation,
metric.name, sample.name, list(sample.labels.keys()), list(sample.labels.values()), metric.documentation,
)
sink.write_value(key, value)
# prometheus_client 0.18.0 adds timestamps, but only for MultiProcessValues
try:
sink.write_value(key, sample.value, sample.timestamp or 0.0) # type: ignore[call-arg]
except TypeError:
sink.write_value(key, sample.value) # type: ignore[call-arg]
finally:
histograms.close()
counters.close()
4 changes: 2 additions & 2 deletions ampel/test/test_concurrent.py
Expand Up @@ -174,8 +174,8 @@ async def test_multiprocess_metrics(prometheus_multiproc_dir):
if sample
}
read_mmap = lambda fname: {
k: v
for k, v, p in mmap_dict.MmapedDict.read_all_values_from_file(
item[0]: item[1]
for item in mmap_dict.MmapedDict.read_all_values_from_file(
prometheus_multiproc_dir / fname
)
}
Expand Down

0 comments on commit e6a01dd

Please sign in to comment.