-
Notifications
You must be signed in to change notification settings - Fork 91
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
Run loop additional metrics #2888
Changes from 10 commits
97b4005
2d72a2f
26e1527
796e822
290c52f
2b7fcae
b80eff3
3e0b450
1953367
0a8d18e
f05901d
827499b
26df6e2
3243d9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ use { | |
}, | ||
number::conversions::u256_to_big_decimal, | ||
primitive_types::{H160, H256, U256}, | ||
prometheus::{IntCounter, IntCounterVec, IntGauge, IntGaugeVec}, | ||
prometheus::{Histogram, HistogramVec, IntCounter, IntCounterVec, IntGauge, IntGaugeVec}, | ||
shared::{ | ||
account_balances::{BalanceFetching, Query}, | ||
bad_token::BadTokenDetecting, | ||
|
@@ -43,6 +43,13 @@ pub struct Metrics { | |
#[metric(labels("result"))] | ||
auction_update: IntCounterVec, | ||
|
||
/// Time taken to update the solvable orders cache. | ||
auction_update_total_time: Histogram, | ||
|
||
/// Time spent on auction update individual stage. | ||
#[metric( labels("stage"))] | ||
auction_update_stage_time: HistogramVec, | ||
|
||
/// Auction creations. | ||
auction_creations: IntCounter, | ||
|
||
|
@@ -151,28 +158,62 @@ impl SolvableOrdersCache { | |
/// the case in unit tests, then concurrent calls might overwrite each | ||
/// other's results. | ||
pub async fn update(&self, block: u64) -> Result<()> { | ||
let start = Instant::now(); | ||
squadgazzz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let min_valid_to = now_in_epoch_seconds() + self.min_order_validity_period.as_secs() as u32; | ||
let db_solvable_orders = self.persistence.solvable_orders(min_valid_to).await?; | ||
|
||
let mut counter = OrderFilterCounter::new(self.metrics, &db_solvable_orders.orders); | ||
let mut invalid_order_uids = Vec::new(); | ||
let mut filtered_order_events = Vec::new(); | ||
|
||
let orders = filter_banned_user_orders(db_solvable_orders.orders, &self.banned_users).await; | ||
let removed = counter.checkpoint("banned_user", &orders); | ||
invalid_order_uids.extend(removed); | ||
let orders = { | ||
let _timer = self | ||
squadgazzz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.metrics | ||
.auction_update_stage_time | ||
.with_label_values(&["banned_user_filtering"]) | ||
.start_timer(); | ||
let orders = | ||
filter_banned_user_orders(db_solvable_orders.orders, &self.banned_users).await; | ||
let removed = counter.checkpoint("banned_user", &orders); | ||
invalid_order_uids.extend(removed); | ||
orders | ||
}; | ||
|
||
let orders = | ||
filter_invalid_signature_orders(orders, self.signature_validator.as_ref()).await; | ||
let removed = counter.checkpoint("invalid_signature", &orders); | ||
invalid_order_uids.extend(removed); | ||
let orders = { | ||
let _timer = self | ||
.metrics | ||
.auction_update_stage_time | ||
.with_label_values(&["invalid_signature_filtering"]) | ||
.start_timer(); | ||
let orders = | ||
filter_invalid_signature_orders(orders, self.signature_validator.as_ref()).await; | ||
let removed = counter.checkpoint("invalid_signature", &orders); | ||
invalid_order_uids.extend(removed); | ||
orders | ||
}; | ||
|
||
let orders = filter_unsupported_tokens(orders, self.bad_token_detector.as_ref()).await?; | ||
let removed = counter.checkpoint("unsupported_token", &orders); | ||
invalid_order_uids.extend(removed); | ||
let orders = { | ||
let _timer = self | ||
.metrics | ||
.auction_update_stage_time | ||
.with_label_values(&["unsupported_token_filtering"]) | ||
.start_timer(); | ||
let orders = | ||
filter_unsupported_tokens(orders, self.bad_token_detector.as_ref()).await?; | ||
let removed = counter.checkpoint("unsupported_token", &orders); | ||
invalid_order_uids.extend(removed); | ||
orders | ||
}; | ||
|
||
let missing_queries: Vec<_> = orders.iter().map(Query::from_order).collect(); | ||
let fetched_balances = self.balance_fetcher.get_balances(&missing_queries).await; | ||
let fetched_balances = { | ||
let _timer = self | ||
.metrics | ||
.auction_update_stage_time | ||
.with_label_values(&["balance_fetch"]) | ||
.start_timer(); | ||
self.balance_fetcher.get_balances(&missing_queries).await | ||
}; | ||
let balances = missing_queries | ||
.into_iter() | ||
.zip(fetched_balances) | ||
|
@@ -218,7 +259,14 @@ impl SolvableOrdersCache { | |
entry.insert(weth_price); | ||
} | ||
|
||
let cow_amms = self.cow_amm_registry.amms().await; | ||
let cow_amms = { | ||
let _timer = self | ||
.metrics | ||
.auction_update_stage_time | ||
.with_label_values(&["cow_amm_registry"]) | ||
.start_timer(); | ||
self.cow_amm_registry.amms().await | ||
}; | ||
let cow_amm_tokens = cow_amms | ||
.iter() | ||
.flat_map(|cow_amm| cow_amm.traded_tokens()) | ||
|
@@ -304,6 +352,9 @@ impl SolvableOrdersCache { | |
}; | ||
|
||
tracing::debug!(%block, "updated current auction cache"); | ||
self.metrics | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GIven that we know that this takes a significant amount of time we could already add metrics for the individual stages of the auction building. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a HistogramVec for individual update stages except solvable order fetching since we already have a separate DB metric for this. |
||
.auction_update_total_time | ||
.observe(start.elapsed().as_secs_f64()); | ||
Ok(()) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: If this variable is only passed in to trigger the metric, we could probably also simply do it where we call
single_run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fetch the latest block timestamp or what exactly? That would work as long as the auction update function takes less than 1 round. For arbitrum, this is not the case.