Skip to content

Commit 0a15414

Browse files
committed
otel metrics: define histogram buckets the same as before
1 parent 2f0353e commit 0a15414

File tree

5 files changed

+48
-30
lines changed

5 files changed

+48
-30
lines changed

src/cdn.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use crate::{Config, InstanceMetrics, metrics::otel::AnyMeterProvider, utils::report_error};
1+
use crate::{
2+
Config, InstanceMetrics,
3+
metrics::{CDN_INVALIDATION_HISTOGRAM_BUCKETS, otel::AnyMeterProvider},
4+
utils::report_error,
5+
};
26
use anyhow::{Context, Error, Result, anyhow, bail};
37
use aws_config::BehaviorVersion;
48
use aws_sdk_cloudfront::{
@@ -38,10 +42,12 @@ impl CdnMetrics {
3842
Self {
3943
invalidation_time: meter
4044
.f64_histogram(format!("{PREFIX}.invalidation_time"))
45+
.with_boundaries(CDN_INVALIDATION_HISTOGRAM_BUCKETS.to_vec())
4146
.with_unit("s")
4247
.build(),
4348
queue_time: meter
4449
.f64_histogram(format!("{PREFIX}.queue_time"))
50+
.with_boundaries(CDN_INVALIDATION_HISTOGRAM_BUCKETS.to_vec())
4551
.with_unit("s")
4652
.build(),
4753
}

src/docbuilder/rustwide_builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
},
1212
docbuilder::Limits,
1313
error::Result,
14-
metrics::otel::AnyMeterProvider,
14+
metrics::{BUILD_TIME_HISTOGRAM_BUCKETS, DOCUMENTATION_SIZE_BUCKETS, otel::AnyMeterProvider},
1515
repositories::RepositoryStatsUpdater,
1616
storage::{
1717
CompressionAlgorithm, RustdocJsonFormatVersion, compress, get_file_list,
@@ -136,6 +136,7 @@ impl BuilderMetrics {
136136
.build(),
137137
build_time: meter
138138
.f64_histogram(format!("{PREFIX}.build_time"))
139+
.with_boundaries(BUILD_TIME_HISTOGRAM_BUCKETS.to_vec())
139140
.with_unit("s")
140141
.build(),
141142
total_builds: meter
@@ -152,6 +153,7 @@ impl BuilderMetrics {
152153
.build(),
153154
documentation_size: meter
154155
.u64_histogram(format!("{PREFIX}.documentation_size"))
156+
.with_boundaries(DOCUMENTATION_SIZE_BUCKETS.to_vec())
155157
.with_unit("bytes")
156158
.with_description("size of the generated documentation in bytes")
157159
.build(),

src/metrics/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ macro_rules! metrics {
6969
"time spent building crates",
7070
)
7171
.namespace($namespace)
72-
.buckets($crate::metrics::build_time_histogram_buckets()),
72+
.buckets($crate::metrics::BUILD_TIME_HISTOGRAM_BUCKETS.to_vec()),
7373
)?;
7474
registry.register(Box::new(build_time.clone()))?;
7575

src/metrics/mod.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,38 @@ pub const DOCUMENTATION_SIZE_BUCKETS: &[f64; 16] = &[
5959
];
6060

6161
/// the measured times of building crates will be put into these buckets
62-
pub fn build_time_histogram_buckets() -> Vec<f64> {
63-
vec![
64-
30.0, // 0.5
65-
60.0, // 1
66-
120.0, // 2
67-
180.0, // 3
68-
240.0, // 4
69-
300.0, // 5
70-
360.0, // 6
71-
420.0, // 7
72-
480.0, // 8
73-
540.0, // 9
74-
600.0, // 10
75-
660.0, // 11
76-
720.0, // 12
77-
780.0, // 13
78-
840.0, // 14
79-
900.0, // 15
80-
1200.0, // 20
81-
1800.0, // 30
82-
2400.0, // 40
83-
3000.0, // 50
84-
3600.0, // 60
85-
]
86-
}
62+
pub const BUILD_TIME_HISTOGRAM_BUCKETS: &[f64] = &[
63+
30.0, // 0.5
64+
60.0, // 1
65+
120.0, // 2
66+
180.0, // 3
67+
240.0, // 4
68+
300.0, // 5
69+
360.0, // 6
70+
420.0, // 7
71+
480.0, // 8
72+
540.0, // 9
73+
600.0, // 10
74+
660.0, // 11
75+
720.0, // 12
76+
780.0, // 13
77+
840.0, // 14
78+
900.0, // 15
79+
1200.0, // 20
80+
1800.0, // 30
81+
2400.0, // 40
82+
3000.0, // 50
83+
3600.0, // 60
84+
];
85+
86+
/// these are the default prometheus bucket sizes,
87+
/// https://docs.rs/prometheus/0.14.0/src/prometheus/histogram.rs.html#25-27
88+
/// tailored to broadly measure the response time (in seconds) of a
89+
/// network service.
90+
/// Otel default buckets are not suited for that.
91+
pub const RESPONSE_TIME_HISTOGRAM_BUCKETS: &[f64] = &[
92+
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0,
93+
];
8794

8895
metrics! {
8996
pub struct InstanceMetrics {

src/web/metrics.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::{
2-
AsyncBuildQueue, Config, InstanceMetrics, ServiceMetrics, db::Pool,
3-
metrics::otel::AnyMeterProvider, web::error::AxumResult,
2+
AsyncBuildQueue, Config, InstanceMetrics, ServiceMetrics,
3+
db::Pool,
4+
metrics::{RESPONSE_TIME_HISTOGRAM_BUCKETS, otel::AnyMeterProvider},
5+
web::error::AxumResult,
46
};
57
use anyhow::{Context as _, Result};
68
use axum::{
@@ -44,6 +46,7 @@ impl WebMetrics {
4446
.build(),
4547
response_time: meter
4648
.f64_histogram(format!("{PREFIX}.response_time"))
49+
.with_boundaries(RESPONSE_TIME_HISTOGRAM_BUCKETS.to_vec())
4750
.with_unit("s")
4851
.build(),
4952
}

0 commit comments

Comments
 (0)