From 0baff09b91e3ac011f9a1f6556f9845a9e3f817d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sehyun=20Chung=20=E2=9C=8C=EF=B8=8E?= <41171808+sehyunc@users.noreply.github.com> Date: Fri, 17 Jan 2025 13:11:15 -0800 Subject: [PATCH] auth-server: add order attrributes to bundle logs --- .../src/server/handle_external_match.rs | 41 +++++++++++++++++-- auth/auth-server/src/telemetry/helpers.rs | 2 + 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/auth/auth-server/src/server/handle_external_match.rs b/auth/auth-server/src/server/handle_external_match.rs index 6c8c9db..831247e 100644 --- a/auth/auth-server/src/server/handle_external_match.rs +++ b/auth/auth-server/src/server/handle_external_match.rs @@ -17,6 +17,7 @@ use renegade_common::types::{token::Token, TimestampedPrice}; use super::Server; use crate::error::AuthServerError; +use crate::telemetry::helpers::calculate_implied_price; use crate::telemetry::{ helpers::{ await_settlement, record_endpoint_metrics, record_external_match_metrics, record_fill_ratio, @@ -157,9 +158,10 @@ impl Server { let match_resp: ExternalMatchResponse = serde_json::from_slice(resp).map_err(AuthServerError::serde)?; + let request_id = uuid::Uuid::new_v4().to_string(); let labels = vec![ (KEY_DESCRIPTION_METRIC_TAG.to_string(), key.clone()), - (REQUEST_ID_METRIC_TAG.to_string(), uuid::Uuid::new_v4().to_string()), + (REQUEST_ID_METRIC_TAG.to_string(), request_id.clone()), (DECIMAL_CORRECTION_FIXED_METRIC_TAG.to_string(), "true".to_string()), ]; @@ -177,7 +179,7 @@ impl Server { } // Log the bundle and record metrics - self.log_bundle(resp)?; + self.log_bundle(&order, resp, &request_id)?; record_external_match_metrics(&order, match_resp, key, did_settle).await?; Ok(()) @@ -203,17 +205,48 @@ impl Server { } /// Log the bundle parameters - fn log_bundle(&self, bundle_bytes: &[u8]) -> Result<(), AuthServerError> { + fn log_bundle( + &self, + order: &ExternalOrder, + bundle_bytes: &[u8], + request_id: &str, + ) -> Result<(), AuthServerError> { let resp = serde_json::from_slice::(bundle_bytes) .map_err(AuthServerError::serde)?; + // Get the decimal-corrected price + let price = calculate_implied_price(&resp.match_bundle, true /* decimal_correct */)?; + let price_fixed = FixedPoint::from_f64_round_down(price); + let match_result = resp.match_bundle.match_result; let is_buy = match_result.direction; let recv = resp.match_bundle.receive; let send = resp.match_bundle.send; + + // Get the base fill ratio + let requested_base_amount = order.get_base_amount(price_fixed); + let response_base_amount = match_result.base_amount; + let base_fill_ratio = response_base_amount as f64 / requested_base_amount as f64; + + // Get the quote fill ratio + let requested_quote_amount = order.get_quote_amount(price_fixed); + let matched_quote_amount = match_result.quote_amount; + let quote_fill_ratio = matched_quote_amount as f64 / requested_quote_amount as f64; + info!( + requested_base_amount = requested_base_amount, + response_base_amount = response_base_amount, + requested_quote_amount = requested_quote_amount, + matched_quote_amount = matched_quote_amount, + base_fill_ratio = base_fill_ratio, + quote_fill_ratio = quote_fill_ratio, + request_id = request_id, "Sending bundle(is_buy: {}, recv: {} ({}), send: {} ({})) to client", - is_buy, recv.amount, recv.mint, send.amount, send.mint + is_buy, + recv.amount, + recv.mint, + send.amount, + send.mint ); Ok(()) diff --git a/auth/auth-server/src/telemetry/helpers.rs b/auth/auth-server/src/telemetry/helpers.rs index a59956f..cdd77fb 100644 --- a/auth/auth-server/src/telemetry/helpers.rs +++ b/auth/auth-server/src/telemetry/helpers.rs @@ -247,6 +247,8 @@ pub(crate) async fn record_external_match_metrics( // Get decimal-corrected price let price = calculate_implied_price(&match_resp.match_bundle, true /* decimal_correct */)?; + let price_fixed = FixedPoint::from_f64_round_down(price); + let price_fixed_f64 = price_fixed.to_f64(); // Record request metrics if let Err(e) = record_external_match_request_metrics(order, price, &labels) {