From 385c65bfcc59ad558fca219eb3aacc5cd186d800 Mon Sep 17 00:00:00 2001 From: Damien Lachaume <135982616+dlachaume@users.noreply.github.com> Date: Mon, 28 Oct 2024 17:00:35 +0100 Subject: [PATCH 1/2] feat: add aggregator metric to record the number of restoration of the Cardano DB in `/statistics/snapshot` route --- .../http_server/routes/statistics_routes.rs | 36 ++++++++++++++++++- mithril-aggregator/src/metrics/service.rs | 4 +++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/mithril-aggregator/src/http_server/routes/statistics_routes.rs b/mithril-aggregator/src/http_server/routes/statistics_routes.rs index 6c0d67d9a19..4eb967df22e 100644 --- a/mithril-aggregator/src/http_server/routes/statistics_routes.rs +++ b/mithril-aggregator/src/http_server/routes/statistics_routes.rs @@ -17,6 +17,7 @@ fn post_statistics( .and(warp::post()) .and(warp::body::json()) .and(middlewares::with_event_transmitter(dependency_manager)) + .and(middlewares::with_metrics_service(dependency_manager)) .and_then(handlers::post_snapshot_statistics) } @@ -28,11 +29,17 @@ mod handlers { use crate::event_store::{EventMessage, TransmitterService}; use crate::http_server::routes::reply; + use crate::MetricsService; pub async fn post_snapshot_statistics( snapshot_download_message: SnapshotDownloadMessage, event_transmitter: Arc>, + metrics_service: Arc, ) -> Result { + metrics_service + .get_cardano_db_total_restoration_since_startup() + .increment(); + let headers: Vec<(&str, &str)> = Vec::new(); match event_transmitter.send_event_message( @@ -61,7 +68,8 @@ mod tests { }; use crate::{ - dependency_injection::DependenciesBuilder, http_server::SERVER_BASE_PATH, Configuration, + dependency_injection::DependenciesBuilder, http_server::SERVER_BASE_PATH, + initialize_dependencies, Configuration, }; fn setup_router( @@ -108,4 +116,30 @@ mod tests { let _ = rx.try_recv().unwrap(); result.unwrap(); } + + #[tokio::test] + async fn test_post_statistics_increments_cardano_db_total_restoration_since_startup_metric() { + let method = Method::POST.as_str(); + let path = "/statistics/snapshot"; + let dependency_manager = Arc::new(initialize_dependencies().await); + let initial_counter_value = dependency_manager + .metrics_service + .get_cardano_db_total_restoration_since_startup() + .get(); + + request() + .method(method) + .json(&SnapshotDownloadMessage::dummy()) + .path(&format!("/{SERVER_BASE_PATH}{path}")) + .reply(&setup_router(dependency_manager.clone())) + .await; + + assert_eq!( + initial_counter_value + 1, + dependency_manager + .metrics_service + .get_cardano_db_total_restoration_since_startup() + .get() + ); + } } diff --git a/mithril-aggregator/src/metrics/service.rs b/mithril-aggregator/src/metrics/service.rs index f12c9ce6d95..6901d65c839 100644 --- a/mithril-aggregator/src/metrics/service.rs +++ b/mithril-aggregator/src/metrics/service.rs @@ -12,6 +12,10 @@ build_metrics_service!( "mithril_aggregator_artifact_detail_cardano_db_total_served_since_startup", "Number of Cardano db artifact details served since startup on a Mithril aggregator node" ), + cardano_db_total_restoration_since_startup:MetricCounter( + "mithril_aggregator_cardano_db_total_restoration_since_startup", + "Number of Cardano db restorations since startup on a Mithril aggregator node" + ), artifact_detail_mithril_stake_distribution_total_served_since_startup:MetricCounter( "mithril_aggregator_artifact_detail_mithril_stake_distribution_total_served_since_startup", "Number of Mithril stake distribution artifact details served since startup on a Mithril aggregator node" From 3f8d8932768678bd91f918fd4572f5a7e149ab0d Mon Sep 17 00:00:00 2001 From: Damien Lachaume <135982616+dlachaume@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:21:47 +0100 Subject: [PATCH 2/2] chore: upgrade crate versions * mithril-aggregator from `0.5.92` to `0.5.93` --- Cargo.lock | 2 +- mithril-aggregator/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 69668784b2b..126a2a9e307 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3552,7 +3552,7 @@ dependencies = [ [[package]] name = "mithril-aggregator" -version = "0.5.92" +version = "0.5.93" dependencies = [ "anyhow", "async-trait", diff --git a/mithril-aggregator/Cargo.toml b/mithril-aggregator/Cargo.toml index f8bb72140f3..53142d1c952 100644 --- a/mithril-aggregator/Cargo.toml +++ b/mithril-aggregator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-aggregator" -version = "0.5.92" +version = "0.5.93" description = "A Mithril Aggregator server" authors = { workspace = true } edition = { workspace = true }