From d8cbc3c5ac9d50784cbf02ba8eeb47b70c5a0f07 Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Fri, 24 Nov 2023 14:43:12 +0100 Subject: [PATCH 1/2] Add metrics for the shadow autopilot --- crates/autopilot/src/run.rs | 2 ++ crates/autopilot/src/shadow.rs | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/autopilot/src/run.rs b/crates/autopilot/src/run.rs index 6e90f8d3de..f9df1dae5d 100644 --- a/crates/autopilot/src/run.rs +++ b/crates/autopilot/src/run.rs @@ -672,6 +672,8 @@ async fn shadow_mode(args: Arguments) -> ! { .await }; + let _ = shared::metrics::serve_metrics(Arc::new(shadow::Liveness), args.metrics_address); + let shadow = shadow::RunLoop::new( orderbook, drivers, diff --git a/crates/autopilot/src/shadow.rs b/crates/autopilot/src/shadow.rs index 8e38be329c..1c2c9c74f2 100644 --- a/crates/autopilot/src/shadow.rs +++ b/crates/autopilot/src/shadow.rs @@ -21,11 +21,20 @@ use { number::nonzero::U256 as NonZeroU256, primitive_types::{H160, U256}, rand::seq::SliceRandom, - shared::token_list::AutoUpdatingTokenList, + shared::{metrics::LivenessChecking, token_list::AutoUpdatingTokenList}, std::{cmp, time::Duration}, tracing::Instrument, }; +pub struct Liveness; +#[async_trait::async_trait] +impl LivenessChecking for Liveness { + async fn is_alive(&self) -> bool { + // can we somehow check that we keep processing auctions? + true + } +} + pub struct RunLoop { orderbook: protocol::Orderbook, drivers: Vec, @@ -108,6 +117,7 @@ impl RunLoop { async fn single_run(&self, id: AuctionId, auction: Auction) { tracing::info!("solving"); Metrics::get().auction.set(id); + Metrics::get().orders.set(auction.orders.len() as _); let mut participants = self.competition(id, &auction).await; @@ -140,6 +150,7 @@ impl RunLoop { .performance_rewards .with_label_values(&[&driver.name]) .inc_by(reward.to_f64_lossy()); + Metrics::get().wins.with_label_values(&[&driver.name]).inc(); } let hex = |bytes: &[u8]| format!("0x{}", hex::encode(bytes)); @@ -292,6 +303,9 @@ struct Metrics { /// Tracks the last seen auction. auction: prometheus::IntGauge, + /// Tracks the number of orders in the auction. + orders: prometheus::IntGauge, + /// Tracks the result of every driver. #[metric(labels("driver", "result"))] results: prometheus::IntCounterVec, @@ -299,6 +313,10 @@ struct Metrics { /// Tracks the approximate performance rewards per driver #[metric(labels("driver"))] performance_rewards: prometheus::CounterVec, + + /// Tracks the winner of every auction. + #[metric(labels("driver"))] + wins: prometheus::CounterVec, } impl Metrics { From 79c7aac32860fe61a1db2a4b4800c6791ef69e74 Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Fri, 24 Nov 2023 15:08:24 +0100 Subject: [PATCH 2/2] clippy --- crates/autopilot/src/run.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/autopilot/src/run.rs b/crates/autopilot/src/run.rs index f9df1dae5d..11bd9f4ad8 100644 --- a/crates/autopilot/src/run.rs +++ b/crates/autopilot/src/run.rs @@ -672,7 +672,7 @@ async fn shadow_mode(args: Arguments) -> ! { .await }; - let _ = shared::metrics::serve_metrics(Arc::new(shadow::Liveness), args.metrics_address); + shared::metrics::serve_metrics(Arc::new(shadow::Liveness), args.metrics_address); let shadow = shadow::RunLoop::new( orderbook,