Skip to content

Commit

Permalink
fix: improve svm landing time metric (#373)
Browse files Browse the repository at this point in the history
* improve measurements

* update buckets for svm landing

* bump

* fix: pr comments
  • Loading branch information
guibescos authored Feb 5, 2025
1 parent 91b7869 commit 44026ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions auction-server/src/auction/service/auction_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use {
self,
service::get_live_opportunities::GetLiveOpportunitiesInput,
},
per_metrics::TRANSACTION_LANDING_TIME_SVM_METRIC,
},
anyhow::Result,
axum::async_trait,
Expand Down Expand Up @@ -689,8 +690,7 @@ impl Service<Svm> {
}

#[tracing::instrument(skip_all, fields(bid_id, total_tries, tx_hash))]
async fn blocking_send_transaction(&self, bid: entities::Bid<Svm>) {
let start = Instant::now();
async fn blocking_send_transaction(&self, bid: entities::Bid<Svm>, start: Instant) {
let mut result_label = METRIC_LABEL_EXPIRED;
let signature = bid.chain_data.transaction.signatures[0];
tracing::Span::current().record("bid_id", bid.id.to_string());
Expand Down Expand Up @@ -737,7 +737,7 @@ impl Service<Svm> {
// but this is rare as we retry for 60 seconds and blockhash expires after 60 seconds
("result", result_label.to_string()),
];
metrics::histogram!("transaction_landing_time_seconds_svm", &labels)
metrics::histogram!(TRANSACTION_LANDING_TIME_SVM_METRIC, &labels)
.record(start.elapsed().as_secs_f64());

tracing::Span::current().record("total_tries", retry_count + 1);
Expand All @@ -749,6 +749,7 @@ impl Service<Svm> {
#[tracing::instrument(skip_all, fields(bid_id))]
pub async fn send_transaction(&self, bid: &entities::Bid<Svm>) -> Signature {
tracing::Span::current().record("bid_id", bid.id.to_string());
let start = Instant::now();
let tx = &bid.chain_data.transaction;
// Do not propagate the error because we retry more in the blocking_send_transaction
if let Err(e) = self
Expand All @@ -762,10 +763,11 @@ impl Service<Svm> {
.simulator
.add_pending_transaction(tx)
.await;

self.task_tracker.spawn({
let (service, bid) = (self.clone(), bid.clone());
async move {
service.blocking_send_transaction(bid).await;
service.blocking_send_transaction(bid, start).await;
}
});
tx.signatures[0]
Expand Down
5 changes: 5 additions & 0 deletions auction-server/src/per_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ use {
},
};

pub const TRANSACTION_LANDING_TIME_SVM_METRIC: &str = "transaction_landing_time_seconds_svm";
pub const TRANSACTION_LANDING_TIME_SVM_BUCKETS: &[f64; 16] = &[
0.1, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 3.75, 5.0, 10.0, 20.0, 40.0,
];

#[derive(Debug, Clone)]
pub struct MetricsLayerData {
category: String,
Expand Down
7 changes: 7 additions & 0 deletions auction-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ async fn fetch_access_tokens(db: &PgPool) -> HashMap<models::AccessTokenToken, m

pub fn setup_metrics_recorder() -> Result<PrometheusHandle> {
PrometheusBuilder::new()
.set_buckets_for_metric(
axum_prometheus::metrics_exporter_prometheus::Matcher::Full(
per_metrics::TRANSACTION_LANDING_TIME_SVM_METRIC.to_string(),
),
per_metrics::TRANSACTION_LANDING_TIME_SVM_BUCKETS,
)
.unwrap()
.set_buckets(SECONDS_DURATION_BUCKETS)
.unwrap()
.install_recorder()
Expand Down

0 comments on commit 44026ba

Please sign in to comment.