Title: Summary quantiles collapse to the minimum observation when 2·epsilon ≥ 1−quantile · Issue #2292 · prometheus/client_java · GitHub
Open Graph Title: Summary quantiles collapse to the minimum observation when 2·epsilon ≥ 1−quantile · Issue #2292 · prometheus/client_java
X Title: Summary quantiles collapse to the minimum observation when 2·epsilon ≥ 1−quantile · Issue #2292 · prometheus/client_java
Description: Version io.prometheus:prometheus-metrics-core:1.8.0 (the affected code in CKMSQuantiles is unchanged since at least 1.3.x and is still present on main). Reproducer import io.prometheus.metrics.core.metrics.Summary; import io.prometheus.m...
Open Graph Description: Version io.prometheus:prometheus-metrics-core:1.8.0 (the affected code in CKMSQuantiles is unchanged since at least 1.3.x and is still present on main). Reproducer import io.prometheus.metrics.core...
X Description: Version io.prometheus:prometheus-metrics-core:1.8.0 (the affected code in CKMSQuantiles is unchanged since at least 1.3.x and is still present on main). Reproducer import io.prometheus.metrics.core...
Opengraph URL: https://github.com/prometheus/client_java/issues/2292
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Summary quantiles collapse to the minimum observation when 2·epsilon ≥ 1−quantile","articleBody":"## Version\n\n`io.prometheus:prometheus-metrics-core:1.8.0` (the affected code in `CKMSQuantiles` is\nunchanged since at least 1.3.x and is still present on `main`).\n\n## Reproducer\n\n```java\nimport io.prometheus.metrics.core.metrics.Summary;\nimport io.prometheus.metrics.model.registry.PrometheusRegistry;\nimport io.prometheus.metrics.model.snapshots.Quantile;\nimport io.prometheus.metrics.model.snapshots.SummarySnapshot;\n\nimport java.util.ArrayList;\nimport java.util.Collections;\nimport java.util.List;\nimport java.util.Random;\n\npublic class SummaryQuantileBugRepro {\n\n public static void main(String[] args) {\n Summary summary =\n Summary.builder()\n .name(\"request_latency\")\n .help(\"reproducer\")\n .quantile(0.9, 0.05)\n .quantile(0.99, 0.005)\n .register(new PrometheusRegistry());\n\n // observe the values 1..100_000 shuffled, so the true p90 is 90_000 and p99 is 99_000\n List\u003cInteger> values = new ArrayList\u003c>();\n for (int i = 1; i \u003c= 100_000; i++) {\n values.add(i);\n }\n Collections.shuffle(values, new Random(42));\n for (int v : values) {\n summary.observe(v);\n }\n\n SummarySnapshot.SummaryDataPointSnapshot dataPoint = summary.collect().getDataPoints().get(0);\n for (Quantile q : dataPoint.getQuantiles()) {\n System.out.printf(\n \"quantile %.2f: reported = %10.1f, expected ~ %10.1f%n\",\n q.getQuantile(), q.getValue(), q.getQuantile() * 100_000);\n }\n }\n}\n```\n\nOutput with 1.8.0:\n\n```\nquantile 0.90: reported = 1.0, expected ~ 90000.0\nquantile 0.99: reported = 1.0, expected ~ 99000.0\n```\n\nBoth quantiles report the **minimum** of all 100,000 observations. The result does not\ndepend on the input distribution or the shuffle seed. A single targeted quantile\n`quantile(0.99, 0.005)` reproduces it too.\n\n## How we found it\n\nIn our application we had\n\n```java\n.quantile(0.9, 0.05)\n.quantile(0.99, 0.005)\n```\n\non a latency Summary. It reported `p90 == p99 == 0.6ms` while a\nclassic `Histogram` fed by the same observations (cross-checked against an in-process\nexact-percentile counter) showed p90 = 2ms, p99 = 44ms. The reported value was below the\ntrue median. Adding a `.quantile(0.5, 0.05)` softens the failure but doesn't fix it: get(0.99)\nthen returns a value from around the 85th percentile.\n\n## Observations\n\n`CKMSQuantiles`:\n\n1. **`compress()` destroys the sketch.** The error function from the CKMS paper\n (definition 5) allows a sample below a target `(q, ε)` at rank `r` to have width\n `2ε(n−r)/(1−q)`. When `2ε ≥ 1−q` — which holds with equality for both `(0.9, 0.05)` and\n `(0.99, 0.005)` — this is `≥ n−r`: one sample may span every rank from `r` to `n`.\n `compress()` then merges away everything between the middle of the distribution and the\n maximum; the sample list collapses to just a few samples no matter how many values are inserted.\n\n2. **`get()` stops at the first wide sample.** The scan stops at the first sample with\n `r + g + delta > desiredRank + f(desiredRank)/2` and returns the previous sample's value.\n That rule is only correct when `g + delta` is small for all samples up to the target\n rank. Below a targeted quantile, deltas may legally be of order `n` — and freshly\n inserted samples get `delta = f(r) − 1` while `get()` flushes the insert buffer right\n before scanning, so maximally-wide fresh samples are always present at query time. The\n scan therefore stops far before the target rank.\n\n## Tightening error/epsilon avoids the issue\n\nThe tight-epsilon (0.01 for p90, 0.001 for p99) Summary agrees with the histogram-derived p99,\nwhile the identically-fed boundary-epsilon (0.05 for p90, 0.005 for p99) Summaries report `p90 == p99` from\nthe very same measurements. So the failure is fully determined by the quantile\nconfiguration, not by the data.\n\n## Side note\n\nI have a fix with reproducer tests ready and happy to open a PR: \nit bounds merges in compress() so a sample can never span across the accuracy window of a target quantile, \nand changes get() to select the sample whose rank interval is centered closest to the desired rank.\nWith the reproducer config, get(0.99) goes from returning the minimum observation to a rank-accurate value.\nThe full existing test suite passes.\n\n\n\n","author":{"url":"https://github.com/olegkovalenko","@type":"Person","name":"olegkovalenko"},"datePublished":"2026-07-08T13:15:37Z","url":"https://github.com/prometheus/client_java/issues/2292"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8c4ea5f0-b958-ade5-15bc-30cadddbdb29 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D9A:5C806:4B894:644D6:6AFBA2FA |
| html-safe-nonce | 3dd24aa1c8dccd8a5d2bed5752078b4f9328fa6806179949e228f43e20078e97 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDlBOjVDODA2OjRCODk0OjY0NEQ2OjZBRkJBMkZBIiwidmlzaXRvcl9pZCI6IjUwMjUzMzk3Nzk0MDM0NTcyNzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f3abfdba0799f78f20f945dd8a3e93365157ae703d40e646e8c410a5b9f379b4 |
| hovercard-subject-tag | issue:4837798559 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/prometheus/client_java/2292/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1b4e0eda18592f9c7ce27d41d4a5d5fa97e467b6368eeb34199b3cf84ac73655/prometheus/client_java/issues/2292 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1b4e0eda18592f9c7ce27d41d4a5d5fa97e467b6368eeb34199b3cf84ac73655/prometheus/client_java/issues/2292 |
| og:image:alt | Version io.prometheus:prometheus-metrics-core:1.8.0 (the affected code in CKMSQuantiles is unchanged since at least 1.3.x and is still present on main). Reproducer import io.prometheus.metrics.core... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | olegkovalenko |
| hostname | github.com |
| expected-hostname | github.com |
| None | 03e5090f0cea887cafa036e3af34d7c668d83b5e9e9e03df72a90efb49b69cdf |
| turbo-cache-control | no-preview |
| go-import | github.com/prometheus/client_java git https://github.com/prometheus/client_java.git |
| octolytics-dimension-user_id | 3380462 |
| octolytics-dimension-user_login | prometheus |
| octolytics-dimension-repository_id | 7997879 |
| octolytics-dimension-repository_nwo | prometheus/client_java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7997879 |
| octolytics-dimension-repository_network_root_nwo | prometheus/client_java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 41f00295b9a35dca977890ab83b22788ab211dc8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width