From a72c4c374afea785929a0a0a98d7840faf3df34c Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Tue, 28 Nov 2023 13:07:26 +0100 Subject: [PATCH] Add metrics for the shadow autopilot (#2079) # Description When changing the shadow infra over to the colocated architecture, we need to also create a replacement for the shadow [solver dashboard](https://g-0263500beb.grafana-workspace.eu-central-1.amazonaws.com/d/AGoBVqH7z/gpv2-shadow-traffic-staging?orgId=1). This PR prepares this. # Changes - [ ] Implement dummy liveness check for shadow runloop - [ ] Serve metrics in shadow mode - [ ] Record a few more metrics (mainly the winner in each auction + total orders in the book) ## How to test Running locally and checking http://localhost:9589/metrics Will update the dashboard once this is merged. --- 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..11bd9f4ad8 100644 --- a/crates/autopilot/src/run.rs +++ b/crates/autopilot/src/run.rs @@ -672,6 +672,8 @@ async fn shadow_mode(args: Arguments) -> ! { .await }; + 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 {