autoendpoint/routes/
metrics.rs1use actix_web::{HttpResponse, web::Data};
2use autopush_common::delivery_metrics::CONTENT_TYPE;
3
4use crate::{
5 error::{ApiErrorKind, ApiResult},
6 server::AppState,
7};
8
9pub async fn metrics_route(app_state: Data<AppState>) -> ApiResult<HttpResponse> {
11 #[cfg(feature = "reliable_report")]
12 update_reliability_report(&app_state).await;
13
14 let report = app_state
15 .delivery_metrics
16 .encode()
17 .map_err(|e| ApiErrorKind::General(format!("Metrics report error: {e}")))?;
18 Ok(HttpResponse::Ok().content_type(CONTENT_TYPE).body(report))
19}
20
21#[cfg(feature = "reliable_report")]
24async fn update_reliability_report(app_state: &AppState) {
25 let reliability = &app_state.reliability;
26 if let Err(e) = reliability.gc().await {
27 warn!("🔍⚠️ Reliability gc error: {e}");
28 }
29 let Some(family) = &app_state.delivery_metrics.reliability_report else {
30 return;
31 };
32 match reliability.report().await {
33 Ok(values) => autopush_common::reliability::update_report(family, values),
34 Err(e) => {
35 family.clear();
37 warn!("🔍⚠️ Reliability report error: {e}");
38 }
39 }
40}