From 891936a4194561e524402a6aed0ff0d49a471315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jordan=20gonz=C3=A1lez?= <30836115+duncanista@users.noreply.github.com> Date: Mon, 25 Nov 2024 08:38:34 -0800 Subject: [PATCH] fix(bottlecap): fallback on yaml otel config (#474) * fallback on opted out only * fallback on yaml otel config * switch `legacy` to `compatibility` --- bottlecap/src/config/mod.rs | 68 ++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/bottlecap/src/config/mod.rs b/bottlecap/src/config/mod.rs index db255e22..3af745a1 100644 --- a/bottlecap/src/config/mod.rs +++ b/bottlecap/src/config/mod.rs @@ -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)] @@ -35,6 +38,8 @@ pub struct FallbackConfig { trace_otel_enabled: bool, otlp_config_receiver_protocols_http_endpoint: Option, otlp_config_receiver_protocols_grpc_endpoint: Option, + // YAML otel, we don't care about the content + otlp_config: Option, } #[derive(Debug, PartialEq, Deserialize, Clone, Default)] @@ -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, }; @@ -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 @@ -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(()) } @@ -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, @@ -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| { @@ -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");