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

Bad token detector metrics #3228

Merged
merged 6 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 18 additions & 2 deletions crates/driver/src/domain/competition/bad_tokens/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use {
super::Quality,
crate::domain::eth,
crate::{
domain::eth,
infra::{observe::metrics, solver},
},
dashmap::DashMap,
std::{
sync::Arc,
Expand All @@ -27,6 +30,7 @@ pub struct Detector {
counter: Arc<DashMap<eth::TokenAddress, TokenStatistics>>,
log_only: bool,
token_freeze_time: Duration,
solver: solver::Name,
}

impl Detector {
Expand All @@ -35,13 +39,15 @@ impl Detector {
required_measurements: u32,
log_only: bool,
token_freeze_time: Duration,
solver: solver::Name,
) -> Self {
Self {
failure_ratio,
required_measurements,
counter: Default::default(),
log_only,
token_freeze_time,
solver,
}
}

Expand Down Expand Up @@ -120,6 +126,10 @@ impl Detector {
tokens = ?new_unsupported_tokens,
"mark tokens as unsupported"
);
metrics::get()
.bad_tokens_detected
.with_label_values(&[&self.solver.0, "metrics"])
.inc_by(new_unsupported_tokens.len() as u64);
}
}
}
Expand All @@ -133,7 +143,13 @@ mod tests {
#[tokio::test]
async fn unfreeze_bad_tokens() {
const FREEZE_DURATION: Duration = Duration::from_millis(50);
let detector = Detector::new(0.5, 2, false, FREEZE_DURATION);
let detector = Detector::new(
0.5,
2,
false,
FREEZE_DURATION,
solver::Name("mysolver".to_string()),
);

let token_a = eth::TokenAddress(eth::ContractAddress(H160([1; 20])));
let token_b = eth::TokenAddress(eth::ContractAddress(H160([2; 20])));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
},
eth,
},
infra,
infra::{self, observe::metrics},
},
futures::FutureExt,
model::interaction::InteractionData,
Expand Down Expand Up @@ -100,6 +100,8 @@ impl Detector {
}
Ok(TokenQuality::Bad { reason }) => {
tracing::debug!(reason, token=?sell_token.0, "cache token as unsupported");
// All solvers share the same cache for the simulation detector, so there is no need to specify the solver name here.
metrics::get().bad_tokens_detected.with_label_values(&["any", "simulation"]).inc();
inner
.cache
.update_quality(sell_token, false, now);
Expand Down
1 change: 1 addition & 0 deletions crates/driver/src/infra/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl Api {
bad_token_config.metrics_strategy_required_measurements,
bad_token_config.metrics_strategy_log_only,
bad_token_config.metrics_strategy_token_freeze_time,
name.clone(),
));
}

Expand Down
3 changes: 3 additions & 0 deletions crates/driver/src/infra/observe/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub struct Metrics {
/// The results of the mempool submission.
#[metric(labels("mempool", "result"))]
pub mempool_submission: prometheus::IntCounterVec,
/// How many tokens detected by specific solver and strategy.
#[metric(labels("solver", "strategy"))]
pub bad_tokens_detected: prometheus::IntCounterVec,
}

/// Setup the metrics registry.
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/infra/observe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use {
url::Url,
};

mod metrics;
pub mod metrics;

/// Setup the observability. The log argument configures the tokio tracing
/// framework.
Expand Down
Loading