Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics for the shadow autopilot #2079

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +33 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make the Liveness struct part of the shared server state and update a timestamp whenever some solver processed an auction.
Then is_alive() would check that this timestamp is not older than some healthy duration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

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
Loading