Skip to content

Commit d31285a

Browse files
authored
[statement-distribution] Add metrics for distributed statements in V2 (#4554)
Part of #4334
1 parent ebb1bb6 commit d31285a

3 files changed

Lines changed: 109 additions & 32 deletions

File tree

polkadot/node/network/statement-distribution/src/lib.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,14 @@ impl<R: rand::Rng> StatementDistributionSubsystem<R> {
284284
);
285285
},
286286
MuxedMessage::Response(result) => {
287-
v2::handle_response(&mut ctx, &mut state, result, &mut self.reputation).await;
287+
v2::handle_response(
288+
&mut ctx,
289+
&mut state,
290+
result,
291+
&mut self.reputation,
292+
&self.metrics,
293+
)
294+
.await;
288295
},
289296
MuxedMessage::RetryRequest(()) => {
290297
// A pending request is ready to retry. This is only a signal to call
@@ -320,7 +327,8 @@ impl<R: rand::Rng> StatementDistributionSubsystem<R> {
320327
let mode = prospective_parachains_mode(ctx.sender(), activated.hash).await?;
321328
if let ProspectiveParachainsMode::Enabled { .. } = mode {
322329
let res =
323-
v2::handle_active_leaves_update(ctx, state, activated, mode).await;
330+
v2::handle_active_leaves_update(ctx, state, activated, mode, &metrics)
331+
.await;
324332
// Regardless of the result of leaf activation, we always prune before
325333
// handling it to avoid leaks.
326334
v2::handle_deactivate_leaves(state, &deactivated);
@@ -370,6 +378,7 @@ impl<R: rand::Rng> StatementDistributionSubsystem<R> {
370378
relay_parent,
371379
statement,
372380
&mut self.reputation,
381+
&self.metrics,
373382
)
374383
.await?;
375384
}
@@ -428,11 +437,24 @@ impl<R: rand::Rng> StatementDistributionSubsystem<R> {
428437

429438
if target.targets_current() {
430439
// pass to v2.
431-
v2::handle_network_update(ctx, state, event, &mut self.reputation).await;
440+
v2::handle_network_update(
441+
ctx,
442+
state,
443+
event,
444+
&mut self.reputation,
445+
&self.metrics,
446+
)
447+
.await;
432448
}
433449
},
434450
StatementDistributionMessage::Backed(candidate_hash) => {
435-
crate::v2::handle_backed_candidate_message(ctx, state, candidate_hash).await;
451+
crate::v2::handle_backed_candidate_message(
452+
ctx,
453+
state,
454+
candidate_hash,
455+
&self.metrics,
456+
)
457+
.await;
436458
},
437459
},
438460
}

polkadot/node/network/statement-distribution/src/metrics.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ const HISTOGRAM_LATENCY_BUCKETS: &[f64] = &[
2525
#[derive(Clone)]
2626
struct MetricsInner {
2727
// V1
28-
statements_distributed: prometheus::Counter<prometheus::U64>,
2928
sent_requests: prometheus::Counter<prometheus::U64>,
3029
received_responses: prometheus::CounterVec<prometheus::U64>,
3130
network_bridge_update: prometheus::HistogramVec,
3231
statements_unexpected: prometheus::CounterVec<prometheus::U64>,
3332
created_message_size: prometheus::Gauge<prometheus::U64>,
3433
// V1+
34+
statements_distributed: prometheus::Counter<prometheus::U64>,
3535
active_leaves_update: prometheus::Histogram,
3636
share: prometheus::Histogram,
3737
// V2+
@@ -51,6 +51,13 @@ impl Metrics {
5151
}
5252
}
5353

54+
/// Update statements distributed counter by an amount
55+
pub fn on_statements_distributed(&self, n: usize) {
56+
if let Some(metrics) = &self.0 {
57+
metrics.statements_distributed.inc_by(n as u64);
58+
}
59+
}
60+
5461
/// Update sent requests counter
5562
/// This counter is updated merely for the statements sent via request/response method,
5663
/// meaning that it counts large statements only

0 commit comments

Comments
 (0)