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

feat: add range based exponential buckets in histogram #233

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kohlisid
Copy link

The current implementation does not have a range based exponential bucket function.

This can be useful in scenarios where the end user doesn't want to perform manual calculations for extracting the required buckets, especially when multiple different ranges are to be used for different histograms.

Similar implementation is provided in the golang client as well.
https://github.com/prometheus/client_golang/blob/5d584e2717ef525673736d72cd1d12e304f243d7/prometheus/histogram.go#L125

@kohlisid kohlisid marked this pull request as ready for review October 15, 2024 05:10
@kohlisid
Copy link
Author

@mxinden please check!
Thank you

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Neat. A couple of comments:

Comment on lines 130 to 132
if length < 1 {
panic!("ExponentialBucketsRange length needs a positive length");
}
Copy link
Member

Choose a reason for hiding this comment

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

You could use a NonZeroU16 instead of a u16. That said, that would be inconsistent with exponential_buckets. Thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

I guess better to keep as u16 to keep consistent with exponential_buckets.
We can keep the additional check in the code for correctness.
What do you think?

src/metrics/histogram.rs Outdated Show resolved Hide resolved
Comment on lines 133 to 135
if min <= 0.0 {
panic!("ExponentialBucketsRange min needs to be greater than 0");
}
Copy link
Member

Choose a reason for hiding this comment

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

We don't panic anywhere else in the crate. Reason being, that given that instrumentation is auxiliary only, folks likely don't want a panic. Would an empty Iterator work too?

Copy link
Author

Choose a reason for hiding this comment

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

Sure! I have removed panics, but instead of an empty iterator I have added defaults with a warning.
Empty iterator might have have side-effects in histogram functionality.
Wdyt?

src/registry.rs Outdated Show resolved Hide resolved
Sidhant Kohli added 2 commits October 29, 2024 10:18
Signed-off-by: Sidhant Kohli <[email protected]>
Signed-off-by: Sidhant Kohli <[email protected]>
@kohlisid kohlisid requested a review from mxinden October 29, 2024 14:20
@kohlisid
Copy link
Author

@mxinden Thanks for the review! Have addressed them with some small follow ups, please take a look whenever you get a chance.

@kohlisid
Copy link
Author

kohlisid commented Nov 6, 2024

@mxinden Just following up on this? Let me know if any other changes are required

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.

2 participants