-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #807 ## Description This PR adds a couple of additional metrics (block importer and p2p) and also contains slight refactor of how we initialize bucket sized for histogram based metrics. The `metrics` command-line parameter has been replaced with `disable-metrics`. Metrics are now enabled by default, with the option to disable them entirely or on a per-module basis. This change is _breaking_ for all dependencies that use CLI to setup the `fuel-core-client` ``` --disable-metrics <METRICS> Disables all metrics, or specify a comma-separated list of modules to disable metrics for specific ones. Available options: importer, p2p, producer, txpool, graphql [env: METRICS=] [default: ] ``` Startup logs also show the metrics config: ``` 2024-10-14T20:17:37.536840Z INFO fuel_core_bin::cli::run: 308: Metrics config: Disable modules: txpool ``` ## Checklist - [X] Breaking changes are clearly marked as such in the PR description and changelog - [X] New behavior is reflected in tests ### Before requesting review - [X] I have reviewed the code myself --------- Co-authored-by: acerone85 <[email protected]> Co-authored-by: rymnc <[email protected]> Co-authored-by: Green Baneling <[email protected]>
- Loading branch information
1 parent
87c9579
commit ada0e9e
Showing
18 changed files
with
437 additions
and
58 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use std::{ | ||
collections::HashMap, | ||
sync::OnceLock, | ||
}; | ||
#[cfg(test)] | ||
use strum_macros::EnumIter; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||
#[cfg_attr(test, derive(EnumIter))] | ||
pub(crate) enum Buckets { | ||
Timing, | ||
} | ||
static BUCKETS: OnceLock<HashMap<Buckets, Vec<f64>>> = OnceLock::new(); | ||
pub(crate) fn buckets(b: Buckets) -> impl Iterator<Item = f64> { | ||
BUCKETS.get_or_init(initialize_buckets)[&b].iter().copied() | ||
} | ||
|
||
#[rustfmt::skip] | ||
fn initialize_buckets() -> HashMap<Buckets, Vec<f64>> { | ||
[ | ||
( | ||
Buckets::Timing, | ||
vec![ | ||
0.005, | ||
0.010, | ||
0.025, | ||
0.050, | ||
0.100, | ||
0.250, | ||
0.500, | ||
1.000, | ||
2.500, | ||
5.000, | ||
10.000, | ||
], | ||
), | ||
] | ||
.into_iter() | ||
.collect() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use strum::IntoEnumIterator; | ||
|
||
use crate::buckets::Buckets; | ||
|
||
use super::initialize_buckets; | ||
|
||
#[test] | ||
fn buckets_are_defined_for_every_variant() { | ||
let actual_buckets = initialize_buckets(); | ||
let actual_buckets = actual_buckets.keys().collect::<Vec<_>>(); | ||
|
||
let required_buckets: Vec<_> = Buckets::iter().collect(); | ||
|
||
assert_eq!(required_buckets.len(), actual_buckets.len()); | ||
|
||
let all_buckets_defined = required_buckets | ||
.iter() | ||
.all(|required_bucket| actual_buckets.contains(&required_bucket)); | ||
|
||
assert!(all_buckets_defined) | ||
} | ||
} |
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,51 @@ | ||
use once_cell::sync::Lazy; | ||
use strum::IntoEnumIterator; | ||
use strum_macros::{ | ||
Display, | ||
EnumIter, | ||
EnumString, | ||
}; | ||
|
||
#[derive(Debug, Display, Clone, Copy, PartialEq, EnumString, EnumIter)] | ||
#[strum(serialize_all = "lowercase")] | ||
pub enum Module { | ||
All, | ||
Importer, | ||
P2P, | ||
Producer, | ||
TxPool, /* TODO[RC]: Not used. Add support in https://github.com/FuelLabs/fuel-core/pull/2321 */ | ||
GraphQL, // TODO[RC]: Not used... yet. | ||
} | ||
|
||
/// Configuration for disabling metrics. | ||
pub trait DisableConfig { | ||
/// Returns `true` if the given module is enabled. | ||
fn is_enabled(&self, module: Module) -> bool; | ||
|
||
/// Returns the list of enabled modules. | ||
fn list_of_enabled(&self) -> Vec<Module>; | ||
} | ||
|
||
impl DisableConfig for Vec<Module> { | ||
fn is_enabled(&self, module: Module) -> bool { | ||
!self.contains(&module) && !self.contains(&Module::All) | ||
} | ||
|
||
fn list_of_enabled(&self) -> Vec<Module> { | ||
Module::iter() | ||
.filter(|module| self.is_enabled(*module) && *module != Module::All) | ||
.collect() | ||
} | ||
} | ||
|
||
static HELP_STRING: Lazy<String> = Lazy::new(|| { | ||
let all_modules: Vec<_> = Module::iter().map(|module| module.to_string()).collect(); | ||
format!( | ||
"Comma-separated list of modules or 'all' to disable all metrics. Available options: {}, all", | ||
all_modules.join(", ") | ||
) | ||
}); | ||
|
||
pub fn help_string() -> &'static str { | ||
&HELP_STRING | ||
} |
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
Oops, something went wrong.