diff --git a/nexus/analyzer/src/lib.rs b/nexus/analyzer/src/lib.rs index 7f1f537b30..13172f511a 100644 --- a/nexus/analyzer/src/lib.rs +++ b/nexus/analyzer/src/lib.rs @@ -553,10 +553,11 @@ fn parse_db_options( Some(config) } DbType::Eventhub => { - let conn_str = opts + let conn_str: String = opts .get("metadata_db") - .context("no metadata db specified")?; - let metadata_db = parse_metadata_db_info(conn_str)?; + .map(|s| s.to_string()) + .unwrap_or_default(); + let metadata_db = parse_metadata_db_info(&conn_str)?; let subscription_id = opts .get("subscription_id") .map(|s| s.to_string()) @@ -575,7 +576,7 @@ fn parse_db_options( .get("location") .context("location not specified")? .to_string(), - metadata_db: Some(metadata_db), + metadata_db, subscription_id, }; let config = Config::EventhubConfig(eventhub_config); @@ -619,6 +620,11 @@ fn parse_db_options( .context("no metadata db specified")?; let metadata_db = parse_metadata_db_info(conn_str)?; + // metadata_db is required for eventhub group + if metadata_db.is_none() { + anyhow::bail!("metadata_db is required for eventhub group"); + } + let mut eventhubs: HashMap = HashMap::new(); for (key, _) in opts { if key == "metadata_db" { @@ -641,7 +647,7 @@ fn parse_db_options( let eventhub_group_config = pt::peerdb_peers::EventHubGroupConfig { eventhubs, - metadata_db: Some(metadata_db), + metadata_db, }; let config = Config::EventhubGroupConfig(eventhub_group_config); Some(config) @@ -651,7 +657,11 @@ fn parse_db_options( Ok(config) } -fn parse_metadata_db_info(conn_str: &str) -> anyhow::Result { +fn parse_metadata_db_info(conn_str: &str) -> anyhow::Result> { + if conn_str.is_empty() { + return Ok(None); + } + let mut metadata_db = PostgresConfig::default(); let param_pairs: Vec<&str> = conn_str.split_whitespace().collect(); match param_pairs.len() { @@ -678,5 +688,5 @@ fn parse_metadata_db_info(conn_str: &str) -> anyhow::Result { }; } - Ok(metadata_db) + Ok(Some(metadata_db)) }