Skip to content

feat: metrics for when blocks are submitted [ENG-702] #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ tracing-subscriber = "0.3.18"

async-trait = "0.1.80"
oauth2 = "4.4.2"
metrics = "0.24.1"
metrics-exporter-prometheus = "0.16.0"
3 changes: 3 additions & 0 deletions bin/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use builder::service::serve_builder_with_span;
use builder::tasks::block::BlockBuilder;
use builder::tasks::oauth::Authenticator;
use builder::tasks::submit::SubmitTask;
use metrics_exporter_prometheus::PrometheusBuilder;

use tokio::select;

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

PrometheusBuilder::new().install().expect("failed to install prometheus exporter");

tracing::debug!(rpc_url = config.host_rpc_url.as_ref(), "instantiated provider");

let sequencer_signer = config.connect_sequencer_signer().await?;
Expand Down
14 changes: 13 additions & 1 deletion src/tasks/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use alloy::{
use alloy_primitives::{FixedBytes, U256};
use alloy_sol_types::SolError;
use eyre::{bail, eyre};
use metrics::{counter, histogram};
use oauth2::TokenResponse;
use std::time::Instant;
use tokio::{sync::mpsc, task::JoinHandle};
use tracing::{debug, error, instrument, trace};
use zenith_types::{
Expand Down Expand Up @@ -170,7 +172,6 @@ impl SubmitTask {

return Ok(ControlFlow::Skip);
}

self.send_transaction(resp, tx).await
}

Expand Down Expand Up @@ -252,6 +253,7 @@ impl SubmitTask {
sig = hex::encode(resp.sig.as_bytes()),
"acquired signature from quincey"
);
counter!("builder.quincey_signature_acquired").increment(1);
resp
};

Expand All @@ -264,12 +266,16 @@ impl SubmitTask {
let handle = tokio::spawn(async move {
loop {
if let Some(in_progress) = inbound.recv().await {
let building_start_time = Instant::now();
let mut retries = 0;
loop {
match self.handle_inbound(&in_progress).await {
Ok(ControlFlow::Retry) => {
retries += 1;
if retries > 3 {
counter!("builder.building_too_many_retries").increment(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice to have for internal visibility 🔥

histogram!("builder.block_build_time")
.record(building_start_time.elapsed().as_millis() as f64);
tracing::error!(
"error handling inbound block: too many retries"
);
Expand All @@ -279,10 +285,16 @@ impl SubmitTask {
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
}
Ok(ControlFlow::Skip) => {
histogram!("builder.block_build_time")
.record(building_start_time.elapsed().as_millis() as f64);
counter!("builder.skipped_blocks").increment(1);
tracing::info!("skipping block");
break;
}
Ok(ControlFlow::Done) => {
histogram!("builder.block_build_time")
.record(building_start_time.elapsed().as_millis() as f64);
counter!("builder.submitted_successful_blocks").increment(1);
tracing::info!("block landed successfully");
break;
}
Expand Down
4 changes: 4 additions & 0 deletions src/tasks/tx_poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use serde_json::from_slice;

pub use crate::config::BuilderConfig;

use metrics::counter;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TxPoolResponse {
transactions: Vec<TxEnvelope>,
Expand Down Expand Up @@ -54,6 +56,7 @@ impl TxPoller {
self.seen_txns.entry(*tx.tx_hash()).or_insert_with(|| {
// add to unique transactions
unique.push(tx.clone());
counter!("builder.unique_txs").increment(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we bucket these by block number maybe?

// expiry is now + cache_duration
time::Instant::now() + Duration::from_secs(self.config.tx_pool_cache_duration)
});
Expand All @@ -77,6 +80,7 @@ impl TxPoller {

for key in expired_keys {
self.seen_txns.remove(&key);
counter!("builder.evicted_txs").increment(1);
}
}
}
Loading