Skip to content

Commit

Permalink
Add metrics for the shadow autopilot (#2079)
Browse files Browse the repository at this point in the history
# 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
<!-- List of detailed changes (how the change is accomplished) -->

- [ ] 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.
  • Loading branch information
fleupold authored Nov 28, 2023
1 parent 1be0d01 commit a72c4c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 19 additions & 1 deletion crates/autopilot/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Driver>,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -292,13 +303,20 @@ 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,

/// 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 {
Expand Down

0 comments on commit a72c4c3

Please sign in to comment.