From 0f82662a7f86c9595c15bb10d60c193b06c0cc80 Mon Sep 17 00:00:00 2001 From: Jeff Biseda Date: Wed, 11 Oct 2023 09:58:39 -0700 Subject: [PATCH] allow empty string for SOLANA_METRICS_CONFIG sanity checking (#33515) --- core/src/validator.rs | 9 +++++---- metrics/src/metrics.rs | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/validator.rs b/core/src/validator.rs index e5eb3544a..b206cf87b 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -561,6 +561,10 @@ impl Validator { )); } + let genesis_config = + open_genesis_config(ledger_path, config.max_genesis_archive_unpacked_size); + metrics_config_sanity_check(genesis_config.cluster_type)?; + if let Some(expected_shred_version) = config.expected_shred_version { if let Some(wait_for_supermajority_slot) = config.wait_for_supermajority { *start_progress.write().unwrap() = ValidatorStartProgress::CleaningBlockStore; @@ -1334,14 +1338,11 @@ impl Validator { config.generator_config.clone(), ); - let cluster_type = bank_forks.read().unwrap().root_bank().cluster_type(); - metrics_config_sanity_check(cluster_type)?; - datapoint_info!( "validator-new", ("id", id.to_string(), String), ("version", solana_version::version!(), String), - ("cluster_type", cluster_type as u32, i64), + ("cluster_type", genesis_config.cluster_type as u32, i64), ); *start_progress.write().unwrap() = ValidatorStartProgress::Running; diff --git a/metrics/src/metrics.rs b/metrics/src/metrics.rs index df761a6ac..b989ada68 100644 --- a/metrics/src/metrics.rs +++ b/metrics/src/metrics.rs @@ -25,7 +25,7 @@ type CounterMap = HashMap<(&'static str, u64), CounterPoint>; #[derive(Debug, Error)] pub enum MetricsError { #[error(transparent)] - VarError(#[from] std::env::VarError), + VarError(#[from] env::VarError), #[error(transparent)] ReqwestError(#[from] reqwest::Error), #[error("SOLANA_METRICS_CONFIG is invalid: '{0}'")] @@ -405,6 +405,9 @@ impl MetricsConfig { fn get_metrics_config() -> Result { let mut config = MetricsConfig::default(); let config_var = env::var("SOLANA_METRICS_CONFIG")?; + if config_var.is_empty() { + Err(env::VarError::NotPresent)?; + } for pair in config_var.split(',') { let nv: Vec<_> = pair.split('=').collect(); @@ -431,7 +434,7 @@ fn get_metrics_config() -> Result { pub fn metrics_config_sanity_check(cluster_type: ClusterType) -> Result<(), MetricsError> { let config = match get_metrics_config() { Ok(config) => config, - Err(MetricsError::VarError(std::env::VarError::NotPresent)) => return Ok(()), + Err(MetricsError::VarError(env::VarError::NotPresent)) => return Ok(()), Err(e) => return Err(e), }; match &config.db[..] {