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
68 changes: 60 additions & 8 deletions bottlecap/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ use std::vec;
use figment::providers::{Format, Yaml};
use figment::{providers::Env, Figment};
use serde::Deserialize;
use serde_json::Value;
use trace_propagation_style::{deserialize_trace_propagation_style, TracePropagationStyle};

use crate::config::flush_strategy::FlushStrategy;
use crate::config::log_level::{deserialize_log_level, LogLevel};
use crate::config::processing_rule::{deserialize_processing_rules, ProcessingRule};
use crate::config::service_mapping::deserialize_service_mapping;
use crate::config::{
flush_strategy::FlushStrategy,
log_level::{deserialize_log_level, LogLevel},
processing_rule::{deserialize_processing_rules, ProcessingRule},
service_mapping::deserialize_service_mapping,
};

/// `FallbackConfig` is a struct that represents fields that are not supported in the extension yet.
///
/// If `extension_version` is set to "legacy", the Go extension will be launched.
/// If `extension_version` is set to `compatibility`, the Go extension will be launched.
#[derive(Debug, PartialEq, Deserialize, Clone, Default)]
#[serde(default)]
#[allow(clippy::module_name_repetitions)]
Expand All @@ -35,6 +38,8 @@ pub struct FallbackConfig {
trace_otel_enabled: bool,
otlp_config_receiver_protocols_http_endpoint: Option<String>,
otlp_config_receiver_protocols_grpc_endpoint: Option<String>,
// YAML otel, we don't care about the content
otlp_config: Option<Value>,
}

#[derive(Debug, PartialEq, Deserialize, Clone, Default)]
Expand Down Expand Up @@ -144,7 +149,7 @@ fn fallback(figment: &Figment) -> Result<(), ConfigError> {

// Customer explicitly opted out of the Next Gen extension
let opted_out = match fallback_config.extension_version.as_deref() {
Some("legacy") => true,
Some("compatibility") => true,
// We want customers using the `next` to not be affected
_ => false,
};
Expand All @@ -168,6 +173,7 @@ fn fallback(figment: &Figment) -> Result<(), ConfigError> {
));
}

// OTEL env
if fallback_config.trace_otel_enabled
|| fallback_config
.otlp_config_receiver_protocols_http_endpoint
Expand All @@ -180,6 +186,12 @@ fn fallback(figment: &Figment) -> Result<(), ConfigError> {
return Err(ConfigError::UnsupportedField("otel".to_string()));
}

// OTEL YAML
if fallback_config.otlp_config.is_some() {
log_fallback_reason("otel");
return Err(ConfigError::UnsupportedField("otel".to_string()));
}

Ok(())
}

Expand Down Expand Up @@ -261,7 +273,7 @@ pub mod tests {
fn test_reject_on_opted_out() {
figment::Jail::expect_with(|jail| {
jail.clear_env();
jail.set_env("DD_EXTENSION_VERSION", "legacy");
jail.set_env("DD_EXTENSION_VERSION", "compatibility");
let config = get_config(Path::new("")).expect_err("should reject unknown fields");
assert_eq!(
config,
Expand All @@ -286,6 +298,47 @@ pub mod tests {
});
}

#[test]
fn test_fallback_on_otel_yaml() {
figment::Jail::expect_with(|jail| {
jail.clear_env();
jail.create_file(
"datadog.yaml",
r"
otlp_config:
receiver:
protocols:
http:
endpoint: localhost:4138
",
)?;

let config = get_config(Path::new("")).expect_err("should reject unknown fields");
assert_eq!(config, ConfigError::UnsupportedField("otel".to_string()));
Ok(())
});
}

#[test]
fn test_fallback_on_otel_yaml_empty_section() {
figment::Jail::expect_with(|jail| {
jail.clear_env();
jail.create_file(
"datadog.yaml",
r"
otlp_config:
receiver:
protocols:
http:
",
)?;

let config = get_config(Path::new("")).expect_err("should reject unknown fields");
assert_eq!(config, ConfigError::UnsupportedField("otel".to_string()));
Ok(())
});
}

#[test]
fn test_allowed_but_disabled() {
figment::Jail::expect_with(|jail| {
Expand Down Expand Up @@ -325,7 +378,6 @@ pub mod tests {
jail.create_file(
"datadog.yaml",
r"
extension_version: next
",
)?;
let config = get_config(Path::new("")).expect("should parse config");
Expand Down
Loading