Skip to content

Commit

Permalink
ensure that counts of prometheus histograms are integers (elastic#1354)
Browse files Browse the repository at this point in the history
* ensure that counts of prometheus histograms are integers

* update changelog
  • Loading branch information
beniwohli authored Oct 13, 2021
1 parent 69af4aa commit 4eb8be5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ endif::[]
//===== Bug fixes
=== Unreleased
// Unreleased changes go here
// When the next release happens, nest these changes under the "Python Agent version 6.x" heading
//[float]
//===== Features
//
//
[float]
===== Bug fixes
* ensure that Prometheus histograms are encoded correctly for APM Server {pull}1354[#1354]
[[release-notes-6.x]]
=== Python Agent version 6.x
Expand Down
2 changes: 1 addition & 1 deletion elasticapm/metrics/sets/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _prom_histogram_handler(self, name, samples, unit):
sample = samples[sample_pos]
if "le" in sample.labels:
values.append(float(sample.labels["le"]))
counts.append(sample.value - prev_val)
counts.append(int(sample.value - prev_val))
prev_val = sample.value
sample_pos += 1

Expand Down
3 changes: 3 additions & 0 deletions tests/metrics/prometheus_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,14 @@ def test_histogram(elasticapm_client, prometheus):
data = list(metricset.collect())
assert data[0]["samples"]["prometheus.metrics.histo"]["values"] == [0.5, 5.5, 55.0, 100.0]
assert data[0]["samples"]["prometheus.metrics.histo"]["counts"] == [2, 1, 3, 1]
assert all(isinstance(v, int) for v in data[0]["samples"]["prometheus.metrics.histo"]["counts"])

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

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

0 comments on commit 4eb8be5

Please sign in to comment.