Skip to content

fix(metrics): size exponential histogram exemplar reservoirs - #2392

Open
LouisDeconinck wants to merge 2 commits into
open-telemetry:mainfrom
LouisDeconinck:fix/exponential-histogram-exemplar-size
Open

LouisDeconinck wants to merge 2 commits into
open-telemetry:mainfrom
LouisDeconinck:fix/exponential-histogram-exemplar-size

Conversation

@LouisDeconinck

Copy link
Copy Markdown

Fixes #2366.

The default exemplar reservoir for exponential histograms used the reservoir's CPU-count default instead of the specification's min(20, max_size) sizing rule.

This creates the default reservoir after validating max_size, with an explicit size capped at 20. Custom reservoirs are unchanged. The regression test covers smaller-than-20, equal-to-20, and larger-than-20 histograms.

Validation:

  • git diff --check
  • Focused Ruby tests not run: Ruby/Bundler is not installed in the execution environment.

AI assistance is disclosed in the commit trailer: Assisted-by: Codex.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 10, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: LouisDeconinck / name: Louis Deconinck (bee7677)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change directly implements the spec-required default sizing and includes a focused regression test covering key boundary cases.

Pull request overview

This PR fixes the default exemplar reservoir sizing for exponential histograms in metrics_sdk to comply with the OpenTelemetry spec requirement of min(20, max_buckets) rather than using the reservoir’s CPU-count default.

Changes:

  • Create the default SimpleFixedSizeExemplarReservoir only after validating max_size, explicitly setting max_size: [20, @size].min.
  • Remove the shared DEFAULT_RESERVOIR constant so the default reservoir sizing can be derived from the histogram’s validated bucket limit.
  • Add a regression test covering max_size below 20, equal to 20, and above 20.
File summaries
File Description
metrics_sdk/lib/opentelemetry/sdk/metrics/aggregation/exponential_bucket_histogram.rb Constructs the default exemplar reservoir with an explicit size capped at 20 based on validated histogram max_size.
metrics_sdk/test/opentelemetry/sdk/metrics/aggregation/exponential_bucket_histogram_test.rb Adds a regression test asserting the default exemplar reservoir size follows the min(20, max_size) rule.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kaylareopelle

Copy link
Copy Markdown
Contributor

Hi @LouisDeconinck, thank you for your contribution! Could you sign the CLA?


# if no reservoir pass from instrument, then use this empty reservoir to avoid no method found error
DEFAULT_RESERVOIR = Metrics::Exemplar::SimpleFixedSizeExemplarReservoir.new
private_constant :DEFAULT_RESERVOIR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to move out of private contstant?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default reservoir now needs a per-instance size - SimpleFixedSizeExemplarReservoir.new(max_size: [20, @SiZe].min) - which depends on the histogram's max_size , so it can't be a shared class constant. This also avoids all default-constructed histograms sharing a single mutable reservoir instance.

@simi

simi commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Focused Ruby tests not run: Ruby/Bundler is not installed in the execution environment.

It would be good to at least somehow verify locally code works before submitting PR.

@LouisDeconinck

Copy link
Copy Markdown
Author

@kaylareopelle CLA was signed.

@LouisDeconinck

Copy link
Copy Markdown
Author

Verified locally in Docker (ruby:3.4): bundle exec rake test in metrics_sdk — 336 runs, 17,223 assertions, 0 failures — and bundle exec rake rubocop — 98 files, no offenses. The run includes the new sizing test ([4, 20, 32] -> [4, 20, 20] max_size cases).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix exponential-histogram exemplar-reservoir default sizing

6 participants