Skip to content

Commit 03ea8f8

Browse files
authored
Improve FB metrics even more (#380)
* Add counter metrics Fix histogram to show correct distr * Add counter metrics Fix histogram to show correct distr
1 parent eae7365 commit 03ea8f8

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

crates/rollup-boost/src/flashblocks/metrics.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@ pub struct FlashblocksServiceMetrics {
2828
#[metric(describe = "Number of messages processed by the service")]
2929
pub messages_processed: Counter,
3030

31-
#[metric(describe = "Number of flashblocks used to build a block")]
32-
pub flashblocks_used: Histogram,
31+
#[metric(describe = "Total number of used flashblocks")]
32+
pub flashblocks_gauge: Gauge,
33+
34+
#[metric(describe = "Total number of used flashblocks")]
35+
pub flashblocks_counter: Counter,
36+
37+
#[metric(describe = "Reduction in flashblocks issued.")]
38+
pub flashblocks_missing_histogram: Histogram,
39+
40+
#[metric(describe = "Reduction in flashblocks issued.")]
41+
pub flashblocks_missing_gauge: Gauge,
42+
43+
#[metric(describe = "Reduction in flashblocks issued.")]
44+
pub flashblocks_missing_counter: Counter,
45+
}
46+
47+
impl FlashblocksServiceMetrics {
48+
pub fn record_flashblocks(&self, flashblocks_count: u64, max_flashblocks: u64) {
49+
let reduced_flashblocks = max_flashblocks.saturating_sub(flashblocks_count);
50+
self.flashblocks_gauge.set(flashblocks_count as f64);
51+
self.flashblocks_counter.increment(flashblocks_count);
52+
self.flashblocks_missing_histogram
53+
.record(reduced_flashblocks as f64);
54+
self.flashblocks_missing_gauge
55+
.set(reduced_flashblocks as f64);
56+
self.flashblocks_missing_counter
57+
.increment(reduced_flashblocks);
58+
}
3359
}

crates/rollup-boost/src/flashblocks/service.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use reth_optimism_payload_builder::payload_id_optimism;
2222
use serde::{Deserialize, Serialize};
2323
use std::io;
2424
use std::sync::Arc;
25+
use std::sync::atomic::{AtomicU64, Ordering};
2526
use thiserror::Error;
2627
use tokio::sync::RwLock;
2728
use tokio::sync::mpsc;
@@ -187,7 +188,12 @@ pub struct FlashblocksService {
187188
/// Websocket publisher for sending valid pre-confirmations to clients.
188189
ws_pub: Arc<WebSocketPublisher>,
189190

191+
/// Metrics
190192
metrics: FlashblocksServiceMetrics,
193+
194+
/// Atomic to track absolute maximum number of flashblocks used is block building.
195+
/// This used to measures the reduction in flashblocks issued.
196+
max_flashblocks: Arc<AtomicU64>,
191197
}
192198

193199
impl FlashblocksService {
@@ -200,6 +206,7 @@ impl FlashblocksService {
200206
best_payload: Arc::new(RwLock::new(FlashblockBuilder::new())),
201207
ws_pub,
202208
metrics: Default::default(),
209+
max_flashblocks: Arc::new(AtomicU64::new(0)),
203210
})
204211
}
205212

@@ -219,10 +226,13 @@ impl FlashblocksService {
219226
// consume the best payload and reset the builder
220227
let payload = {
221228
let mut builder = self.best_payload.write().await;
222-
let flashblocks_number = builder.flashblocks.len();
229+
let flashblocks_number = builder.flashblocks.len() as u64;
230+
let max_flashblocks = self
231+
.max_flashblocks
232+
.fetch_max(flashblocks_number, Ordering::Relaxed)
233+
.max(flashblocks_number);
223234
self.metrics
224-
.flashblocks_used
225-
.record(flashblocks_number as f64);
235+
.record_flashblocks(flashblocks_number, max_flashblocks);
226236
tracing::Span::current().record("flashblocks_count", flashblocks_number);
227237
// Take payload and place new one in its place in one go to avoid double locking
228238
std::mem::replace(&mut *builder, FlashblockBuilder::new()).into_envelope(version)?

0 commit comments

Comments
 (0)