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
Show all changes
40 commits
Select commit Hold shift + click to select a range
993e5f6
adding unleash to ci (#5020)
gnunicorn Feb 25, 2020
a64dd52
Fix: CI failing for some CLI tests (#5043)
cecton Feb 25, 2020
ab8da74
aura: remove unused tx pool (#5046)
andresilva Feb 25, 2020
b874cb2
Extend rust nightly detection in `wasm-builder` (#5021)
bkchr Feb 25, 2020
063c0c3
Add steps setting to benchmarking CLI (#5033)
seerscode Feb 25, 2020
71d10b4
Remove indices from node-template (#5025)
shawntabrizi Feb 25, 2020
88b03c9
Fix documentation for "BlockBuilder::push_trusted" (#5051)
NikVolf Feb 25, 2020
504478a
do not check unleash on every PR, only master and tags (#5054)
gnunicorn Feb 25, 2020
7c75157
prepare version to alpha.1 (#5055)
gnunicorn Feb 25, 2020
48150f2
Sync: validate block responses for required data (#5052)
arkpar Feb 25, 2020
7fff6cb
Make these chainspecs fields private (#5031)
tomaka Feb 26, 2020
78224bd
Fix dockerfile (#5059)
chevdor Feb 26, 2020
4d61dc7
Adds documentation for `wipe` and `commit` (#5053)
bkchr Feb 26, 2020
bad1280
Fix the issue with `trybuild`'s `ui` tests (#4992)
TriplEight Feb 26, 2020
0f4f9d7
Activate publishing of draft releases... (#5062)
s3krit Feb 26, 2020
5b41575
Fix/div by zero (#5041)
cowboy-bebug Feb 26, 2020
2afecf8
set missing metadata fields, prepping alpha.2 (#5067)
gnunicorn Feb 26, 2020
d81f60e
Fix revalidation not revalidating multiple times (#5065)
NikVolf Feb 27, 2020
6e6d06c
removes use of sc_client::Client from sc_finality_grandpa (#5030)
seunlanlege Feb 27, 2020
06fae63
Remove deprecated host functions (#5038)
bkchr Feb 27, 2020
8c22368
removes use of sc_client::Client from sc_basic_authorship (#5050)
seunlanlege Feb 27, 2020
850ffec
pallet-transaction-payment clean up (#5070)
pepyakin Feb 27, 2020
e769ac4
*: Rename prometheus-exporter crate to substrate-prometheus-end… (#5076)
mxinden Feb 27, 2020
f41677d
rename `browser-utils` to `substrate-browser-utils` (#5079)
expenses Feb 27, 2020
013c1ee
prepping for Alpha.3 (#5080)
gnunicorn Feb 27, 2020
6653f4b
Propagate DispatchError for benchmarks. (#5075)
seerscode Feb 28, 2020
6b27391
Add options to overwrite range bounds in benchmark command. (#5072)
seerscode Feb 28, 2020
b5ec7d4
Update yamux to version 0.4.4. (#5086)
twittner Feb 28, 2020
29cee59
Remove more instances of futures01 (#4633)
expenses Feb 28, 2020
3beb09d
Make export blocks default to json on stdout (#5090)
pscott Mar 2, 2020
675f6b0
Offence reporting returns a result (#5082)
montekki Mar 2, 2020
1808b93
Update to libp2p 0.16.2 (#5088)
tomaka Mar 2, 2020
65ad8e9
Remove request ID from the new protocol (#5049)
tomaka Mar 2, 2020
7e383ed
Make sure we remove a peer on disconnect in gossip (#5104)
bkchr Mar 2, 2020
9fb3a7f
Expose `state-db` memory info (#5110)
bkchr Mar 3, 2020
798390f
Change extrinsic_count to extrinsic_index in pallet-utility (#5044)
joepetrowski Mar 3, 2020
a201f34
Add more metrics to prometheus (#5034)
expenses Mar 3, 2020
870540b
Update to SCALE 1.2.0 (#5113)
bkchr Mar 3, 2020
75116bd
Lazy payouts (#4474)
gavofyork Mar 3, 2020
01aebec
impl on_runtime_upgrade
gui1117 Mar 3, 2020
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
Add more metrics to prometheus (#5034)
* Add a few things

* Add finality_grandpa_round

* fix fg tests

* Nitpicks

* Nitpicks

* Fix name of prometheus crate
  • Loading branch information
expenses authored Mar 3, 2020
commit a201f34963dbd6fb7a266a5d6f0b5660ca0db34b
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub fn new_full(config: Configuration<GenesisConfig>)
on_exit: service.on_exit(),
telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
voting_rule: grandpa::VotingRulesBuilder::default().build(),
prometheus_registry: service.prometheus_registry()
};

// the GRANDPA voter task is considered infallible, i.e.
Expand Down
1 change: 1 addition & 0 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ macro_rules! new_full {
on_exit: service.on_exit(),
telemetry_on_connect: Some(service.telemetry_on_connect_stream()),
voting_rule: grandpa::VotingRulesBuilder::default().build(),
prometheus_registry: service.prometheus_registry(),
};

// the GRANDPA voter task is considered infallible, i.e.
Expand Down
1 change: 1 addition & 0 deletions client/finality-grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 31 additions & 0 deletions client/finality-grandpa/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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>,
Expand All @@ -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>,
}

Expand All @@ -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(())
})
Expand Down
12 changes: 11 additions & 1 deletion client/finality-grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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(&registry)
.expect("Other metrics would have failed to register before these; qed")
}),
_phantom: PhantomData,
});

Expand Down Expand Up @@ -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,
});

Expand Down
6 changes: 6 additions & 0 deletions client/finality-grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -1642,6 +1647,7 @@ fn grandpa_environment_respects_voting_rules() {
voters: Arc::new(authority_set.current_authorities()),
network,
voting_rule,
metrics: None,
_phantom: PhantomData,
}
};
Expand Down
1 change: 1 addition & 0 deletions client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sp-consensus = { version = "0.8.0-alpha.2", path = "../../primitives/consensus/c
sp-consensus-babe = { version = "0.8.0-alpha.2", path = "../../primitives/consensus/babe" }
sp-core = { version = "2.0.0-alpha.2", path = "../../primitives/core" }
sp-runtime = { version = "2.0.0-alpha.2", path = "../../primitives/runtime" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.8.0-alpha.2", path = "../../utils/prometheus" }
thiserror = "1"
unsigned-varint = { version = "0.3.1", features = ["futures", "futures-codec"] }
void = "1.0.2"
Expand Down
4 changes: 4 additions & 0 deletions client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use core::{fmt, iter};
use std::{future::Future, pin::Pin};
use std::{error::Error, fs, io::{self, Write}, net::Ipv4Addr, path::{Path, PathBuf}, sync::Arc};
use zeroize::Zeroize;
use prometheus_endpoint::Registry;

/// Network initialization parameters.
pub struct Params<B: BlockT, H: ExHashT> {
Expand Down Expand Up @@ -90,6 +91,9 @@ pub struct Params<B: BlockT, H: ExHashT> {

/// Type to check incoming block announcements.
pub block_announce_validator: Box<dyn BlockAnnounceValidator<B> + Send>,

/// Registry for recording prometheus metrics to.
pub metrics_registry: Option<Registry>,
}

bitflags! {
Expand Down
3 changes: 3 additions & 0 deletions client/network/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub enum Error {
/// The second peer id that was found for the bootnode.
second_id: PeerId,
},
/// Prometheus metrics error.
Prometheus(prometheus_endpoint::PrometheusError)
}

// Make `Debug` use the `Display` implementation.
Expand All @@ -60,6 +62,7 @@ impl std::error::Error for Error {
Error::Io(ref err) => Some(err),
Error::Client(ref err) => Some(err),
Error::DuplicateBootnode { .. } => None,
Error::Prometheus(ref err) => Some(err),
}
}
}
41 changes: 38 additions & 3 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use libp2p::swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent};
use parking_lot::Mutex;
use sc_peerset::PeersetHandle;
use sp_runtime::{traits::{Block as BlockT, NumberFor}, ConsensusEngineId};
use prometheus_endpoint::{Registry, Gauge, U64, register, PrometheusError};

use crate::{behaviour::{Behaviour, BehaviourOut}, config::{parse_str_addr, parse_addr}};
use crate::{transport, config::NonReservedPeerMode, ReputationChange};
Expand Down Expand Up @@ -294,6 +295,10 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
from_worker,
light_client_rqs: params.on_demand.and_then(|od| od.extract_receiver()),
event_streams: Vec::new(),
metrics: match params.metrics_registry {
Some(registry) => Some(Metrics::register(&registry)?),
None => None
}
})
}

Expand Down Expand Up @@ -727,6 +732,26 @@ pub struct NetworkWorker<B: BlockT + 'static, H: ExHashT> {
light_client_rqs: Option<mpsc::UnboundedReceiver<RequestData<B>>>,
/// Senders for events that happen on the network.
event_streams: Vec<mpsc::UnboundedSender<Event>>,
/// Prometheus network metrics.
metrics: Option<Metrics>
}

struct Metrics {
is_major_syncing: Gauge<U64>,
peers_count: Gauge<U64>,
}

impl Metrics {
fn register(registry: &Registry) -> Result<Self, PrometheusError> {
Ok(Self {
is_major_syncing: register(Gauge::new(
"is_major_syncing", "Whether the node is performing a major sync or not.",
)?, registry)?,
peers_count: register(Gauge::new(
"peers_count", "Number of network gossip peers",
)?, registry)?,
})
}
}

impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
Expand Down Expand Up @@ -818,16 +843,26 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
};
}

let num_connected_peers = this.network_service.user_protocol_mut().num_connected_peers();

// Update the variables shared with the `NetworkService`.
this.num_connected.store(this.network_service.user_protocol_mut().num_connected_peers(), Ordering::Relaxed);
this.num_connected.store(num_connected_peers, Ordering::Relaxed);
{
let external_addresses = Swarm::<B, H>::external_addresses(&this.network_service).cloned().collect();
*this.external_addresses.lock() = external_addresses;
}
this.is_major_syncing.store(match this.network_service.user_protocol_mut().sync_state() {

let is_major_syncing = match this.network_service.user_protocol_mut().sync_state() {
SyncState::Idle => false,
SyncState::Downloading => true,
}, Ordering::Relaxed);
};

this.is_major_syncing.store(is_major_syncing, Ordering::Relaxed);

if let Some(metrics) = this.metrics.as_ref() {
metrics.is_major_syncing.set(is_major_syncing as u64);
metrics.peers_count.set(num_connected_peers as u64);
}

Poll::Pending
}
Expand Down
6 changes: 4 additions & 2 deletions client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,8 @@ pub trait TestNetFactory: Sized {
transaction_pool: Arc::new(EmptyTransactionPool),
protocol_id: ProtocolId::from(&b"test-protocol-name"[..]),
import_queue,
block_announce_validator: Box::new(DefaultBlockAnnounceValidator::new(client.clone()))
block_announce_validator: Box::new(DefaultBlockAnnounceValidator::new(client.clone())),
metrics_registry: None,
}).unwrap();

self.mut_peers(|peers| {
Expand Down Expand Up @@ -713,7 +714,8 @@ pub trait TestNetFactory: Sized {
transaction_pool: Arc::new(EmptyTransactionPool),
protocol_id: ProtocolId::from(&b"test-protocol-name"[..]),
import_queue,
block_announce_validator: Box::new(DefaultBlockAnnounceValidator::new(client.clone()))
block_announce_validator: Box::new(DefaultBlockAnnounceValidator::new(client.clone())),
metrics_registry: None,
}).unwrap();

self.mut_peers(|peers| {
Expand Down
2 changes: 1 addition & 1 deletion client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sc-rpc = { version = "2.0.0-alpha.2", path = "../rpc" }
sc-telemetry = { version = "2.0.0-alpha.2", path = "../telemetry" }
sc-offchain = { version = "2.0.0-alpha.2", path = "../offchain" }
parity-multiaddr = { package = "parity-multiaddr", version = "0.5.0" }
substrate-prometheus-endpoint = { path = "../../utils/prometheus" , version = "0.8.0-alpha.2"}
prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../utils/prometheus" , version = "0.8.0-alpha.2"}
sc-tracing = { version = "2.0.0-alpha.2", path = "../tracing" }
tracing = "0.1.10"
parity-util-mem = { version = "0.5.1", default-features = false, features = ["primitive-types"] }
Expand Down
Loading