Skip to content

Commit

Permalink
allow empty string for SOLANA_METRICS_CONFIG sanity checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jbiseda committed Oct 11, 2023
1 parent 7006a6f commit 0964faf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 5 additions & 4 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions metrics/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")]
Expand Down Expand Up @@ -405,6 +405,9 @@ impl MetricsConfig {
fn get_metrics_config() -> Result<MetricsConfig, MetricsError> {
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();
Expand All @@ -431,7 +434,7 @@ fn get_metrics_config() -> Result<MetricsConfig, MetricsError> {
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[..] {
Expand Down

0 comments on commit 0964faf

Please sign in to comment.