forked from paritytech/polkadot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add node authority status metric (paritytech#4699)
* Check authority status on active leaves update Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * cargo changes Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Fix tests Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Add metric for authority status Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Revert "Fix tests" This reverts commit 5bd56bb. * Revert "cargo changes" This reverts commit ffea18f. * Revert "Check authority status on active leaves update" This reverts commit 55a30ac. * Test fixups Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fix Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * update Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * undo damage Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * dont update status on runtime errors Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Fix tests Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * fix inconsistency Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Review feedback Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * Dont derive primitive Default Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * add dummy_session_info helper Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * unset parachain validator status if no longer authority Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * update Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * damn Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> * 🤦 Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
- Loading branch information
Showing
4 changed files
with
196 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2021 Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use polkadot_node_subsystem_util::{ | ||
metrics, | ||
metrics::{ | ||
prometheus, | ||
prometheus::{Gauge, PrometheusError, Registry, U64}, | ||
}, | ||
}; | ||
|
||
/// Dispute Distribution metrics. | ||
#[derive(Clone, Default)] | ||
pub struct Metrics(Option<MetricsInner>); | ||
|
||
#[derive(Clone)] | ||
struct MetricsInner { | ||
/// Tracks authority status for producing relay chain blocks. | ||
is_authority: Gauge<U64>, | ||
/// Tracks authority status for parachain approval checking. | ||
is_parachain_validator: Gauge<U64>, | ||
} | ||
|
||
impl Metrics { | ||
/// Dummy constructor for testing. | ||
#[cfg(test)] | ||
pub fn new_dummy() -> Self { | ||
Self(None) | ||
} | ||
|
||
/// Set the `relaychain validator` metric. | ||
pub fn on_is_authority(&self) { | ||
if let Some(metrics) = &self.0 { | ||
metrics.is_authority.set(1); | ||
} | ||
} | ||
|
||
/// Unset the `relaychain validator` metric. | ||
pub fn on_is_not_authority(&self) { | ||
if let Some(metrics) = &self.0 { | ||
metrics.is_authority.set(0); | ||
} | ||
} | ||
|
||
/// Set the `parachain validator` metric. | ||
pub fn on_is_parachain_validator(&self) { | ||
if let Some(metrics) = &self.0 { | ||
metrics.is_parachain_validator.set(1); | ||
} | ||
} | ||
|
||
/// Unset the `parachain validator` metric. | ||
pub fn on_is_not_parachain_validator(&self) { | ||
if let Some(metrics) = &self.0 { | ||
metrics.is_parachain_validator.set(0); | ||
} | ||
} | ||
} | ||
|
||
impl metrics::Metrics for Metrics { | ||
fn try_register(registry: &Registry) -> Result<Self, PrometheusError> { | ||
let metrics = MetricsInner { | ||
is_authority: prometheus::register( | ||
Gauge::new("polkadot_node_is_authority", "Tracks the node authority status across sessions. \ | ||
An authority is any node that is a potential block producer in a session.")?, | ||
registry, | ||
)?, | ||
is_parachain_validator: prometheus::register( | ||
Gauge::new("polkadot_node_is_parachain_validator", | ||
"Tracks the node parachain validator status across sessions. Parachain validators are a \ | ||
subset of authorities that perform approval checking of all parachain candidates in a session.")?, | ||
registry, | ||
)?, | ||
}; | ||
Ok(Metrics(Some(metrics))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters