Skip to content

feat(metrics): expose histograms in both classic and native form - #3825

Open
pbleser-oc wants to merge 1 commit into
opencloud-eu:mainfrom
pbleser-oc:feat/3822-native-histograms
Open

pbleser-oc wants to merge 1 commit into
opencloud-eu:mainfrom
pbleser-oc:feat/3822-native-histograms

Conversation

@pbleser-oc

@pbleser-oc pbleser-oc commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #3822 (part of #3817)

Changes

  • New helpers in pkg/metrics:
    • DualHistogramOpts: adds the native histogram settings, so the histogram is exposed in both classic and native form. If no Buckets are set, it uses prometheus.DefBuckets, because client_golang otherwise exposes no classic buckets once native buckets are enabled.
    • NativeHistogramOpts: native-only, for histograms with high cardinality that have classic fallback metrics with fewer labels.
    • Hardcoded defaults for all services: bucket factor 1.1 (≈10% relative error), at most 100 buckets, never reset (NativeHistogramMinResetDuration is 0): when a histogram exceeds 100 native buckets, client_golang reduces the resolution of its native part instead. A reset would set the whole histogram back to zero, including its classic buckets, _count and _sum, i.e. a counter reset also for scrapers that only ingest the classic histogram.
  • All classic histograms now use DualHistogramOpts: graph (http_request_duration_seconds, ldap_client_operation_duration_seconds, identity_backend_api_duration_seconds), postprocessing, search, invitations and webfinger. Their classic buckets are unchanged.
  • proxy's request_duration_seconds uses NativeHistogramOpts, which adds the bucket cap to its existing native-only setup. proxy's classic duration_seconds and service_duration_seconds stay classic-only on purpose: they are the fallback for scrapers without native histograms, and their native form would only duplicate request_duration_seconds.

Cost

The native part adds about 120 bytes of heap per native bucket to every label combination of a histogram. Measured with values spread over 1ms–100ms, 1ms–10s and 100µs–1000s, a label combination grows from about 1.2 KB (classic only) to 8 KB, 8.5 KB and 12.7 KB (54, 54 and 94 native buckets). With the cap of 100 buckets, it stays below about 13 KB.

graph's http_request_duration_seconds has the most label combinations (about 85 routes times the status codes that actually occur, typically a few hundred), so about 2–4 MB more. All other histograms have at most a few dozen label combinations, adding less than 1 MB together.

Impact on Prometheus setups

  • Native histograms not enabled (the default, scrape_native_histograms: false): nothing changes. The classic histograms are ingested as before.
  • Native histograms enabled (scrape_native_histograms: true, or --enable-feature=native-histograms before Prometheus v3.9): for every histogram that now uses DualHistogramOpts, Prometheus now stores only the native form. The classic _bucket, _sum and _count series stop, so dashboards, recording rules and alerts that use them go empty until they are rewritten for native histograms (e.g. histogram_quantile(0.99, rate(x[5m])), histogram_count(rate(x[5m])), histogram_sum(rate(x[5m]))). To keep the classic series as well, for example while migrating dashboards, set always_scrape_classic_histograms: true in the scrape config.

This should be mentioned in the release notes.

Tests

  • Unit tests for both helpers in pkg/metrics/histogram_test.go: they check the classic buckets (explicit and default) and the native part of what a histogram exposes.
  • go build, go vet and the tests of the affected packages pass.

@codacy-production

codacy-production Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 10 complexity

Metric Results
Complexity 10

View in Codacy

🟢 Coverage 54.84% diff coverage · +0.01% coverage variation

Metric Results
Coverage variation ✅ +0.01% coverage variation (-1.00%)
Diff coverage ✅ 54.84% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (4c6d7e7) 92640 25430 27.45%
Head commit (6ab5d13) 92654 (+14) 25445 (+15) 27.46% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3825) 31 17 54.84%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Add the helpers DualHistogramOpts and NativeHistogramOpts to pkg/metrics,
which add the settings for the native part of a Prometheus histogram,
with the same hardcoded defaults for all services (bucket factor 1.1,
at most 100 buckets, never reset).

Native histograms that exceed the limit of 100 buckets are never reset
(NativeHistogramMinResetDuration is 0): client_golang reduces the
resolution of their native part instead (until the process restarts).
A reset would set the whole histogram back to zero, including its
classic buckets, count and sum, i.e. a counter reset about once an hour
(with a minimum reset duration of 1 hour) for every scraper, also for
those that only ingest the classic histogram.

The classic histograms of the graph, postprocessing, search, invitations
and webfinger services now use DualHistogramOpts, so that they are
exposed in both classic and native form: Prometheus scrapers without
native histograms (the default) keep ingesting the classic buckets,
while scrapers with scrape_native_histograms enabled ingest the native
histogram instead (and the classic one as well if
always_scrape_classic_histograms is enabled). Histograms that didn't
define buckets keep prometheus.DefBuckets.

The native-only request_duration_seconds histogram of the proxy service
now uses NativeHistogramOpts, which additionally caps its number of
buckets. The classic duration_seconds and service_duration_seconds
histograms of the proxy service remain classic-only on purpose: they
are the fallback for scrapers without native histograms, and their
native form would only duplicate request_duration_seconds.

Cost: the native part adds about 120 bytes of heap per native bucket to
every label combination (child) of a histogram. Measured with values
spread over 1ms-100ms, 1ms-10s and 100us-1000s, a child grows from about
1.2 KB (classic only) to 8 KB, 8.5 KB and 12.7 KB (54, 54 and 94 native
buckets); with the cap of 100 buckets, it stays below about 13 KB.
graph's http_request_duration_seconds has the most children (about 85
routes times the status codes that actually occur, typically a few
hundred), i.e. about 2-4 MB more; all other histograms have at most a
few dozen children, adding less than 1 MB together.

Fixes opencloud-eu#3822
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metrics: expose histograms in both classic and native form

1 participant