fix: prevent Summary quantiles from collapsing to the minimum observation#2316
Open
manduinca wants to merge 1 commit into
Open
fix: prevent Summary quantiles from collapsing to the minimum observation#2316manduinca wants to merge 1 commit into
manduinca wants to merge 1 commit into
Conversation
…tion CKMSQuantiles returned the minimum observation for every targeted quantile whenever 2*epsilon >= 1-quantile (e.g. quantile(0.9, 0.05) or quantile(0.99, 0.005)). At the boundary the error function permits a sample's uncertainty (delta) to reach the order of n at low ranks, which broke both the query and compression: - get() stopped at the first sample whose maximum rank exceeded desiredRank + f(desiredRank)/2 and returned the preceding sample. A freshly inserted low-rank sample (delta = f(r) - 1) then made the scan stop almost immediately, returning a value near the minimum. get() now returns the sample whose possible-rank interval is centered closest to the desired rank. - compress() bounded merges by the error function at the left edge only, where f is huge for low ranks, so it merged away all resolution between the median and the maximum. Merges are now bounded by the error function over the whole rank interval the merged sample would span, via a new f(lo, hi) overload (f(r) delegates to f(r, r), so single-rank behavior is unchanged). Adds regression tests for the boundary configuration. Fixes prometheus#2292 Signed-off-by: Jean Pierre Mandujano G. <jeanpierre.mandujano@gmail.com>
manduinca
requested review from
dhoard,
fstab,
jaydeluca and
zeitlinger
as code owners
July 19, 2026 23:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2292
When a targeted quantile has
2*epsilon >= 1 - quantile, all reported quantiles could collapse to the minimum observation. The query scan stopped too early: a freshly inserted low-rank sample can carry adeltaon the order ofn, so the runningrank + g + deltaexceeded the target far sooner than it should and returned a value near the minimum.The fix has two parts, matching the diagnosis in the issue.
compress()now keeps a merged sample from spanning a quantile's target rank, and the query uses the minimum of the error function over a sample's rank interval[lo, hi]rather than at a single point. To support that I split the single-argumentf(r)intof(lo, hi)(the plain error function isf(r, r)), which is numerically identical for the existing call sites.Added a regression test that reproduces the collapse and asserts distinct quantiles.
CKMSQuantilesTestpasses (18 tests).