mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
Add more metrics to prometheus (#5034)
* Add a few things * Add finality_grandpa_round * fix fg tests * Nitpicks * Nitpicks * Fix name of prometheus crate
This commit is contained in:
@@ -35,6 +35,7 @@ sc-network = { version = "0.8.0-alpha.2", path = "../network" }
|
||||
sc-network-gossip = { version = "0.8.0-alpha.2", path = "../network-gossip" }
|
||||
sp-finality-tracker = { version = "2.0.0-alpha.2", path = "../../primitives/finality-tracker" }
|
||||
sp-finality-grandpa = { version = "2.0.0-alpha.2", path = "../../primitives/finality-grandpa" }
|
||||
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus", version = "0.8.0-alpha.2" }
|
||||
sc-block-builder = { version = "0.8.0-alpha.2", path = "../block-builder" }
|
||||
finality-grandpa = { version = "0.11.1", features = ["derive-codec"] }
|
||||
pin-project = "0.4.6"
|
||||
|
||||
@@ -58,6 +58,7 @@ use crate::justification::GrandpaJustification;
|
||||
use crate::until_imported::UntilVoteTargetImported;
|
||||
use crate::voting_rule::VotingRule;
|
||||
use sp_finality_grandpa::{AuthorityId, AuthoritySignature, SetId, RoundNumber};
|
||||
use prometheus_endpoint::{Gauge, U64, register, PrometheusError};
|
||||
|
||||
type HistoricalVotes<Block> = finality_grandpa::HistoricalVotes<
|
||||
<Block as BlockT>::Hash,
|
||||
@@ -372,6 +373,24 @@ impl<Block: BlockT> SharedVoterSetState<Block> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Prometheus metrics for GRANDPA.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct Metrics {
|
||||
finality_grandpa_round: Gauge<U64>,
|
||||
}
|
||||
|
||||
impl Metrics {
|
||||
pub(crate) fn register(registry: &prometheus_endpoint::Registry) -> Result<Self, PrometheusError> {
|
||||
Ok(Self {
|
||||
finality_grandpa_round: register(
|
||||
Gauge::new("finality_grandpa_round", "Highest completed GRANDPA round.")?,
|
||||
registry
|
||||
)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// The environment we run GRANDPA in.
|
||||
pub(crate) struct Environment<Backend, Block: BlockT, C, N: NetworkT<Block>, SC, VR> {
|
||||
pub(crate) client: Arc<C>,
|
||||
@@ -384,6 +403,7 @@ pub(crate) struct Environment<Backend, Block: BlockT, C, N: NetworkT<Block>, SC,
|
||||
pub(crate) set_id: SetId,
|
||||
pub(crate) voter_set_state: SharedVoterSetState<Block>,
|
||||
pub(crate) voting_rule: VR,
|
||||
pub(crate) metrics: Option<Metrics>,
|
||||
pub(crate) _phantom: PhantomData<Backend>,
|
||||
}
|
||||
|
||||
@@ -397,6 +417,17 @@ impl<Backend, Block: BlockT, C, N: NetworkT<Block>, SC, VR> Environment<Backend,
|
||||
self.voter_set_state.with(|voter_set_state| {
|
||||
if let Some(set_state) = f(&voter_set_state)? {
|
||||
*voter_set_state = set_state;
|
||||
|
||||
if let Some(metrics) = self.metrics.as_ref() {
|
||||
if let VoterSetState::Live { completed_rounds, .. } = voter_set_state {
|
||||
let highest = completed_rounds.rounds.iter()
|
||||
.map(|round| round.number)
|
||||
.max()
|
||||
.expect("There is always one completed round (genesis); qed");
|
||||
|
||||
metrics.finality_grandpa_round.set(highest);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
|
||||
@@ -104,7 +104,7 @@ pub use voting_rule::{
|
||||
};
|
||||
|
||||
use aux_schema::PersistentData;
|
||||
use environment::{Environment, VoterSetState};
|
||||
use environment::{Environment, VoterSetState, Metrics};
|
||||
use import::GrandpaBlockImport;
|
||||
use until_imported::UntilGlobalMessageBlocksImported;
|
||||
use communication::{NetworkBridge, Network as NetworkT};
|
||||
@@ -551,6 +551,8 @@ pub struct GrandpaParams<Block: BlockT, C, N, SC, VR, X> {
|
||||
pub telemetry_on_connect: Option<futures::channel::mpsc::UnboundedReceiver<()>>,
|
||||
/// A voting rule used to potentially restrict target votes.
|
||||
pub voting_rule: VR,
|
||||
/// The prometheus metrics registry.
|
||||
pub prometheus_registry: Option<prometheus_endpoint::Registry>,
|
||||
}
|
||||
|
||||
/// Run a GRANDPA voter as a task. Provide configuration and a link to a
|
||||
@@ -576,6 +578,7 @@ pub fn run_grandpa_voter<Block: BlockT, BE: 'static, C, N, SC, VR, X>(
|
||||
on_exit,
|
||||
telemetry_on_connect,
|
||||
voting_rule,
|
||||
prometheus_registry,
|
||||
} = grandpa_params;
|
||||
|
||||
// NOTE: we have recently removed `run_grandpa_observer` from the public
|
||||
@@ -634,6 +637,7 @@ pub fn run_grandpa_voter<Block: BlockT, BE: 'static, C, N, SC, VR, X>(
|
||||
voting_rule,
|
||||
persistent_data,
|
||||
voter_commands_rx,
|
||||
prometheus_registry,
|
||||
);
|
||||
|
||||
let voter_work = voter_work
|
||||
@@ -673,6 +677,7 @@ where
|
||||
voting_rule: VR,
|
||||
persistent_data: PersistentData<Block>,
|
||||
voter_commands_rx: mpsc::UnboundedReceiver<VoterCommand<Block::Hash, NumberFor<Block>>>,
|
||||
prometheus_registry: Option<prometheus_endpoint::Registry>,
|
||||
) -> Self {
|
||||
|
||||
let voters = persistent_data.authority_set.current_authorities();
|
||||
@@ -687,6 +692,10 @@ where
|
||||
authority_set: persistent_data.authority_set.clone(),
|
||||
consensus_changes: persistent_data.consensus_changes.clone(),
|
||||
voter_set_state: persistent_data.set_state.clone(),
|
||||
metrics: prometheus_registry.map(|registry| {
|
||||
Metrics::register(®istry)
|
||||
.expect("Other metrics would have failed to register before these; qed")
|
||||
}),
|
||||
_phantom: PhantomData,
|
||||
});
|
||||
|
||||
@@ -807,6 +816,7 @@ where
|
||||
consensus_changes: self.env.consensus_changes.clone(),
|
||||
network: self.env.network.clone(),
|
||||
voting_rule: self.env.voting_rule.clone(),
|
||||
metrics: self.env.metrics.clone(),
|
||||
_phantom: PhantomData,
|
||||
});
|
||||
|
||||
|
||||
@@ -447,6 +447,7 @@ fn run_to_completion_with<F>(
|
||||
on_exit: Exit,
|
||||
telemetry_on_connect: None,
|
||||
voting_rule: (),
|
||||
prometheus_registry: None,
|
||||
};
|
||||
let voter = run_grandpa_voter(grandpa_params).expect("all in order with client and network");
|
||||
|
||||
@@ -578,6 +579,7 @@ fn finalize_3_voters_1_full_observer() {
|
||||
on_exit: Exit,
|
||||
telemetry_on_connect: None,
|
||||
voting_rule: (),
|
||||
prometheus_registry: None,
|
||||
};
|
||||
|
||||
voters.push(run_grandpa_voter(grandpa_params).expect("all in order with client and network"));
|
||||
@@ -741,6 +743,7 @@ fn transition_3_voters_twice_1_full_observer() {
|
||||
on_exit: Exit,
|
||||
telemetry_on_connect: None,
|
||||
voting_rule: (),
|
||||
prometheus_registry: None,
|
||||
};
|
||||
let voter = run_grandpa_voter(grandpa_params).expect("all in order with client and network");
|
||||
|
||||
@@ -1166,6 +1169,7 @@ fn voter_persists_its_votes() {
|
||||
on_exit: Exit,
|
||||
telemetry_on_connect: None,
|
||||
voting_rule: VotingRulesBuilder::default().build(),
|
||||
prometheus_registry: None,
|
||||
};
|
||||
|
||||
let voter = run_grandpa_voter(grandpa_params)
|
||||
@@ -1511,6 +1515,7 @@ fn voter_catches_up_to_latest_round_when_behind() {
|
||||
on_exit: Exit,
|
||||
telemetry_on_connect: None,
|
||||
voting_rule: (),
|
||||
prometheus_registry: None,
|
||||
};
|
||||
|
||||
Box::pin(run_grandpa_voter(grandpa_params).expect("all in order with client and network"))
|
||||
@@ -1642,6 +1647,7 @@ fn grandpa_environment_respects_voting_rules() {
|
||||
voters: Arc::new(authority_set.current_authorities()),
|
||||
network,
|
||||
voting_rule,
|
||||
metrics: None,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user