Skip to content

Commit

Permalink
helper: add metrics for agg job timings
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah-Kennedy committed Oct 23, 2024
1 parent 9e1e934 commit 3291471
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/daphne-server/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub trait DaphneServiceMetrics: DaphneMetrics {
fn count_http_status_code(&self, status_code: u16);
fn daphne(&self) -> &dyn DaphneMetrics;
fn auth_method_inc(&self, method: AuthMethod);
fn aggregate_job_latency(&self, time: std::time::Duration);
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand All @@ -27,6 +28,7 @@ mod prometheus {
DapError,
};
use prometheus::{register_int_counter_vec_with_registry, IntCounterVec, Registry};
use std::time::Duration;

impl DaphneMetrics for DaphnePromServiceMetrics {
fn report_inc_by(&self, status: ReportStatus, val: u64) {
Expand Down Expand Up @@ -76,6 +78,10 @@ mod prometheus {
fn daphne(&self) -> &dyn DaphneMetrics {
self
}

fn aggregate_job_latency(&self, _time: Duration) {
// unimplemented by default due to elevated cardinality
}
}

#[derive(Clone)]
Expand Down
7 changes: 7 additions & 0 deletions crates/daphne-server/src/router/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,19 @@ async fn agg_job(
resource::AggregationJobId,
>,
) -> AxumDapResponse {
let timer = std::time::Instant::now();

let resp = helper::handle_agg_job_init_req(
&*app,
req,
fetch_replay_protection_override(app.kv()).await,
)
.await;

let elapsed = timer.elapsed();

app.server_metrics().aggregate_job_latency(elapsed);

AxumDapResponse::from_result_with_success_code(resp, app.server_metrics(), StatusCode::CREATED)
}

Expand Down

0 comments on commit 3291471

Please sign in to comment.