Skip to content

Commit

Permalink
abstract out prometheus metrics matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffgrunewald committed Mar 6, 2024
1 parent 15f4e5b commit d2852e1
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions crates/dscvr-telemetry-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
pub use axum::{Matcher, AXUM_HTTP_REQUESTS_DURATION_SECONDS, AXUM_HTTP_REQUESTS_TOTAL};
pub use axum::{AXUM_HTTP_REQUESTS_DURATION_SECONDS, AXUM_HTTP_REQUESTS_TOTAL};

pub const IC_REPLICA_REQUESTS_TOTAL: &str = "ic-replica-requests-total";
pub const IC_REPLICA_REQUESTS_DURATION_SECONDS: &str = "ic-replica-requests-duration-seconds";

pub mod axum {
use axum::{extract::MatchedPath, middleware::Next, response::Response, routing::get, Router};
use http::Request;
use metrics_exporter_prometheus::{BuildError, PrometheusBuilder};
use metrics_exporter_prometheus::{BuildError, Matcher, PrometheusBuilder};
use std::time::Instant;

pub use metrics_exporter_prometheus::Matcher;

pub const AXUM_HTTP_REQUESTS_TOTAL: &str = "axum-http-requests-total";
pub const AXUM_HTTP_REQUESTS_DURATION_SECONDS: &str = "axum-http-requests-duration-seconds";

Expand All @@ -21,7 +19,7 @@ pub mod axum {
app: Router<S>,
global_buckets: Option<&[f64]>,
global_labels: Option<Vec<(K, V)>>,
matched_metric_buckets: Option<Vec<(Matcher, &[f64])>>,
matched_metric_buckets: Option<Vec<(&str, &[f64])>>,
) -> Result<Router<S>, BuildError>
where
K: Into<String>,
Expand All @@ -45,9 +43,9 @@ pub mod axum {
};

let builder = if let Some(buckets) = matched_metric_buckets {
buckets
.into_iter()
.try_fold(builder, |b, (k, v)| b.set_buckets_for_metric(k, v))?
buckets.into_iter().try_fold(builder, |b, (k, v)| {
b.set_buckets_for_metric(Matcher::Full(k.to_owned()), v)
})?
} else {
builder
};
Expand Down

0 comments on commit d2852e1

Please sign in to comment.