-
Notifications
You must be signed in to change notification settings - Fork 167
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
base: main
Are you sure you want to change the base?
Conversation
/// 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; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Motivation
The Prometheus entries is creating a lot of copy-pasted code which is bad taste.
Proposal
This PR does two things:
bucket_latencies
andbucket_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.