Skip to content

Commit

Permalink
[statement-distribution] Add metrics for distributed statements in V2 (
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiEres authored and TarekkMA committed Aug 2, 2024
1 parent 3c73beb commit 9c31b7b
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 32 deletions.
30 changes: 26 additions & 4 deletions polkadot/node/network/statement-distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,14 @@ impl<R: rand::Rng> StatementDistributionSubsystem<R> {
);
},
MuxedMessage::Response(result) => {
v2::handle_response(&mut ctx, &mut state, result, &mut self.reputation).await;
v2::handle_response(
&mut ctx,
&mut state,
result,
&mut self.reputation,
&self.metrics,
)
.await;
},
MuxedMessage::RetryRequest(()) => {
// A pending request is ready to retry. This is only a signal to call
Expand Down Expand Up @@ -320,7 +327,8 @@ impl<R: rand::Rng> StatementDistributionSubsystem<R> {
let mode = prospective_parachains_mode(ctx.sender(), activated.hash).await?;
if let ProspectiveParachainsMode::Enabled { .. } = mode {
let res =
v2::handle_active_leaves_update(ctx, state, activated, mode).await;
v2::handle_active_leaves_update(ctx, state, activated, mode, &metrics)
.await;
// Regardless of the result of leaf activation, we always prune before
// handling it to avoid leaks.
v2::handle_deactivate_leaves(state, &deactivated);
Expand Down Expand Up @@ -370,6 +378,7 @@ impl<R: rand::Rng> StatementDistributionSubsystem<R> {
relay_parent,
statement,
&mut self.reputation,
&self.metrics,
)
.await?;
}
Expand Down Expand Up @@ -428,11 +437,24 @@ impl<R: rand::Rng> StatementDistributionSubsystem<R> {

if target.targets_current() {
// pass to v2.
v2::handle_network_update(ctx, state, event, &mut self.reputation).await;
v2::handle_network_update(
ctx,
state,
event,
&mut self.reputation,
&self.metrics,
)
.await;
}
},
StatementDistributionMessage::Backed(candidate_hash) => {
crate::v2::handle_backed_candidate_message(ctx, state, candidate_hash).await;
crate::v2::handle_backed_candidate_message(
ctx,
state,
candidate_hash,
&self.metrics,
)
.await;
},
},
}
Expand Down
9 changes: 8 additions & 1 deletion polkadot/node/network/statement-distribution/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ const HISTOGRAM_LATENCY_BUCKETS: &[f64] = &[
#[derive(Clone)]
struct MetricsInner {
// V1
statements_distributed: prometheus::Counter<prometheus::U64>,
sent_requests: prometheus::Counter<prometheus::U64>,
received_responses: prometheus::CounterVec<prometheus::U64>,
network_bridge_update: prometheus::HistogramVec,
statements_unexpected: prometheus::CounterVec<prometheus::U64>,
created_message_size: prometheus::Gauge<prometheus::U64>,
// V1+
statements_distributed: prometheus::Counter<prometheus::U64>,
active_leaves_update: prometheus::Histogram,
share: prometheus::Histogram,
// V2+
Expand All @@ -51,6 +51,13 @@ impl Metrics {
}
}

/// Update statements distributed counter by an amount
pub fn on_statements_distributed(&self, n: usize) {
if let Some(metrics) = &self.0 {
metrics.statements_distributed.inc_by(n as u64);
}
}

/// Update sent requests counter
/// This counter is updated merely for the statements sent via request/response method,
/// meaning that it counts large statements only
Expand Down
Loading

0 comments on commit 9c31b7b

Please sign in to comment.