Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions bottlecap/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ impl ConfigBuilder {
}

// If Logs URL is not set, set it to the default
if self.config.logs_config_logs_dd_url.is_empty() {
if self.config.logs_config_logs_dd_url.trim().is_empty() {
self.config.logs_config_logs_dd_url = build_fqdn_logs(self.config.site.clone());
} else {
self.config.logs_config_logs_dd_url =
logs_intake_url(self.config.logs_config_logs_dd_url.as_str());
}

// If APM URL is not set, set it to the default
Expand Down Expand Up @@ -481,6 +484,19 @@ fn build_fqdn_logs(site: String) -> String {
format!("https://http-intake.logs.{site}")
}

#[inline]
#[must_use]
fn logs_intake_url(url: &str) -> String {
let url = url.trim();
if url.is_empty() {
return url.to_string();
}
Comment thread
shreyamalpani marked this conversation as resolved.
if url.starts_with("https://") || url.starts_with("http://") {
return url.to_string();
}
Comment thread
shreyamalpani marked this conversation as resolved.
format!("https://{url}")
}

pub fn deserialize_optional_string<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
where
D: Deserializer<'de>,
Expand Down Expand Up @@ -811,7 +827,44 @@ pub mod tests {
let config = get_config(Path::new(""));
assert_eq!(
config.logs_config_logs_dd_url,
"agent-http-intake-pci.logs.datadoghq.com:443".to_string()
"https://agent-http-intake-pci.logs.datadoghq.com:443".to_string()
);
Ok(())
});
}

#[test]
fn test_logs_intake_url_adds_prefix() {
Comment thread
shreyamalpani marked this conversation as resolved.
figment::Jail::expect_with(|jail| {
jail.clear_env();
jail.set_env(
"DD_LOGS_CONFIG_LOGS_DD_URL",
"dr-test-failover-http-intake.logs.datadoghq.com:443",
);

let config = get_config(Path::new(""));
// ensure host:port URL is prefixed with https://
assert_eq!(
config.logs_config_logs_dd_url,
"https://dr-test-failover-http-intake.logs.datadoghq.com:443".to_string()
);
Ok(())
});
}

#[test]
fn test_prefixed_logs_intake_url() {
Comment thread
shreyamalpani marked this conversation as resolved.
figment::Jail::expect_with(|jail| {
jail.clear_env();
jail.set_env(
"DD_LOGS_CONFIG_LOGS_DD_URL",
"https://custom-intake.logs.datadoghq.com:443",
);

let config = get_config(Path::new(""));
assert_eq!(
config.logs_config_logs_dd_url,
"https://custom-intake.logs.datadoghq.com:443".to_string()
);
Ok(())
});
Expand Down
Loading