use crate::bootstrap::metrics_bootstrap;
#[cfg(test)]
use crate::bootstrap::{install_bootstrap_config, BootstrapConfig, MetricsBootstrap};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DefaultMetricsConfig {
pub enabled: bool,
}
impl Default for DefaultMetricsConfig {
fn default() -> Self {
Self {
enabled: metrics_bootstrap().enabled,
}
}
}
impl DefaultMetricsConfig {
pub fn new() -> Self {
Self::default()
}
pub fn disabled() -> Self {
Self { enabled: false }
}
pub fn is_enabled(&self) -> bool {
self.enabled
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::bootstrap::bootstrap_test_lock;
#[test]
fn test_default_config() {
let _lock = bootstrap_test_lock();
let _guard = install_bootstrap_config(BootstrapConfig::default());
let config = DefaultMetricsConfig::default();
assert!(config.enabled);
}
#[test]
fn test_disabled_config() {
let config = DefaultMetricsConfig::disabled();
assert!(!config.enabled);
}
#[test]
fn test_bootstrap_override() {
let _lock = bootstrap_test_lock();
let _guard = install_bootstrap_config(BootstrapConfig {
metrics: MetricsBootstrap {
enabled: false,
..MetricsBootstrap::default()
},
..BootstrapConfig::default()
});
let config = DefaultMetricsConfig::default();
assert!(!config.enabled);
}
}