Skip to content

Commit

Permalink
Add upper_bound tag for the total count when collecting histograms bu…
Browse files Browse the repository at this point in the history
…ckets (#3777)

* Add upper_bound tag for the total count when collecting histograms bucket

* Use append instead of + operator
  • Loading branch information
mfpierre authored and hkaj committed May 22, 2019
1 parent 8f0d3b9 commit dbec73a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ def _submit_gauges_from_histogram(self, metric_name, metric, scraper_config, hos
)
elif sample[self.SAMPLE_NAME].endswith("_count"):
tags = self._metric_tags(metric_name, val, sample, scraper_config, hostname)
if scraper_config['send_histograms_buckets']:
tags.append("upper_bound:none")
self.gauge(
"{}.{}.count".format(scraper_config['namespace'], metric_name),
val,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,10 @@ def _submit_gauges_from_histogram(
# histograms do not have a value attribute
val = getattr(metric, self.METRIC_TYPES[4]).sample_count
if self._is_value_valid(val):
self._submit_gauge("{}.count".format(name), val, metric, custom_tags)
if send_histograms_buckets:
self._submit_gauge("{}.count".format(name), val, metric, custom_tags=custom_tags + ["upper_bound:none"])
else:
self._submit_gauge("{}.count".format(name), val, metric, custom_tags)
else:
self.log.debug("Metric value is not supported for metric {}.count.".format(name))
val = getattr(metric, self.METRIC_TYPES[4]).sample_sum
Expand Down
2 changes: 1 addition & 1 deletion datadog_checks_base/tests/test_openmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_submit_histogram(aggregator, mocked_prometheus_check, mocked_prometheus
check = mocked_prometheus_check
check.submit_openmetric('custom.histogram', _histo, mocked_prometheus_scraper_config)
aggregator.assert_metric('prometheus.custom.histogram.sum', 1337, tags=[], count=1)
aggregator.assert_metric('prometheus.custom.histogram.count', 4, tags=[], count=1)
aggregator.assert_metric('prometheus.custom.histogram.count', 4, tags=['upper_bound:none'], count=1)
aggregator.assert_metric('prometheus.custom.histogram.count', 1, tags=['upper_bound:1.0'], count=1)
aggregator.assert_metric('prometheus.custom.histogram.count', 2, tags=['upper_bound:31104000.0'], count=1)
aggregator.assert_metric('prometheus.custom.histogram.count', 3, tags=['upper_bound:432400000.0'], count=1)
Expand Down
2 changes: 1 addition & 1 deletion datadog_checks_base/tests/test_prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def test_submit_histogram(mocked_prometheus_check):
check._submit('custom.histogram', _histo)
check.gauge.assert_has_calls(
[
mock.call('prometheus.custom.histogram.count', 42, [], hostname=None),
mock.call('prometheus.custom.histogram.count', 42, ['upper_bound:none'], hostname=None),
mock.call('prometheus.custom.histogram.sum', 3.14, [], hostname=None),
mock.call('prometheus.custom.histogram.count', 33, ['upper_bound:12.7'], hostname=None),
mock.call('prometheus.custom.histogram.count', 666, ['upper_bound:18.2'], hostname=None),
Expand Down

0 comments on commit dbec73a

Please sign in to comment.