Unverified Commit 6b72d032 authored by Andronik Ordian's avatar Andronik Ordian Committed by GitHub
Browse files

approval-voting metrics (#2483)

* approval-voting metrics

* metric: approvals produced
parent a6c637ae
Pipeline #127532 failed with stages
in 36 minutes and 12 seconds
......@@ -5407,6 +5407,7 @@ dependencies = [
"polkadot-node-primitives",
"polkadot-node-subsystem",
"polkadot-node-subsystem-test-helpers",
"polkadot-node-subsystem-util",
"polkadot-overseer",
"polkadot-primitives",
"rand_core 0.5.1",
......
......@@ -17,7 +17,8 @@ kvdb = "0.9.0"
kvdb-rocksdb = "0.11.0"
derive_more = "0.99.1"
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
polkadot-node-subsystem = { path = "../../subsystem" }
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
polkadot-overseer = { path = "../../overseer" }
polkadot-primitives = { path = "../../../primitives" }
polkadot-node-primitives = { path = "../../primitives" }
......
......@@ -28,7 +28,7 @@
//!
//! We maintain a rolling window of session indices. This starts as empty
use polkadot_subsystem::{
use polkadot_node_subsystem::{
messages::{
RuntimeApiMessage, RuntimeApiRequest, ChainApiMessage, ApprovalDistributionMessage,
},
......@@ -708,7 +708,7 @@ mod tests {
use polkadot_node_subsystem_test_helpers::make_subsystem_context;
use polkadot_node_primitives::approval::{VRFOutput, VRFProof};
use polkadot_primitives::v1::ValidatorIndex;
use polkadot_subsystem::messages::AllMessages;
use polkadot_node_subsystem::messages::AllMessages;
use sp_core::testing::TaskExecutor;
use sp_runtime::{Digest, DigestItem};
use sp_consensus_babe::Epoch as BabeEpoch;
......
......@@ -21,7 +21,7 @@
//! of others. It uses this information to determine when candidates and blocks have
//! been sufficiently approved to finalize.
use polkadot_subsystem::{
use polkadot_node_subsystem::{
messages::{
AssignmentCheckResult, ApprovalCheckResult, ApprovalVotingMessage,
RuntimeApiMessage, RuntimeApiRequest, ChainApiMessage, ApprovalDistributionMessage,
......@@ -31,6 +31,9 @@ use polkadot_subsystem::{
Subsystem, SubsystemContext, SubsystemError, SubsystemResult, SpawnedSubsystem,
FromOverseer, OverseerSignal,
};
use polkadot_node_subsystem_util::{
metrics::{self, prometheus},
};
use polkadot_primitives::v1::{
ValidatorIndex, Hash, SessionIndex, SessionInfo, CandidateHash,
CandidateReceipt, BlockNumber, PersistedValidationData,
......@@ -94,15 +97,79 @@ pub struct ApprovalVotingSubsystem {
keystore: Arc<LocalKeystore>,
slot_duration_millis: u64,
db: Arc<dyn KeyValueDB>,
metrics: Metrics,
}
#[derive(Clone)]
struct MetricsInner {
imported_candidates_total: prometheus::Counter<prometheus::U64>,
assignments_produced_total: prometheus::Counter<prometheus::U64>,
approvals_produced_total: prometheus::Counter<prometheus::U64>,
}
/// Aproval Voting metrics.
#[derive(Default, Clone)]
pub struct Metrics(Option<MetricsInner>);
impl Metrics {
fn on_candidate_imported(&self) {
if let Some(metrics) = &self.0 {
metrics.imported_candidates_total.inc();
}
}
fn on_assignment_produced(&self) {
if let Some(metrics) = &self.0 {
metrics.assignments_produced_total.inc();
}
}
fn on_approval_produced(&self) {
if let Some(metrics) = &self.0 {
metrics.approvals_produced_total.inc();
}
}
}
impl metrics::Metrics for Metrics {
fn try_register(
registry: &prometheus::Registry,
) -> std::result::Result<Self, prometheus::PrometheusError> {
let metrics = MetricsInner {
imported_candidates_total: prometheus::register(
prometheus::Counter::new(
"parachain_imported_candidates_total",
"Number of candidates imported by the approval voting subsystem",
)?,
registry,
)?,
assignments_produced_total: prometheus::register(
prometheus::Counter::new(
"parachain_assignments_produced_total",
"Number of assignments produced by the approval voting subsystem",
)?,
registry,
)?,
approvals_produced_total: prometheus::register(
prometheus::Counter::new(
"parachain_approvals_produced_total",
"Number of approvals produced by the approval voting subsystem",
)?,
registry,
)?,
};
Ok(Metrics(Some(metrics)))
}
}
impl ApprovalVotingSubsystem {
/// Create a new approval voting subsystem with the given keystore, slot duration,
/// Create a new approval voting subsystem with the given keystore and config,
/// which creates a DB at the given path. This function will delete the directory
/// at the given path if it already exists.
pub fn with_config(
config: Config,
keystore: Arc<LocalKeystore>,
metrics: Metrics,
) -> std::io::Result<Self> {
const DEFAULT_CACHE_SIZE: usize = 100 * 1024 * 1024; // 100MiB default should be fine unless finality stalls.
......@@ -115,6 +182,7 @@ impl ApprovalVotingSubsystem {
keystore,
slot_duration_millis: config.slot_duration_millis,
db,
metrics,
})
}
}
......@@ -343,6 +411,7 @@ async fn run<C>(
handle_from_overseer(
&mut ctx,
&mut state,
&subsystem.metrics,
db_writer,
next_msg?,
&mut last_finalized_height,
......@@ -353,6 +422,7 @@ async fn run<C>(
handle_background_request(
&mut ctx,
&mut state,
&subsystem.metrics,
req,
).await?
} else {
......@@ -363,6 +433,7 @@ async fn run<C>(
if handle_actions(
&mut ctx,
&subsystem.metrics,
&mut wakeups,
db_writer,
&background_tx,
......@@ -378,6 +449,7 @@ async fn run<C>(
// returns `true` if any of the actions was a `Conclude` command.
async fn handle_actions(
ctx: &mut impl SubsystemContext,
metrics: &Metrics,
wakeups: &mut Wakeups,
db: &dyn KeyValueDB,
background_tx: &mpsc::Sender<BackgroundRequest>,
......@@ -406,6 +478,7 @@ async fn handle_actions(
candidate,
backing_group,
} => {
metrics.on_assignment_produced();
let block_hash = indirect_cert.block_hash;
let validator_index = indirect_cert.validator;
......@@ -439,6 +512,7 @@ async fn handle_actions(
async fn handle_from_overseer(
ctx: &mut impl SubsystemContext,
state: &mut State<impl DBReader>,
metrics: &Metrics,
db_writer: &dyn KeyValueDB,
x: FromOverseer<ApprovalVotingMessage>,
last_finalized_height: &mut Option<BlockNumber>,
......@@ -468,6 +542,8 @@ async fn handle_from_overseer(
);
for (c_hash, c_entry) in block_batch.imported_candidates {
metrics.on_candidate_imported();
let our_tranche = c_entry
.approval_entry(&block_batch.block_hash)
.and_then(|a| a.our_assignment().map(|a| a.tranche()));
......@@ -542,11 +618,12 @@ async fn handle_from_overseer(
async fn handle_background_request(
ctx: &mut impl SubsystemContext,
state: &State<impl DBReader>,
metrics: &Metrics,
request: BackgroundRequest,
) -> SubsystemResult<Vec<Action>> {
match request {
BackgroundRequest::ApprovalVote(vote_request) => {
issue_approval(ctx, state, vote_request).await
issue_approval(ctx, state, metrics, vote_request).await
}
BackgroundRequest::CandidateValidation(
validation_data,
......@@ -1443,6 +1520,7 @@ async fn launch_approval(
async fn issue_approval(
ctx: &mut impl SubsystemContext,
state: &State<impl DBReader>,
metrics: &Metrics,
request: ApprovalVoteRequest,
) -> SubsystemResult<Vec<Action>> {
let ApprovalVoteRequest { validator_index, block_hash, candidate_index } = request;
......@@ -1541,6 +1619,8 @@ async fn issue_approval(
validator_index as _,
)?;
metrics.on_approval_produced();
// dispatch to approval distribution.
ctx.send_message(ApprovalDistributionMessage::DistributeApproval(IndirectSignedApprovalVote {
block_hash,
......
......@@ -21,7 +21,7 @@ use polkadot_node_primitives::approval::{
RELAY_VRF_MODULO_CONTEXT, DelayTranche,
};
use polkadot_node_subsystem_test_helpers::make_subsystem_context;
use polkadot_subsystem::messages::AllMessages;
use polkadot_node_subsystem::messages::AllMessages;
use sp_core::testing::TaskExecutor;
use parking_lot::Mutex;
......
......@@ -57,7 +57,7 @@ impl ApprovalCheckingDiagnostic {
Some(prometheus_endpoint::register(
prometheus_endpoint::Histogram::with_opts(
prometheus_endpoint::HistogramOpts::new(
"approval_checking_finality_lag",
"parachain_approval_checking_finality_lag",
"How far behind the head of the chain the Approval Checking protocol wants to vote",
).buckets(vec![1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 20.0, 30.0, 40.0, 50.0])
)?,
......
......@@ -497,6 +497,7 @@ where
approval_voting: ApprovalVotingSubsystem::with_config(
approval_voting_config,
keystore.clone(),
Metrics::register(registry)?,
)?,
gossip_support: GossipSupportSubsystem::new(),
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment