Skip to content

Commit fff85cc

Browse files
authored
fix: Honor noproxy and skip proxying if ddsite is in the noproxy list (#520)
* fix: Honor noproxy and skip proxying if ddsite is in the noproxy list * feat: specs * feat: Oneline check, add comment
1 parent a1574fc commit fff85cc

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

bottlecap/src/config/mod.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use figment::{providers::Env, Figment};
1414
use serde::{Deserialize, Deserializer};
1515
use serde_json::Value;
1616
use trace_propagation_style::{deserialize_trace_propagation_style, TracePropagationStyle};
17+
use tracing::debug;
1718

1819
use crate::config::{
1920
flush_strategy::FlushStrategy,
@@ -260,7 +261,13 @@ pub fn get_config(config_directory: &Path) -> Result<Config, ConfigError> {
260261
if config.site.is_empty() {
261262
config.site = "datadoghq.com".to_string();
262263
}
263-
264+
// TODO(astuyve)
265+
// Bit of a hack as we're not checking individual privatelink setups
266+
// potentially a user could use the proxy for logs and privatelink for APM
267+
if std::env::var("NO_PROXY").map_or(false, |no_proxy| no_proxy.contains(&config.site)) {
268+
debug!("NO_PROXY contains DD_SITE, disabling proxy");
269+
config.https_proxy = None;
270+
}
264271
// Merge YAML nested fields
265272
//
266273
// Set logs_config_processing_rules if not defined in env
@@ -522,6 +529,33 @@ pub mod tests {
522529
});
523530
}
524531

532+
#[test]
533+
fn test_proxy_config() {
534+
figment::Jail::expect_with(|jail| {
535+
jail.clear_env();
536+
jail.set_env("DD_PROXY_HTTPS", "my-proxy:3128");
537+
let config = get_config(Path::new("")).expect("should parse config");
538+
assert_eq!(config.https_proxy, Some("my-proxy:3128".to_string()));
539+
Ok(())
540+
});
541+
}
542+
543+
#[test]
544+
fn test_noproxy_config() {
545+
figment::Jail::expect_with(|jail| {
546+
jail.clear_env();
547+
jail.set_env("DD_SITE", "datadoghq.eu");
548+
jail.set_env("DD_PROXY_HTTPS", "my-proxy:3128");
549+
jail.set_env(
550+
"NO_PROXY",
551+
"127.0.0.1,localhost,172.16.0.0/12,us-east-1.amazonaws.com,datadoghq.eu",
552+
);
553+
let config = get_config(Path::new("")).expect("should parse noproxy");
554+
assert_eq!(config.https_proxy, None);
555+
Ok(())
556+
});
557+
}
558+
525559
#[test]
526560
fn test_parse_flush_strategy_end() {
527561
figment::Jail::expect_with(|jail| {

0 commit comments

Comments
 (0)