Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
some beefy metrics
  • Loading branch information
dharjeezy committed Dec 13, 2022
commit f7e48e99dd4ee646129386c2faef3e05fa76591f
10 changes: 9 additions & 1 deletion client/beefy/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use sc_consensus::{BlockCheckParams, BlockImport, BlockImportParams, ImportResul
use crate::{
communication::notification::BeefyVersionedFinalityProofSender,
justification::{decode_and_verify_finality_proof, BeefyVersionedFinalityProof},
metric_inc, metric_set,
metrics::Metrics,
};

/// A block-import handler for BEEFY.
Expand All @@ -48,6 +50,7 @@ pub struct BeefyBlockImport<Block: BlockT, Backend, RuntimeApi, I> {
runtime: Arc<RuntimeApi>,
inner: I,
justification_sender: BeefyVersionedFinalityProofSender<Block>,
metrics: Option<Metrics>,
}

impl<Block: BlockT, BE, Runtime, I: Clone> Clone for BeefyBlockImport<Block, BE, Runtime, I> {
Expand All @@ -57,6 +60,7 @@ impl<Block: BlockT, BE, Runtime, I: Clone> Clone for BeefyBlockImport<Block, BE,
runtime: self.runtime.clone(),
inner: self.inner.clone(),
justification_sender: self.justification_sender.clone(),
metrics: self.metrics.clone(),
}
}
}
Expand All @@ -68,8 +72,9 @@ impl<Block: BlockT, BE, Runtime, I> BeefyBlockImport<Block, BE, Runtime, I> {
runtime: Arc<Runtime>,
inner: I,
justification_sender: BeefyVersionedFinalityProofSender<Block>,
metrics: Option<Metrics>,
) -> BeefyBlockImport<Block, BE, Runtime, I> {
BeefyBlockImport { backend, runtime, inner, justification_sender }
BeefyBlockImport { backend, runtime, inner, justification_sender, metrics }
}
}

Expand Down Expand Up @@ -143,12 +148,15 @@ where
self.justification_sender
.notify(|| Ok::<_, ()>(proof))
.expect("forwards closure result; the closure always returns Ok; qed.");

metric_set!(self, beefy_good_justification_imports, number);
} else {
debug!(
target: "beefy",
"🥩 error decoding justification: {:?} for imported block {:?}",
encoded, number,
);
metric_set!(self, beefy_bad_justification_imports, number);
}
},
_ => (),
Expand Down
24 changes: 22 additions & 2 deletions client/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub fn beefy_block_import_and_links<B, BE, RuntimeApi, I>(
wrapped_block_import: I,
backend: Arc<BE>,
runtime: Arc<RuntimeApi>,
prometheus_registry: Option<Registry>,
) -> (BeefyBlockImport<B, BE, RuntimeApi, I>, BeefyVoterLinks<B>, BeefyRPCLinks<B>)
where
B: Block,
Expand All @@ -151,9 +152,28 @@ where
let (to_voter_justif_sender, from_block_import_justif_stream) =
BeefyVersionedFinalityProofStream::<B>::channel();

let metrics =
prometheus_registry.as_ref().map(metrics::Metrics::register).and_then(
|result| match result {
Ok(metrics) => {
debug!(target: "beefy", "🥩 Registered metrics");
Some(metrics)
},
Err(err) => {
debug!(target: "beefy", "🥩 Failed to register metrics: {:?}", err);
None
},
},
);

// BlockImport
let import =
BeefyBlockImport::new(backend, runtime, wrapped_block_import, to_voter_justif_sender);
let import = BeefyBlockImport::new(
backend,
runtime,
wrapped_block_import,
to_voter_justif_sender,
metrics,
);
let voter_links = BeefyVoterLinks {
from_block_import_justif_stream,
to_rpc_justif_sender,
Expand Down
36 changes: 35 additions & 1 deletion client/beefy/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

use prometheus::{register, Counter, Gauge, PrometheusError, Registry, U64};
/// BEEFY metrics exposed through Prometheus
pub(crate) struct Metrics {
#[derive(Clone)]
pub struct Metrics {
/// Current active validator set id
pub beefy_validator_set_id: Gauge<U64>,
/// Total number of votes sent by this node
Expand All @@ -47,6 +48,14 @@ pub(crate) struct Metrics {
pub beefy_buffered_justifications_full: Counter<U64>,
/// Trying to set Best Beefy block to old block
pub beefy_best_block_to_old_block: Gauge<U64>,
/// Number of Successful handled votes
pub beefy_successful_handled_votes: Counter<U64>,
/// Number of Successful votes
pub beefy_successful_votes: Counter<U64>,
/// Number of Bad Justification imports
pub beefy_bad_justification_imports: Gauge<U64>,
/// Number of Good Justification imports
pub beefy_good_justification_imports: Gauge<U64>,
}

impl Metrics {
Expand Down Expand Up @@ -131,6 +140,31 @@ impl Metrics {
)?,
registry,
)?,
beefy_successful_handled_votes: register(
Counter::new(
"substrate_beefy_successful_handled_votes",
"Number of Successful handled votes",
)?,
registry,
)?,
beefy_successful_votes: register(
Counter::new("substrate_beefy_successful_votes", "Number of Successful votes")?,
registry,
)?,
beefy_bad_justification_imports: register(
Gauge::new(
"substrate_beefy_bad_justification_imports",
"Number of Bad Justification imports",
)?,
registry,
)?,
beefy_good_justification_imports: register(
Gauge::new(
"substrate_beefy_good_justification_imports",
"Number of Good Justification imports",
)?,
registry,
)?,
})
}
}
Expand Down
3 changes: 3 additions & 0 deletions client/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ where
}
}
}
metric_inc!(self, beefy_successful_handled_votes);
Ok(())
}

Expand Down Expand Up @@ -799,6 +800,8 @@ where

self.gossip_engine.gossip_message(topic::<B>(), encoded_message, false);

metric_inc!(self, beefy_successful_votes);

Ok(())
}

Expand Down