Add Prometheus timers to the subsystems (#1923)

* reexport prometheus-super for ease of use of other subsystems

* add some prometheus timers for collation generation subsystem

* add timing metrics to av-store

* add metrics to candidate backing

* add timing metric to bitfield signing

* add timing metrics to candidate selection

* add timing metrics to candidate-validation

* add timing metrics to chain-api

* add timing metrics to provisioner

* add timing metrics to runtime-api

* add timing metrics to availability-distribution

* add timing metrics to bitfield-distribution

* add timing metrics to collator protocol: collator side

* add timing metrics to collator protocol: validator side

* fix candidate validation test failures

* add timing metrics to pov distribution

* add timing metrics to statement-distribution

* use substrate_prometheus_endpoint prometheus reexport instead of prometheus_super

* don't include JOB_DELAY in bitfield-signing metrics

* give adder-collator ability to easily export its genesis-state and validation code

* wip: adder-collator pushbutton script

* don't attempt to register the adder-collator automatically

Instead, get these values with

```sh
target/release/adder-collator export-genesis-state
target/release/adder-collator export-genesis-wasm
```

And then register the parachain on https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer

To collect prometheus data, after running the script, create `prometheus.yml` per the instructions
at https://www.notion.so/paritytechnologies/Setting-up-Prometheus-locally-835cb3a9df7541a781c381006252b5ff
and then run:

```sh
docker run -v `pwd`/prometheus.yml:/etc/prometheus/prometheus.yml:z --network host prom/prometheus
```

Demonstrates that data makes it across to prometheus, though it is likely to be useful in the future
to tweak the buckets.

* Update parachain/test-parachains/adder/collator/src/cli.rs

Co-authored-by: Andronik Ordian <write@reusable.software>

* use the grandpa-pause parameter

* skip metrics in tracing instrumentation

* remove unnecessary grandpa_pause cli param

Co-authored-by: Andronik Ordian <write@reusable.software>
This commit is contained in:
Peter Goodspeed-Niklaus
2020-11-20 15:04:51 +01:00
committed by GitHub
parent e49989971d
commit 0a5bc82529
23 changed files with 1199 additions and 87 deletions
@@ -125,6 +125,8 @@ async fn handle_signal(
match signal {
OverseerSignal::Conclude => Ok(true),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { activated, deactivated }) => {
let _timer = state.metrics.time_handle_signal();
for relay_parent in activated {
let (vals_tx, vals_rx) = oneshot::channel();
ctx.send_message(AllMessages::RuntimeApi(RuntimeApiMessage::Request(
@@ -267,6 +269,8 @@ async fn handle_fetch(
descriptor: CandidateDescriptor,
response_sender: oneshot::Sender<Arc<PoV>>,
) -> SubsystemResult<()> {
let _timer = state.metrics.time_handle_fetch();
let relay_parent_state = match state.relay_parent_state.get_mut(&relay_parent) {
Some(s) => s,
None => return Ok(()),
@@ -316,6 +320,8 @@ async fn handle_distribute(
descriptor: CandidateDescriptor,
pov: Arc<PoV>,
) -> SubsystemResult<()> {
let _timer = state.metrics.time_handle_distribute();
let relay_parent_state = match state.relay_parent_state.get_mut(&relay_parent) {
None => return Ok(()),
Some(s) => s,
@@ -483,6 +489,8 @@ async fn handle_network_update(
ctx: &mut impl SubsystemContext<Message = PoVDistributionMessage>,
update: NetworkBridgeEvent<protocol_v1::PoVDistributionMessage>,
) -> SubsystemResult<()> {
let _timer = state.metrics.time_handle_network_update();
match update {
NetworkBridgeEvent::PeerConnected(peer, _observed_role) => {
state.peer_state.insert(peer, PeerState { awaited: HashMap::new() });
@@ -600,6 +608,10 @@ impl PoVDistribution {
#[derive(Clone)]
struct MetricsInner {
povs_distributed: prometheus::Counter<prometheus::U64>,
handle_signal: prometheus::Histogram,
handle_fetch: prometheus::Histogram,
handle_distribute: prometheus::Histogram,
handle_network_update: prometheus::Histogram,
}
/// Availability Distribution metrics.
@@ -612,6 +624,26 @@ impl Metrics {
metrics.povs_distributed.inc();
}
}
/// Provide a timer for `handle_signal` which observes on drop.
fn time_handle_signal(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
self.0.as_ref().map(|metrics| metrics.handle_signal.start_timer())
}
/// Provide a timer for `handle_fetch` which observes on drop.
fn time_handle_fetch(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
self.0.as_ref().map(|metrics| metrics.handle_fetch.start_timer())
}
/// Provide a timer for `handle_distribute` which observes on drop.
fn time_handle_distribute(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
self.0.as_ref().map(|metrics| metrics.handle_distribute.start_timer())
}
/// Provide a timer for `handle_network_update` which observes on drop.
fn time_handle_network_update(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
self.0.as_ref().map(|metrics| metrics.handle_network_update.start_timer())
}
}
impl metrics::Metrics for Metrics {
@@ -624,6 +656,42 @@ impl metrics::Metrics for Metrics {
)?,
registry,
)?,
handle_signal: prometheus::register(
prometheus::Histogram::with_opts(
prometheus::HistogramOpts::new(
"parachain_pov_distribution_handle_signal",
"Time spent within `pov_distribution::handle_signal`",
)
)?,
registry,
)?,
handle_fetch: prometheus::register(
prometheus::Histogram::with_opts(
prometheus::HistogramOpts::new(
"parachain_pov_distribution_handle_fetch",
"Time spent within `pov_distribution::handle_fetch`",
)
)?,
registry,
)?,
handle_distribute: prometheus::register(
prometheus::Histogram::with_opts(
prometheus::HistogramOpts::new(
"parachain_pov_distribution_handle_distribute",
"Time spent within `pov_distribution::handle_distribute`",
)
)?,
registry,
)?,
handle_network_update: prometheus::register(
prometheus::Histogram::with_opts(
prometheus::HistogramOpts::new(
"parachain_pov_distribution_handle_network_update",
"Time spent within `pov_distribution::handle_network_update`",
)
)?,
registry,
)?,
};
Ok(Metrics(Some(metrics)))
}