Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions crates/datadog-agent-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ pub struct Config<E: ConfigExtension = NoExtension> {
pub tags: HashMap<String, String>,

// Logs
/// Master toggle for log collection. Sourced from `DD_LOGS_ENABLED` /
/// `logs_enabled` in datadog.yaml. Defaults to `false` to match the
/// dd-agent default; consumers that want a different default should
/// override post-build or in their `ConfigExtension`.
pub logs_enabled: bool,
pub logs_config_logs_dd_url: String,
pub logs_config_processing_rules: Option<Vec<ProcessingRule>>,
pub logs_config_use_compression: bool,
Expand Down Expand Up @@ -189,6 +194,7 @@ impl<E: ConfigExtension> Default for Config<E> {
compression_level: 3,

// Logs
logs_enabled: false,
logs_config_logs_dd_url: String::default(),
logs_config_processing_rules: None,
logs_config_use_compression: true,
Expand Down
40 changes: 40 additions & 0 deletions crates/datadog-agent-config/src/sources/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ pub struct EnvConfig {
pub compression_level: Option<i32>,

// Logs
/// @env `DD_LOGS_ENABLED`
///
/// Master toggle for log collection. Default `false`.
#[serde(deserialize_with = "deserialize_optional_bool_from_anything")]
pub logs_enabled: Option<bool>,
/// @env `DD_LOGS_CONFIG_LOGS_DD_URL`
///
/// Define the endpoint and port to hit when using a proxy for logs.
Expand Down Expand Up @@ -403,6 +408,7 @@ fn merge_config<E: ConfigExtension>(config: &mut Config<E>, env_config: &EnvConf
merge_option_to_value!(config, env_config, compression_level);

// Logs
merge_option_to_value!(config, env_config, logs_enabled);
merge_string!(config, env_config, logs_config_logs_dd_url);
merge_option!(config, env_config, logs_config_processing_rules);
merge_option_to_value!(config, env_config, logs_config_use_compression);
Expand Down Expand Up @@ -628,6 +634,7 @@ mod tests {
),
// Bool
("DD_SKIP_SSL_VALIDATION", "not_a_bool"),
("DD_LOGS_ENABLED", "not_a_bool"),
("DD_LOGS_CONFIG_USE_COMPRESSION", "not_a_bool"),
(
"DD_APM_CONFIG_OBFUSCATION_HTTP_REMOVE_QUERY_STRING",
Expand Down Expand Up @@ -846,6 +853,7 @@ mod tests {
jail.set_env("DD_COMPRESSION_LEVEL", "4");

// Logs
jail.set_env("DD_LOGS_ENABLED", "true");
jail.set_env("DD_LOGS_CONFIG_LOGS_DD_URL", "https://logs.datadoghq.com");
jail.set_env(
"DD_LOGS_CONFIG_PROCESSING_RULES",
Expand Down Expand Up @@ -991,6 +999,7 @@ mod tests {
("team".to_string(), "test-team".to_string()),
("project".to_string(), "test-project".to_string()),
]),
logs_enabled: true,
logs_config_logs_dd_url: "https://logs.datadoghq.com".to_string(),
logs_config_processing_rules: Some(vec![ProcessingRule {
kind: Kind::ExcludeAtMatch,
Expand Down Expand Up @@ -1122,6 +1131,37 @@ mod tests {
});
}

#[test]
fn test_logs_enabled_from_env() {
figment::Jail::expect_with(|jail| {
jail.clear_env();
jail.set_env("DD_LOGS_ENABLED", "true");

let mut config: Config = Config::default();
EnvConfigSource
.load(&mut config)
.expect("Failed to load config");

assert!(config.logs_enabled);
Ok(())
});
}

#[test]
fn test_logs_enabled_defaults_false_when_unset() {
figment::Jail::expect_with(|jail| {
jail.clear_env();

let mut config: Config = Config::default();
EnvConfigSource
.load(&mut config)
.expect("Failed to load config");

assert!(!config.logs_enabled);
Ok(())
});
}

#[test]
fn test_dd_org_uuid_from_env() {
figment::Jail::expect_with(|jail| {
Expand Down
9 changes: 9 additions & 0 deletions crates/datadog-agent-config/src/sources/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ pub struct YamlConfig {
pub tags: HashMap<String, String>,

// Logs
/// YAML key: `logs_enabled`. Master toggle for log collection; matches
/// dd-agent's top-level `logs_enabled` (default `false`).
#[serde(deserialize_with = "deserialize_optional_bool_from_anything")]
pub logs_enabled: Option<bool>,
#[serde(deserialize_with = "deserialize_with_default")]
pub logs_config: LogsConfig,

Expand Down Expand Up @@ -438,6 +442,7 @@ fn merge_config<E: ConfigExtension>(config: &mut Config<E>, yaml_config: &YamlCo
merge_string!(config, yaml_config, dd_url);

// Logs
merge_option_to_value!(config, yaml_config, logs_enabled);
merge_string!(
config,
logs_config_logs_dd_url,
Expand Down Expand Up @@ -777,6 +782,7 @@ version: "v1.0.0"
tags: 12345

# Logs (nested)
logs_enabled: [1, 2, 3]
logs_config:
Comment thread
duncanista marked this conversation as resolved.
logs_dd_url: "https://custom-logs.example.com"
processing_rules: 12345
Expand Down Expand Up @@ -867,6 +873,7 @@ otlp_config:
expected.api_key = "test-api-key-12345".to_string();
expected.dd_org_uuid = "00000000-0000-0000-0000-000000000001".to_string();
expected.dd_url = "https://custom-metrics.example.com".to_string();
// logs_enabled was given an invalid type above → must stay at default (false)
expected.logs_config_logs_dd_url = "https://custom-logs.example.com".to_string();
expected.apm_dd_url = "https://custom-apm.example.com".to_string();
// Option<String> fields
Expand Down Expand Up @@ -934,6 +941,7 @@ tags:
- "project:test-project"

# Logs
logs_enabled: true
logs_config:
logs_dd_url: "https://logs.datadoghq.com"
processing_rules:
Expand Down Expand Up @@ -1060,6 +1068,7 @@ otlp_config:
("team".to_string(), "test-team".to_string()),
("project".to_string(), "test-project".to_string()),
]),
logs_enabled: true,
logs_config_logs_dd_url: "https://logs.datadoghq.com".to_string(),
logs_config_processing_rules: Some(vec![ProcessingRule {
name: "test-exclude".to_string(),
Expand Down
Loading