Skip to content

Commit

Permalink
auth-server: add flag to toggle quote comparison' (#84)
Browse files Browse the repository at this point in the history
auth-server add flag to toggle quote comparison
  • Loading branch information
sehyunc authored Jan 12, 2025
1 parent f3d3fec commit 6f361d8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 3 additions & 0 deletions auth/auth-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ pub struct Cli {
/// The StatsD recorder port to send metrics to
#[arg(long, env = "STATSD_PORT", default_value = "8125")]
pub statsd_port: u16,
/// Whether or not to enable quote comparison functionality
#[arg(long, env = "ENABLE_QUOTE_COMPARISON", default_value = "false")]
pub enable_quote_comparison: bool,
}

// -------------
Expand Down
11 changes: 6 additions & 5 deletions auth/auth-server/src/server/handle_external_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,18 @@ impl Server {
let match_resp: ExternalMatchResponse =
serde_json::from_slice(resp).map_err(AuthServerError::serde)?;

// Record quote comparison metrics before settlement
let labels = vec![
(KEY_DESCRIPTION_METRIC_TAG.to_string(), key.clone()),
(REQUEST_ID_METRIC_TAG.to_string(), uuid::Uuid::new_v4().to_string()),
(DECIMAL_CORRECTION_FIXED_METRIC_TAG.to_string(), "true".to_string()),
];

// Record quote comparisons
self.quote_metrics
.record_quote_comparison(&match_resp.match_bundle, labels.as_slice())
.await;
// Record quote comparisons before settlement, if enabled
if let Some(quote_metrics) = &self.quote_metrics {
quote_metrics
.record_quote_comparison(&match_resp.match_bundle, labels.as_slice())
.await;
}

// If the bundle settles, increase the API user's a rate limit token balance
let did_settle = await_settlement(&match_resp.match_bundle, &self.arbitrum_client).await?;
Expand Down
12 changes: 8 additions & 4 deletions auth/auth-server/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct Server {
/// The rate limiter
pub rate_limiter: BundleRateLimiter,
/// The quote metrics recorder
pub quote_metrics: Arc<QuoteComparisonHandler>,
pub quote_metrics: Option<Arc<QuoteComparisonHandler>>,
}

impl Server {
Expand All @@ -89,9 +89,13 @@ impl Server {

let rate_limiter = BundleRateLimiter::new(args.bundle_rate_limit);

// Setup the quote metrics recorder and sources
let odos_source = OdosQuoteSource::new();
let quote_metrics = Arc::new(QuoteComparisonHandler::new(vec![odos_source]));
// Setup the quote metrics recorder and sources if enabled
let quote_metrics = if args.enable_quote_comparison {
let odos_source = OdosQuoteSource::new();
Some(Arc::new(QuoteComparisonHandler::new(vec![odos_source])))
} else {
None
};

Ok(Self {
db_pool: Arc::new(db_pool),
Expand Down

0 comments on commit 6f361d8

Please sign in to comment.