Skip to content

Commit 5d4c5e5

Browse files
JulianVenturaJulian Ventura
andauthored
feat: add batcher queue len and queue size in bytes metrics (#1593)
Co-authored-by: Julian Ventura <[email protected]>
1 parent a810589 commit 5d4c5e5

File tree

3 files changed

+471
-89
lines changed

3 files changed

+471
-89
lines changed

batcher/aligned-batcher/src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use tokio::time::{timeout, Instant};
1616
use types::batch_state::BatchState;
1717
use types::user_state::UserState;
1818

19+
use batch_queue::calculate_batch_size;
1920
use std::collections::HashMap;
2021
use std::env;
2122
use std::net::SocketAddr;
@@ -1043,10 +1044,13 @@ impl Batcher {
10431044
BatchQueueEntryPriority::new(max_fee, nonce),
10441045
);
10451046

1046-
info!(
1047-
"Current batch queue length: {}",
1048-
batch_state_lock.batch_queue.len()
1049-
);
1047+
// Update metrics
1048+
let queue_len = batch_state_lock.batch_queue.len();
1049+
let queue_size_bytes = calculate_batch_size(&batch_state_lock.batch_queue)?;
1050+
self.metrics
1051+
.update_queue_metrics(queue_len as i64, queue_size_bytes as i64);
1052+
1053+
info!("Current batch queue length: {}", queue_len);
10501054

10511055
let mut proof_submitter_addr = proof_submitter_addr;
10521056

@@ -1226,6 +1230,13 @@ impl Batcher {
12261230
))?;
12271231
}
12281232

1233+
// Update metrics
1234+
let queue_len = batch_state_lock.batch_queue.len();
1235+
let queue_size_bytes = calculate_batch_size(&batch_state_lock.batch_queue)?;
1236+
1237+
self.metrics
1238+
.update_queue_metrics(queue_len as i64, queue_size_bytes as i64);
1239+
12291240
Ok(())
12301241
}
12311242

@@ -1373,6 +1384,8 @@ impl Batcher {
13731384
batch_state_lock
13741385
.user_states
13751386
.insert(nonpaying_replacement_addr, nonpaying_user_state);
1387+
1388+
self.metrics.update_queue_metrics(0, 0);
13761389
}
13771390

13781391
/// Receives new block numbers, checks if conditions are met for submission and

batcher/aligned-batcher/src/metrics.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub struct BatcherMetrics {
2020
pub batcher_started: IntCounter,
2121
pub gas_price_used_on_latest_batch: IntGauge,
2222
pub broken_ws_connections: IntCounter,
23+
pub queue_len: IntGauge,
24+
pub queue_size_bytes: IntGauge,
2325
pub s3_duration: IntGauge,
2426
pub create_new_task_duration: IntGauge,
2527
pub cancel_create_new_task_duration: IntGauge,
@@ -52,6 +54,11 @@ impl BatcherMetrics {
5254
"broken_ws_connections_count",
5355
"Broken websocket connections"
5456
))?;
57+
let queue_len = register_int_gauge!(opts!("queue_len", "Amount of proofs in the queue"))?;
58+
let queue_size_bytes = register_int_gauge!(opts!(
59+
"queue_size_bytes",
60+
"Accumulated size in bytes of all proofs in the queue"
61+
))?;
5562
let s3_duration = register_int_gauge!(opts!("s3_duration", "S3 Duration"))?;
5663
let create_new_task_duration = register_int_gauge!(opts!(
5764
"create_new_task_duration",
@@ -82,6 +89,8 @@ impl BatcherMetrics {
8289
registry.register(Box::new(gas_price_used_on_latest_batch.clone()))?;
8390
registry.register(Box::new(batcher_started.clone()))?;
8491
registry.register(Box::new(broken_ws_connections.clone()))?;
92+
registry.register(Box::new(queue_len.clone()))?;
93+
registry.register(Box::new(queue_size_bytes.clone()))?;
8594
registry.register(Box::new(s3_duration.clone()))?;
8695
registry.register(Box::new(create_new_task_duration.clone()))?;
8796
registry.register(Box::new(cancel_create_new_task_duration.clone()))?;
@@ -108,6 +117,8 @@ impl BatcherMetrics {
108117
batcher_started,
109118
gas_price_used_on_latest_batch,
110119
broken_ws_connections,
120+
queue_len,
121+
queue_size_bytes,
111122
s3_duration,
112123
create_new_task_duration,
113124
cancel_create_new_task_duration,
@@ -142,4 +153,9 @@ impl BatcherMetrics {
142153
pub fn user_error(&self, label_values: &[&str]) {
143154
self.user_errors.with_label_values(label_values).inc();
144155
}
156+
157+
pub fn update_queue_metrics(&self, queue_len: i64, queue_size: i64) {
158+
self.queue_len.set(queue_len);
159+
self.queue_size_bytes.set(queue_size);
160+
}
145161
}

0 commit comments

Comments
 (0)