Skip to content
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

Custom metric buckets #844

Merged
merged 7 commits into from
Nov 21, 2024
Merged

Custom metric buckets #844

merged 7 commits into from
Nov 21, 2024

Conversation

Sushisource
Copy link
Member

What was changed

Allow configuring custom buckets for histogram metrics

Why?

Oft-requested feature

Checklist

  1. Closes [Feature Request] Customize metric bucket sizes #459

  2. How was this tested:
    Added tests

  3. Any docs updates needed?

I'm looking at passing buckets in with user-created histograms, but my initial inclination is that that may not actually make sense since the otel API separates how aggregation happens from the instrument definition, so we would need to do some odd contortions to take the buckets from the histogram definition and somehow apply that to the overall meter provider definition.

Ultimately, it's pretty easy for the user to just use a constant for their histogram name, and then register the buckets for that in the telemetry options.

@Sushisource Sushisource requested a review from a team as a code owner November 20, 2024 20:10
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

I'm ok with requiring named bucket configuration to be done at metric init time instead of histogram creation time (at least at first and can wait if/until it becomes a real issue for users).

///
/// See [here](https://docs.rs/opentelemetry_sdk/latest/opentelemetry_sdk/metrics/enum.Aggregation.html#variant.ExplicitBucketHistogram.field.boundaries)
/// for the exact meaning of boundaries.
pub overrides: HashMap<&'static str, Vec<f64>>,
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure this can be &'static here since it comes from users on lang side. It may have to be String.

Copy link
Member Author

@Sushisource Sushisource Nov 20, 2024

Choose a reason for hiding this comment

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

Duh, good point, thanks. I initially meant this to be only overrides of core-defined ones, but, it'll need to apply to user ones too.

Comment on lines +101 to +103
/// Overrides where the key is the metric name and the value is the list of bucket boundaries.
/// The metric name will apply regardless of name prefixing, if any. IE: the name acts like
/// `*metric_name`.
Copy link
Member

Choose a reason for hiding this comment

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

Does this wildcard thing only apply to OTel or does it apply to Prometheus too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both

///
/// See [here](https://docs.rs/opentelemetry_sdk/latest/opentelemetry_sdk/metrics/enum.Aggregation.html#variant.ExplicitBucketHistogram.field.boundaries)
/// for the exact meaning of boundaries.
pub overrides: HashMap<&'static str, Vec<f64>>,
Copy link
Member

Choose a reason for hiding this comment

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

I was going to suggest we also provide the configured buckets as part of buffered/custom metric to the user, but that may not be needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that's what the PR description is about. It's just extremely annoying to do

Copy link
Member

@cretz cretz Nov 20, 2024

Choose a reason for hiding this comment

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

To clarify, here I am saying it may be neat to have the MetricEvent::Create buffered metric event include the buckets for those writing generic buffered metric impls, not necessarily concerned about the metric creation side. But I understand that is a bit difficult too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it's the same thing. The problem is you define these Views at meter creation time, and instrument (metric) creation time is too late. So, not just annoying really but AFAICT may not even be possible.

@Sushisource Sushisource merged commit d31c105 into master Nov 21, 2024
6 checks passed
@Sushisource Sushisource deleted the custom-metric-buckets branch November 21, 2024 16:51
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.

[Feature Request] Customize metric bucket sizes
2 participants