fuel_core_metrics/
config.rs

1use once_cell::sync::Lazy;
2use strum::IntoEnumIterator;
3use strum_macros::{
4    Display,
5    EnumIter,
6    EnumString,
7};
8
9#[derive(Debug, Display, Clone, Copy, PartialEq, EnumString, EnumIter)]
10#[strum(serialize_all = "lowercase")]
11pub enum Module {
12    All,
13    Importer,
14    P2P,
15    Producer,
16    TxPool,
17    GraphQL, // TODO[RC]: Not used... yet.
18    GasPrice,
19}
20
21/// Configuration for disabling metrics.
22pub trait DisableConfig {
23    /// Returns `true` if the given module is enabled.
24    fn is_enabled(&self, module: Module) -> bool;
25
26    /// Returns the list of enabled modules.
27    fn list_of_enabled(&self) -> Vec<Module>;
28}
29
30impl DisableConfig for Vec<Module> {
31    fn is_enabled(&self, module: Module) -> bool {
32        !self.contains(&module) && !self.contains(&Module::All)
33    }
34
35    fn list_of_enabled(&self) -> Vec<Module> {
36        Module::iter()
37            .filter(|module| self.is_enabled(*module) && *module != Module::All)
38            .collect()
39    }
40}
41
42static HELP_STRING: Lazy<String> = Lazy::new(|| {
43    let all_modules: Vec<_> = Module::iter().map(|module| module.to_string()).collect();
44    format!(
45        "Comma-separated list of modules or 'all' to disable all metrics. Available options: {}, all",
46        all_modules.join(", ")
47    )
48});
49
50pub fn help_string() -> &'static str {
51    &HELP_STRING
52}