Skip to content

Commit 4eb8be5

Browse files
authored
ensure that counts of prometheus histograms are integers (#1354)
* ensure that counts of prometheus histograms are integers * update changelog
1 parent 69af4aa commit 4eb8be5

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.asciidoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ endif::[]
3030
//===== Bug fixes
3131
3232
33+
=== Unreleased
34+
35+
// Unreleased changes go here
36+
// When the next release happens, nest these changes under the "Python Agent version 6.x" heading
37+
//[float]
38+
//===== Features
39+
//
40+
//
41+
[float]
42+
===== Bug fixes
43+
* ensure that Prometheus histograms are encoded correctly for APM Server {pull}1354[#1354]
44+
3345
[[release-notes-6.x]]
3446
=== Python Agent version 6.x
3547

elasticapm/metrics/sets/prometheus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def _prom_histogram_handler(self, name, samples, unit):
9595
sample = samples[sample_pos]
9696
if "le" in sample.labels:
9797
values.append(float(sample.labels["le"]))
98-
counts.append(sample.value - prev_val)
98+
counts.append(int(sample.value - prev_val))
9999
prev_val = sample.value
100100
sample_pos += 1
101101

tests/metrics/prometheus_tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,14 @@ def test_histogram(elasticapm_client, prometheus):
133133
data = list(metricset.collect())
134134
assert data[0]["samples"]["prometheus.metrics.histo"]["values"] == [0.5, 5.5, 55.0, 100.0]
135135
assert data[0]["samples"]["prometheus.metrics.histo"]["counts"] == [2, 1, 3, 1]
136+
assert all(isinstance(v, int) for v in data[0]["samples"]["prometheus.metrics.histo"]["counts"])
136137

137138
assert data[1]["samples"]["prometheus.metrics.histowithlabel"]["values"] == [0.5, 5.5, 55.0, 100.0]
138139
assert data[1]["samples"]["prometheus.metrics.histowithlabel"]["counts"] == [1, 1, 1, 0]
140+
assert all(isinstance(v, int) for v in data[1]["samples"]["prometheus.metrics.histowithlabel"]["counts"])
139141
assert data[1]["tags"] == {"alabel": "foo", "anotherlabel": "baz"}
140142

141143
assert data[2]["samples"]["prometheus.metrics.histowithlabel"]["values"] == [0.5, 5.5, 55.0, 100.0]
142144
assert data[2]["samples"]["prometheus.metrics.histowithlabel"]["counts"] == [0, 0, 0, 1]
145+
assert all(isinstance(v, int) for v in data[2]["samples"]["prometheus.metrics.histowithlabel"]["counts"])
143146
assert data[2]["tags"] == {"alabel": "foo", "anotherlabel": "bazzinga"}

0 commit comments

Comments
 (0)