Skip to content

Commit afd4a8b

Browse files
author
Stanisław Drozd
authored
wormhole-attester: Add a histogram metric for tx processing duration (#434)
This adds buckets between 16ms and 65.536 seconds. In tilt, most attestation txs fall between 256 and 1024 milliseconds.
1 parent 5484606 commit afd4a8b

File tree

1 file changed

+21
-0
lines changed
  • solana/pyth2wormhole/client/src

1 file changed

+21
-0
lines changed

solana/pyth2wormhole/client/src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ use {
2121
},
2222
p2w_sdk::P2WEmitter,
2323
prometheus::{
24+
register_histogram,
2425
register_int_counter,
2526
register_int_gauge,
27+
Histogram,
2628
IntCounter,
2729
IntGauge,
2830
},
@@ -99,6 +101,13 @@ lazy_static! {
99101
"Latest sequence number produced by this attester"
100102
)
101103
.expect("FATAL: Could not instantiate LAST_SEQNO_GAUGE");
104+
static ref SOL_RPC_TX_PROCESSING_HIST: Histogram = register_histogram!(
105+
"sol_rpc_tx_processing",
106+
"How long in milliseconds it takes to send a transaction to the Solana RPC",
107+
prometheus::exponential_buckets(0.016, 2.0, 13) // 0.016s, 0.032s, 0.064s, [...], 65.536s
108+
.expect("FATAL: Could not instantiate buckets for SOL_RPC_TX_PROCESSING_HIST")
109+
)
110+
.expect("FATAL: Could not instantiate SOL_RPC_TX_PROCESSING_HIST");
102111
}
103112

104113
#[tokio::main(flavor = "multi_thread")]
@@ -813,6 +822,9 @@ async fn attestation_job(args: AttestationJobArgs) -> Result<(), ErrBoxSend> {
813822
symbols.as_slice(),
814823
latest_blockhash,
815824
);
825+
826+
let tx_processing_start_time = Instant::now();
827+
816828
let sig = rpc
817829
.send_and_confirm_transaction(&tx_res?)
818830
.map_err(|e| -> ErrBoxSend { e.into() })
@@ -827,6 +839,15 @@ async fn attestation_job(args: AttestationJobArgs) -> Result<(), ErrBoxSend> {
827839
},
828840
)
829841
.await?;
842+
843+
let tx_processing_duration = tx_processing_start_time.elapsed();
844+
845+
// Manually insert the value into histogram. NOTE: We're not
846+
// using the start_timer() method because it would record
847+
// durations even for early returns in error conditions which
848+
// would look weird in monitoring.
849+
SOL_RPC_TX_PROCESSING_HIST.observe(tx_processing_duration.as_secs_f64());
850+
830851
let seqno = tx_data
831852
.transaction
832853
.meta

0 commit comments

Comments
 (0)