Skip to content

Commit

Permalink
allow empty metadata db for eventhub
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik committed Sep 28, 2023
1 parent bd0191f commit 73e639d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions nexus/analyzer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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);
Expand Down Expand Up @@ -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<String, EventHubConfig> = HashMap::new();
for (key, _) in opts {
if key == "metadata_db" {
Expand All @@ -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)
Expand All @@ -651,7 +657,11 @@ fn parse_db_options(
Ok(config)
}

fn parse_metadata_db_info(conn_str: &str) -> anyhow::Result<PostgresConfig> {
fn parse_metadata_db_info(conn_str: &str) -> anyhow::Result<Option<PostgresConfig>> {
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() {
Expand All @@ -678,5 +688,5 @@ fn parse_metadata_db_info(conn_str: &str) -> anyhow::Result<PostgresConfig> {
};
}

Ok(metadata_db)
Ok(Some(metadata_db))
}

0 comments on commit 73e639d

Please sign in to comment.