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

Simplify the Prometheus stuff #2878

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

Conversation

MathieuDutSik
Copy link
Contributor

Motivation

The Prometheus entries is creating a lot of copy-pasted code which is bad taste.

Proposal

This PR does two things:

  • Change the use statements which lead to smaller code.
  • Introduce functions bucket_latencies and bucket_interval for creating the bucket of values in a more organized way.

Test Plan

The CI

Release Plan

The intervals have changed a bit. So, if the operation code strictly depends on the exact values of the buckets then
something else would have to be done.

Links

None.

Comment on lines +41 to +76
/// Construct the latencies starting from 0.0001 and ending at the maximum latency
pub fn bucket_latencies(max_latency: f64) -> Option<Vec<f64>> {
let mut latencies = Vec::new();
let mut latency = 0.0001_f64;
let max_delta = 0.01;
loop {
for mult in [1.0_f64, 2.5_f64, 5.0_f64] {
let target_latency = latency * mult;
latencies.push(target_latency);
let delta = (target_latency - max_latency).abs() / max_latency;
if delta < max_delta {
return Some(latencies);
}
}
latency *= 10_f64;
}
}

/// Construct the bucket interval starting from a value and an ending value.
pub fn bucket_interval(start_value: f64, end_value: f64) -> Option<Vec<f64>> {
let mut values = Vec::new();
let mut value = start_value;
let max_delta = 0.01;
loop {
for mult in [1.0_f64, 2.5_f64, 5.0_f64] {
let target_value = value * mult;
values.push(target_value);
let delta = (target_value - end_value).abs() / end_value;
if delta < max_delta {
return Some(values);
}
}
value *= 10_f64;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Prometheus already provides utility functions to generate these buckets, like I mentioned in the issue: #2795 (comment)
Couldn't we use those instead of implementing it from scratch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can use those instead of this code.
However, the obtained buckets would be different, it would be a strictly exponential growth. Which may be fine.
I do not think anyone of us is using the bucket.

@MathieuDutSik MathieuDutSik marked this pull request as ready for review November 13, 2024 16:20
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