Skip to content

Commit

Permalink
Merge pull request #2057 from input-output-hk/dlachaume/2054/add-miss…
Browse files Browse the repository at this point in the history
…ing-aggregator-prometheus-metric

Feat: add aggregator metric to record the number of restoration of the Cardano database
  • Loading branch information
dlachaume authored Oct 29, 2024
2 parents e68fb58 + 3f8d893 commit 8ee076c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
36 changes: 35 additions & 1 deletion mithril-aggregator/src/http_server/routes/statistics_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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<TransmitterService<EventMessage>>,
metrics_service: Arc<MetricsService>,
) -> Result<impl warp::Reply, Infallible> {
metrics_service
.get_cardano_db_total_restoration_since_startup()
.increment();

let headers: Vec<(&str, &str)> = Vec::new();

match event_transmitter.send_event_message(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
);
}
}
4 changes: 4 additions & 0 deletions mithril-aggregator/src/metrics/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8ee076c

Please sign in to comment.