Skip to content

Commit dfa90a0

Browse files
authored
feat: metrics for when blocks are submitted [ENG-702] (#33)
1 parent 1fed095 commit dfa90a0

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ tracing-subscriber = "0.3.18"
5050

5151
async-trait = "0.1.80"
5252
oauth2 = "4.4.2"
53+
metrics = "0.24.1"
54+
metrics-exporter-prometheus = "0.16.0"

bin/builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use builder::service::serve_builder_with_span;
55
use builder::tasks::block::BlockBuilder;
66
use builder::tasks::oauth::Authenticator;
77
use builder::tasks::submit::SubmitTask;
8+
use metrics_exporter_prometheus::PrometheusBuilder;
89

910
use tokio::select;
1011

@@ -17,6 +18,8 @@ async fn main() -> eyre::Result<()> {
1718
let provider = config.connect_provider().await?;
1819
let authenticator = Authenticator::new(&config);
1920

21+
PrometheusBuilder::new().install().expect("failed to install prometheus exporter");
22+
2023
tracing::debug!(rpc_url = config.host_rpc_url.as_ref(), "instantiated provider");
2124

2225
let sequencer_signer = config.connect_sequencer_signer().await?;

src/tasks/submit.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use alloy::{
1717
use alloy_primitives::{FixedBytes, U256};
1818
use alloy_sol_types::SolError;
1919
use eyre::{bail, eyre};
20+
use metrics::{counter, histogram};
2021
use oauth2::TokenResponse;
22+
use std::time::Instant;
2123
use tokio::{sync::mpsc, task::JoinHandle};
2224
use tracing::{debug, error, instrument, trace};
2325
use zenith_types::{
@@ -170,7 +172,6 @@ impl SubmitTask {
170172

171173
return Ok(ControlFlow::Skip);
172174
}
173-
174175
self.send_transaction(resp, tx).await
175176
}
176177

@@ -252,6 +253,7 @@ impl SubmitTask {
252253
sig = hex::encode(resp.sig.as_bytes()),
253254
"acquired signature from quincey"
254255
);
256+
counter!("builder.quincey_signature_acquired").increment(1);
255257
resp
256258
};
257259

@@ -264,12 +266,16 @@ impl SubmitTask {
264266
let handle = tokio::spawn(async move {
265267
loop {
266268
if let Some(in_progress) = inbound.recv().await {
269+
let building_start_time = Instant::now();
267270
let mut retries = 0;
268271
loop {
269272
match self.handle_inbound(&in_progress).await {
270273
Ok(ControlFlow::Retry) => {
271274
retries += 1;
272275
if retries > 3 {
276+
counter!("builder.building_too_many_retries").increment(1);
277+
histogram!("builder.block_build_time")
278+
.record(building_start_time.elapsed().as_millis() as f64);
273279
tracing::error!(
274280
"error handling inbound block: too many retries"
275281
);
@@ -279,10 +285,16 @@ impl SubmitTask {
279285
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
280286
}
281287
Ok(ControlFlow::Skip) => {
288+
histogram!("builder.block_build_time")
289+
.record(building_start_time.elapsed().as_millis() as f64);
290+
counter!("builder.skipped_blocks").increment(1);
282291
tracing::info!("skipping block");
283292
break;
284293
}
285294
Ok(ControlFlow::Done) => {
295+
histogram!("builder.block_build_time")
296+
.record(building_start_time.elapsed().as_millis() as f64);
297+
counter!("builder.submitted_successful_blocks").increment(1);
286298
tracing::info!("block landed successfully");
287299
break;
288300
}

src/tasks/tx_poller.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use serde_json::from_slice;
1111

1212
pub use crate::config::BuilderConfig;
1313

14+
use metrics::counter;
15+
1416
#[derive(Debug, Clone, Serialize, Deserialize)]
1517
pub struct TxPoolResponse {
1618
transactions: Vec<TxEnvelope>,
@@ -54,6 +56,7 @@ impl TxPoller {
5456
self.seen_txns.entry(*tx.tx_hash()).or_insert_with(|| {
5557
// add to unique transactions
5658
unique.push(tx.clone());
59+
counter!("builder.unique_txs").increment(1);
5760
// expiry is now + cache_duration
5861
time::Instant::now() + Duration::from_secs(self.config.tx_pool_cache_duration)
5962
});
@@ -77,6 +80,7 @@ impl TxPoller {
7780

7881
for key in expired_keys {
7982
self.seen_txns.remove(&key);
83+
counter!("builder.evicted_txs").increment(1);
8084
}
8185
}
8286
}

0 commit comments

Comments
 (0)