Skip to content

feat(metrics): use shared bucket sets for the classic histograms - #3828

Draft
pbleser-oc wants to merge 2 commits into
opencloud-eu:mainfrom
pbleser-oc:feat/3823-histogram-buckets
Draft

pbleser-oc wants to merge 2 commits into
opencloud-eu:mainfrom
pbleser-oc:feat/3823-histogram-buckets

Conversation

@pbleser-oc

Copy link
Copy Markdown
Member

Fixes #3823 (part of #3817)

Note

This PR builds on #3825, whose commit is included here until #3825 is merged; this PR will then be rebased onto main. Only the last commit, ca9893d ("use shared bucket sets for the classic histograms"), belongs to this PR. To review only that, use the diff of that commit or git show ca9893db29.

Changes

Four shared bucket sets in pkg/metrics, so that the classic histograms of the services use consistent boundaries, each with about a dozen buckets:

Set Boundaries (s) Buckets
RequestDurationBuckets 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60 12
FastOperationDurationBuckets 0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10 13
TransferDurationBuckets 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 300, 1800 14
ProcessingDurationBuckets 0.1, 0.5, 1, 2.5, 5, 10, 30, 60, 120, 300, 600, 1200 12

Used by the services (number of buckets before → after):

Metric Before After
opencloud_graph_http_request_duration_seconds DefBuckets (11) request (12)
opencloud_graph_identity_backend_api_duration_seconds DefBuckets (11) request (12)
opencloud_graph_ldap_client_operation_duration_seconds DefBuckets (11) fast operation (13)
opencloud_invitations_invitation_duration_seconds DefBuckets (11) request (12)
opencloud_webfinger_webfinger_duration_seconds DefBuckets (11) fast operation (13)
opencloud_proxy_duration_seconds DefBuckets (11) transfer (14)
opencloud_proxy_service_duration_seconds DefBuckets (11) transfer (14)
opencloud_search_search_duration_seconds 0.1 – 60s (8) request (12)
opencloud_search_index_duration_seconds 0.1 – 1200s (12) processing (12), unchanged
opencloud_postprocessing_duration_seconds 0.1 – 1200s (12) processing (12), unchanged

Why: prometheus.DefBuckets (0.005 – 10s) puts everything slower than 10s into the +Inf bucket, e.g. slow Graph API calls and identity backend operations, and the uploads and downloads that go through the proxy (which also measures the transfer of the body). At the same time, it barely resolves LDAP operations, which mostly take a few milliseconds.

The new boundaries are estimates, which can be refined once the native histograms (#3825) show the actual distributions.

Impact

  • Continuity: changing the bucket boundaries breaks the continuity of the _bucket series of the first eight metrics in the table above: queries over a time range that includes the upgrade mix old and new boundaries. This should be mentioned in the release notes.
  • Cost: only for setups that ingest the classic histograms; every additional bucket is one more time series per label combination: a few hundred for opencloud_graph_http_request_duration_seconds (+1 bucket), roughly 90 for the two proxy histograms (+3 buckets each), a handful for the others.

Tests

  • New unit test: every bucket set is in increasing order, unique, and exposed as such by a histogram.
  • go build, go vet and the tests of the affected packages pass.

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
Add four bucket sets to pkg/metrics, so that the classic histograms of
the services use consistent boundaries, each with about a dozen buckets:

  RequestDurationBuckets        0.01 .. 60s    (12 buckets)
  FastOperationDurationBuckets  0.001 .. 10s   (13 buckets)
  TransferDurationBuckets       0.01 .. 1800s  (14 buckets)
  ProcessingDurationBuckets     0.1 .. 1200s   (12 buckets)

and use them in the services (the number of buckets before -> after):

  graph http_request_duration_seconds           DefBuckets -> request (11 -> 12)
  graph identity_backend_api_duration_seconds   DefBuckets -> request (11 -> 12)
  graph ldap_client_operation_duration_seconds  DefBuckets -> fast operation (11 -> 13)
  invitations invitation_duration_seconds       DefBuckets -> request (11 -> 12)
  webfinger webfinger_duration_seconds          DefBuckets -> fast operation (11 -> 13)
  proxy duration_seconds                        DefBuckets -> transfer (11 -> 14)
  proxy service_duration_seconds                DefBuckets -> transfer (11 -> 14)
  search search_duration_seconds                0.1 .. 60s -> request (8 -> 12)
  search index_duration_seconds                 unchanged (processing)
  postprocessing duration_seconds               unchanged (processing)

prometheus.DefBuckets (0.005 .. 10s) put everything slower than 10s into
the +Inf bucket, e.g. slow Graph API calls and identity backend
operations, and the uploads and downloads that go through the proxy
(which also measures the transfer of the body), while it barely resolved
LDAP operations, which mostly take a few milliseconds.

The new boundaries are estimates, which can be refined once the native
histograms show the actual distributions.

Changing the bucket boundaries breaks the continuity of the _bucket
series of these histograms: queries over a time range that includes the
upgrade mix old and new boundaries. The affected metrics are:

- opencloud_graph_http_request_duration_seconds
- opencloud_graph_identity_backend_api_duration_seconds
- opencloud_graph_ldap_client_operation_duration_seconds
- opencloud_invitations_invitation_duration_seconds
- opencloud_webfinger_webfinger_duration_seconds
- opencloud_proxy_duration_seconds
- opencloud_proxy_service_duration_seconds
- opencloud_search_search_duration_seconds

The boundaries of opencloud_search_index_duration_seconds and
opencloud_postprocessing_duration_seconds don't change.

Fixes opencloud-eu#3823
@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 13 complexity

Metric Results
Complexity 13

View in Codacy

🟢 Coverage 47.37% diff coverage · 0.00% coverage variation

Metric Results
Coverage variation ✅ 0.00% coverage variation (-1.00%)
Diff coverage ✅ 47.37% 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 (ca9893d) 92658 (+18) 25433 (+3) 27.45% (0.00%)

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 (#3828) 38 18 47.37%

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.

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: review classic histogram bucket boundaries

1 participant