Repository navigation
Conversation
_prepare_buckets accepted any non-decreasing list, so buckets=[0.1, 0.5, 0.5, 1.0] exposed two series with le="0.5" and a NaN bound passed too. Require strictly increasing bounds, as client_golang does. Signed-off-by: Christopher Krah <github@christopher-krah.com>
csmarchbanks
left a comment
There was a problem hiding this comment.
Thanks! I think we need a test case for just [float("nan")] as well. I prefer raising as it probably indicates a typo or something, it doesn't make sense to duplicate them.
A single NaN bound skipped the pairwise order check, so buckets=[float("nan")]
was accepted and exposed a le="NaN" series.
Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
chrikrah
left a comment
There was a problem hiding this comment.
@csmarchbanks Added. It closes the lone-NaN case the description flagged: a one-element list has no pairs, so 5739cf9 still accepted [float("nan")] and exposed a le="NaN" series. The new commit rejects any NaN bound up front, before the order check.
$ PYTHONPATH=. python -m pytest tests/test_core.py -q -p no:cacheprovider # Python 3.12.3, pytest 9.1.1
new head: 114 passed
same tests, metrics.py from 5739cf9: 1 failed, 113 passed (test_setting_buckets, the [nan] case)
$ flake8 prometheus_client/ tests/ # flake8 7.3, via tox env deps
$ isort --check prometheus_client/ tests/ # isort 5.10.1
both clean
Kept raising for repeated bounds, as you prefer. If a separate NaN message reads as noise next to the order error, I'd still keep it: "not in strictly increasing order" would send someone hunting for a sort problem that isn't there. Anything else you want in this one before it merges?
A
NaNbucket bound passesHistogram._prepare_buckets(prometheus_client/metrics.py:642), becausebuckets != sorted(buckets)never fires on it. The histogram then exposes anle="NaN"series that no observation can land in. This change requires strictly increasing bounds:[0.1, nan, 1.0]and a repeated bound such as[0.1, 0.5, 0.5, 1.0]now raiseValueErrorat construction. No issue exists for this.Before, at
9cd073c:The repeated bound is the part to decide. Prometheus ingests it today, since both
le="0.5"series always carry the same value. Raising there buys consistency withclient_golang("histogram buckets must be in increasing order",prometheus/histogram.go:590), not ingestion safety. Code that passes one today gets aValueErrorwith this change. A lone[nan]still passes, as the check compares pairs.Verification
This touches the same function as #1104. I will rebase onto whichever lands first.
@csmarchbanks, should a repeated bound raise as here, or be dropped silently as
client_javadoes?