-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A0-3015: Finality rate metrics (#1521)
# Description Introduce `FinalityRateMetrics` - they measure the number of own finalized blocks and the number of own hopeless blocks (our blocks which are forking the finalized chain). ### Implementation details: The interface consists of `{ report_own_imported, report_finalized }`. `report_own_imported` is called when own block is imported and is added to internal storage of `FinalityRateMetrics` object. `report_finalized` is called when **any** finalized block appears and: * if it is own block, it should have been added to internal storage when reporting import - we count it as **own finalized** * all blocks which are on the same level as the given newly finalized block are removed from storage, and if they are not the given block, they are counted as **own hopeless**. ## Type of change - New feature (non-breaking change which adds functionality) # Checklist: <!-- delete when not applicable to your PR --> - I have added tests - I have made neccessary updates to the Infrastructure - I have made corresponding changes to the existing documentation - I have created new documentation
- Loading branch information
Showing
14 changed files
with
289 additions
and
54 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
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
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
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
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 |
---|---|---|
@@ -1,21 +1,53 @@ | ||
use primitives::BlockHash; | ||
use log::warn; | ||
use substrate_prometheus_endpoint::Registry; | ||
|
||
use super::{timing::DefaultClock, Checkpoint}; | ||
use crate::TimingBlockMetrics; | ||
use super::{finality_rate::FinalityRateMetrics, timing::DefaultClock, Checkpoint}; | ||
use crate::{metrics::LOG_TARGET, BlockId, TimingBlockMetrics}; | ||
|
||
/// Wrapper around various block-related metrics. | ||
#[derive(Clone)] | ||
pub struct AllBlockMetrics { | ||
timing_metrics: TimingBlockMetrics<DefaultClock>, | ||
finality_rate_metrics: FinalityRateMetrics, | ||
} | ||
|
||
impl AllBlockMetrics { | ||
pub fn new(timing_metrics: TimingBlockMetrics<DefaultClock>) -> Self { | ||
AllBlockMetrics { timing_metrics } | ||
pub fn new(registry: Option<&Registry>) -> Self { | ||
let timing_metrics = match TimingBlockMetrics::new(registry, DefaultClock) { | ||
Ok(timing_metrics) => timing_metrics, | ||
Err(e) => { | ||
warn!( | ||
target: LOG_TARGET, | ||
"Failed to register Prometheus block timing metrics: {:?}.", e | ||
); | ||
TimingBlockMetrics::Noop | ||
} | ||
}; | ||
let finality_rate_metrics = match FinalityRateMetrics::new(registry) { | ||
Ok(finality_rate_metrics) => finality_rate_metrics, | ||
Err(e) => { | ||
warn!( | ||
target: LOG_TARGET, | ||
"Failed to register Prometheus finality rate metrics: {:?}.", e | ||
); | ||
FinalityRateMetrics::Noop | ||
} | ||
}; | ||
AllBlockMetrics { | ||
timing_metrics, | ||
finality_rate_metrics, | ||
} | ||
} | ||
|
||
/// Triggers all contained block metrics. | ||
pub fn report_block(&self, hash: BlockHash, checkpoint: Checkpoint) { | ||
self.timing_metrics.report_block(hash, checkpoint); | ||
pub fn report_block(&self, block_id: BlockId, checkpoint: Checkpoint, own: Option<bool>) { | ||
self.timing_metrics | ||
.report_block(block_id.hash(), checkpoint); | ||
self.finality_rate_metrics.report_block( | ||
block_id.hash(), | ||
block_id.number(), | ||
checkpoint, | ||
own, | ||
); | ||
} | ||
} |
Oops, something went wrong.