Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions prometheus_client/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ def sample_line(samples):

om_samples: Dict[str, List[str]] = {}
for s in metric.samples:
# The text format has no native histograms, as in OpenMetrics 1.0.
if s.native_histogram:
continue
for suffix in ['_created', '_gsum', '_gcount']:
if s.name == metric.name + suffix:
# OpenMetrics specific sample, put in a gauge at the end.
Expand Down
13 changes: 13 additions & 0 deletions tests/test_exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ def test_gaugehistogram(self):
# HELP gh_gsum help
# TYPE gh_gsum gauge
gh_gsum 7.0
""", generate_latest(self.registry))

def test_native_histogram_is_skipped(self):
hfm = core.HistogramMetricFamily('nh', 'help', buckets=[('1.0', 4), ('+Inf', 5)], sum_value=7)
hfm.add_sample('nh', {}, 0, None, None, core.NativeHistogram(
5, 7, 0, 0.001, 0, (core.BucketSpan(0, 1),), None, (5,), None))
self.custom_collector(hfm)
self.assertEqual(b"""# HELP nh help
# TYPE nh histogram
nh_bucket{le="1.0"} 4.0
nh_bucket{le="+Inf"} 5.0
nh_count 5.0
nh_sum 7.0
""", generate_latest(self.registry))

def test_info(self):
Expand Down
Loading