Skip to content

Commit 227fd93

Browse files
committed
Add missing buckets (aka boundaries) to OTEL histogram metrics
1 parent 6a00328 commit 227fd93

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/telemetry.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ pub(crate) fn record_cache_hit(bytes: u64) {
180180
static CACHE_HIT_BYTES_HISTOGRAM: LazyLock<Histogram<u64>> = LazyLock::new(|| {
181181
opentelemetry::global::meter(CARGO_CRATE_NAME)
182182
.u64_histogram("s3_cache.hit_bytes_histogram")
183+
.with_boundaries(OBJECT_SIZE_BUCKETS.to_vec())
183184
.with_description("Distribution of object sizes on cache hits")
184185
.build()
185186
});
@@ -230,6 +231,7 @@ pub(crate) fn record_cache_miss(bytes: u64) {
230231
static CACHE_MISS_BYTES_HISTOGRAM: LazyLock<Histogram<u64>> = LazyLock::new(|| {
231232
opentelemetry::global::meter(CARGO_CRATE_NAME)
232233
.u64_histogram("s3_cache.miss_bytes_histogram")
234+
.with_boundaries(OBJECT_SIZE_BUCKETS.to_vec())
233235
.with_description("Distribution of object sizes on cache misses")
234236
.build()
235237
});
@@ -280,6 +282,7 @@ pub(crate) fn record_cache_eviction(bytes: u64) {
280282
static CACHE_EVICTION_BYTES_HISTOGRAM: LazyLock<Histogram<u64>> = LazyLock::new(|| {
281283
opentelemetry::global::meter(CARGO_CRATE_NAME)
282284
.u64_histogram("s3_cache.eviction_bytes_histogram")
285+
.with_boundaries(OBJECT_SIZE_BUCKETS.to_vec())
283286
.with_description("Distribution of object sizes on cache evictions")
284287
.build()
285288
});
@@ -331,6 +334,7 @@ pub(crate) fn record_cache_eviction_age(age_secs: f64) {
331334
static CACHE_EVICTION_AGE_HISTOGRAM: LazyLock<Histogram<f64>> = LazyLock::new(|| {
332335
opentelemetry::global::meter(CARGO_CRATE_NAME)
333336
.f64_histogram("s3_cache.eviction_age_histogram")
337+
.with_boundaries(EVICTION_AGE_BUCKETS.to_vec())
334338
.with_description("Age of objects (in seconds) at the time of eviction, capped at TTL")
335339
.with_unit("s")
336340
.build()
@@ -362,6 +366,7 @@ pub(crate) fn record_cache_oversized(bytes: u64) {
362366
static CACHE_OVERSIZED_BYTES_HISTOGRAM: LazyLock<Histogram<u64>> = LazyLock::new(|| {
363367
opentelemetry::global::meter(CARGO_CRATE_NAME)
364368
.u64_histogram("s3_cache.oversized_bytes_histogram")
369+
.with_boundaries(OVERSIZED_OBJECT_SIZE_BUCKETS.to_vec())
365370
.with_description("Distribution of object sizes that exceeded the max cacheable size")
366371
.build()
367372
});
@@ -415,6 +420,7 @@ pub(crate) fn record_unique_requested(bytes: u64) {
415420
static CACHE_UNIQUE_REQUESTED_BYTES_HISTOGRAM: LazyLock<Histogram<u64>> = LazyLock::new(|| {
416421
opentelemetry::global::meter(CARGO_CRATE_NAME)
417422
.u64_histogram("s3_cache.estimated_unique_bytes_histogram")
423+
.with_boundaries(OBJECT_SIZE_BUCKETS.to_vec())
418424
.with_description("Distribution of estimated unique object sizes")
419425
.build()
420426
});
@@ -623,9 +629,16 @@ pub(crate) struct RequestDuration {
623629
}
624630

625631
pub(crate) fn record_request_duration(data: RequestDuration) {
632+
static REQUEST_DURATION_BUCKETS: LazyLock<Vec<f64>> = LazyLock::new(|| {
633+
vec![
634+
1.0, 5.0, 10.0, 25.0, 50.0, 100.0, 250.0, 500.0, 1000.0, 2500.0, 5000.0, 10000.0,
635+
]
636+
});
637+
626638
static REQUEST_DURATION_MS: LazyLock<Histogram<f64>> = LazyLock::new(|| {
627639
opentelemetry::global::meter(CARGO_CRATE_NAME)
628640
.f64_histogram("http.server.request.duration")
641+
.with_boundaries(REQUEST_DURATION_BUCKETS.to_vec())
629642
.with_description("Duration of the request in milliseconds")
630643
.with_unit("ms")
631644
.build()
@@ -637,9 +650,7 @@ pub(crate) fn record_request_duration(data: RequestDuration) {
637650
"http_server_request_duration",
638651
"Duration of get_object requests in milliseconds",
639652
)
640-
.buckets(vec![
641-
1.0, 5.0, 10.0, 25.0, 50.0, 100.0, 250.0, 500.0, 1000.0, 2500.0, 5000.0, 10000.0,
642-
]),
653+
.buckets(REQUEST_DURATION_BUCKETS.to_vec()),
643654
)
644655
.unwrap();
645656
PROMETHEUS_REGISTRY
@@ -682,9 +693,13 @@ pub(crate) struct ResponseBodySize {
682693
}
683694

684695
pub(crate) fn record_response_body_size(data: ResponseBodySize) {
696+
static RESPONSE_BODY_SIZE_BUCKETS: LazyLock<Vec<f64>> =
697+
LazyLock::new(|| prometheus::exponential_buckets(1024.0, 4.0, 10).unwrap());
698+
685699
static RESPONSE_BODY_SIZE_BYTES: LazyLock<Histogram<f64>> = LazyLock::new(|| {
686700
opentelemetry::global::meter(CARGO_CRATE_NAME)
687701
.f64_histogram("http.server.response.body.size")
702+
.with_boundaries(RESPONSE_BODY_SIZE_BUCKETS.to_vec())
688703
.with_description("Size of the response body in bytes")
689704
.with_unit("By")
690705
.build()
@@ -696,7 +711,7 @@ pub(crate) fn record_response_body_size(data: ResponseBodySize) {
696711
"http_server_response_body_size",
697712
"Size of get_object response bodies in bytes",
698713
)
699-
.buckets(prometheus::exponential_buckets(1024.0, 4.0, 10).unwrap()),
714+
.buckets(RESPONSE_BODY_SIZE_BUCKETS.to_vec()),
700715
)
701716
.unwrap();
702717
PROMETHEUS_REGISTRY

0 commit comments

Comments
 (0)