-
Notifications
You must be signed in to change notification settings - Fork 860
Add native histogram support to all remaining production histograms #7636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CharlieTLe
wants to merge
3
commits into
cortexproject:master
Choose a base branch
from
CharlieTLe:worktree-parallel-fluttering-spark
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Native Histogram Support for All Production Metrics | ||
|
|
||
| ## Problem | ||
|
|
||
| Cortex exposes ~56 histogram metrics across its components. Native histograms (introduced in Prometheus 2.40) offer significant advantages over classic histograms: | ||
|
|
||
| 1. **Higher resolution** — Exponential bucket boundaries adapt to observed values, eliminating the need to pre-define bucket ranges. | ||
| 2. **Lower storage cost** — Native histograms typically use fewer time series than classic histograms with many buckets. | ||
| 3. **Better aggregation** — Native histograms can be merged across instances without information loss from mismatched bucket boundaries. | ||
|
|
||
| Previously, ~11 histograms were converted to dual-format (classic + native). The remaining ~45 production histograms were still classic-only, providing an inconsistent experience for operators who want to adopt native histograms. | ||
|
|
||
| ## Design | ||
|
|
||
| ### Dual-Format Histograms | ||
|
|
||
| All production histograms are configured as dual-format by adding three fields to each `prometheus.HistogramOpts`: | ||
|
|
||
| ```go | ||
| NativeHistogramBucketFactor: 1.1, | ||
| NativeHistogramMaxBucketNumber: 100, | ||
| NativeHistogramMinResetDuration: time.Hour, | ||
| ``` | ||
|
|
||
| This means: | ||
| - **Classic scrapes** continue to work unchanged — the histogram exposes classic buckets as before. | ||
| - **Native-aware scrapes** (using `Accept: application/vnd.google.protobuf`) receive native histogram data instead. | ||
| - No behavioral change for existing deployments until they opt in to native histogram scraping. | ||
|
|
||
| ### Configuration Values | ||
|
|
||
| | Field | Value | Rationale | | ||
| |-------|-------|-----------| | ||
| | `NativeHistogramBucketFactor` | 1.1 | ~10% relative resolution per bucket, providing good precision without excessive bucket count. Matches the pattern already established in the codebase. | | ||
| | `NativeHistogramMaxBucketNumber` | 100 | Upper bound on bucket count to prevent cardinality explosion from pathological distributions. | | ||
| | `NativeHistogramMinResetDuration` | `time.Hour` | Prevents premature schema resets during transient spikes, reducing unnecessary churn. | | ||
|
|
||
| These values match the existing pattern used by the ~11 histograms already converted (e.g., in `pkg/distributor`, `pkg/ingester`). | ||
|
|
||
| ### Affected Components | ||
|
|
||
| | Component | Histograms | | ||
| |-----------|-----------| | ||
| | Ingester | 8 (WAL replay, appender add/commit, queried samples/exemplars/series/chunks) | | ||
| | Querier | 7 (store gateway client, instances hit, refetches, blocks scan, tenant federation) | | ||
| | Cache | 4 (instrumented cache value size/duration, memcached, redis) | | ||
| | API | 3 (request duration, message sizes) | | ||
| | Distributor | 2 (query duration, labels per sample) | | ||
| | Compactor | 2 (meta sync duration, garbage collection duration) | | ||
| | Storage/TSDB | 5 (bucket index load, multilevel cache fetch/backfill) | | ||
| | Store Gateway | 1 (blocks sync) | | ||
| | Frontend | 2 (queue duration, retries) | | ||
| | Scheduler | 1 (queue duration) | | ||
| | Alertmanager | 2 (client request duration, initial sync duration) | | ||
| | Ring/KV | 4 (KV request duration, consul, dynamodb, lifecycler shutdown) | | ||
| | Ruler | 2 (client pool request duration, frontend client pool) | | ||
| | HA Tracker | 1 (change propagation time) | | ||
| | Configs | 2 (client request duration, database request duration) | | ||
| | Parquet Converter | 1 (block conversion delay) | | ||
|
|
||
| ### Backward Compatibility | ||
|
|
||
| This change is fully backward compatible: | ||
|
|
||
| - **No metric name changes** — all existing metric names, labels, and bucket boundaries are preserved. | ||
| - **No scrape format change** — classic format is served unless the scraper explicitly requests native histograms via content negotiation. | ||
| - **No configuration required** — dual-format is enabled automatically; operators opt in to native scraping at the Prometheus/agent level. | ||
|
|
||
| ## Migration Path | ||
|
|
||
| 1. **Deploy updated Cortex** — histograms begin emitting dual-format data. No observable change for classic scrapers. | ||
| 2. **Enable native histogram ingestion** in Prometheus (or compatible agents) by configuring `scrape_protocols` to include `PrometheusProto`. | ||
| 3. **Update dashboards/alerts** — native histograms use the base metric name (without `_bucket`/`_sum`/`_count` suffixes). For example: | ||
|
|
||
| ```promql | ||
| # Classic histogram query: | ||
| histogram_quantile(0.99, rate(cortex_ingester_tsdb_appender_commit_duration_seconds_bucket[5m])) | ||
|
|
||
| # Native histogram query (uses base name directly): | ||
| histogram_quantile(0.99, rate(cortex_ingester_tsdb_appender_commit_duration_seconds[5m])) | ||
| ``` | ||
|
|
||
| Native histograms also enable new PromQL functions not available with classic histograms: `histogram_avg()`, `histogram_fraction()`, `histogram_stddev()`, and `histogram_stdvar()`. | ||
|
|
||
| ## Alternatives Considered | ||
|
|
||
| ### Native-only (no classic buckets) | ||
|
|
||
| Rejected because it would break existing dashboards and alerts that rely on classic bucket boundaries. Dual-format ensures zero disruption. | ||
|
|
||
| ### Per-histogram configuration | ||
|
|
||
| Rejected because uniform settings simplify operations and the chosen values (1.1 factor, 100 max buckets, 1h min reset) are broadly suitable for all Cortex histograms. Operators who need different settings can override at the scrape level. |
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, can you add a PR number?