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
4 changes: 2 additions & 2 deletions prometheus_client/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,10 @@ def __init__(self,

def _prepare_buckets(self, source_buckets: Sequence[Union[float, str]]) -> None:
buckets = [float(b) for b in source_buckets]
if buckets != sorted(buckets):
if any(not lower < upper for lower, upper in zip(buckets, buckets[1:])):
# This is probably an error on the part of the user,
# so raise rather than sorting for them.
raise ValueError('Buckets not in sorted order')
raise ValueError('Buckets not in strictly increasing order')
if buckets and buckets[-1] != INF:
buckets.append(INF)
if len(buckets) < 2:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,10 @@ def test_setting_buckets(self):
self.assertRaises(ValueError, Histogram, 'h', 'help', registry=None, buckets=[])
self.assertRaises(ValueError, Histogram, 'h', 'help', registry=None, buckets=[float("inf")])
self.assertRaises(ValueError, Histogram, 'h', 'help', registry=None, buckets=[3, 1])
self.assertRaises(ValueError, Histogram, 'h', 'help', registry=None, buckets=[1, 1, 2])
self.assertRaises(ValueError, Histogram, 'h', 'help', registry=None, buckets=[1, '1.0'])
self.assertRaises(ValueError, Histogram, 'h', 'help', registry=None, buckets=[1, float("inf"), float("inf")])
self.assertRaises(ValueError, Histogram, 'h', 'help', registry=None, buckets=[1, float("nan")])

def test_labels(self):
self.assertRaises(ValueError, Histogram, 'h', 'help', registry=None, labelnames=['le'])
Expand Down