@@ -441,12 +441,12 @@ impl Default for Config {
441
441
}
442
442
}
443
443
444
- fn log_fallback_reason ( reason : & str ) {
444
+ fn log_unsupported_reason ( reason : & str ) {
445
445
error ! ( "Fallback support for {reason} is no longer available." ) ;
446
446
}
447
447
448
448
#[ must_use = "fallback reasons should be processed to emit appropriate metrics" ]
449
- pub fn fallback ( config : & Config ) -> Vec < String > {
449
+ pub fn inspect_config ( config : & Config ) -> Vec < String > {
450
450
let mut fallback_reasons = Vec :: new ( ) ;
451
451
452
452
// Customer explicitly opted out of the Next Gen extension
@@ -458,15 +458,15 @@ pub fn fallback(config: &Config) -> Vec<String> {
458
458
459
459
if opted_out {
460
460
let reason = "extension_version" ;
461
- log_fallback_reason ( reason) ;
461
+ log_unsupported_reason ( reason) ;
462
462
fallback_reasons. push ( reason. to_string ( ) ) ;
463
463
}
464
464
465
465
// ASM / .NET
466
466
// todo(duncanista): Remove once the .NET runtime is fixed
467
467
if config. serverless_appsec_enabled && has_dotnet_binary ( ) {
468
468
let reason = "serverless_appsec_enabled_dotnet" ;
469
- log_fallback_reason ( reason) ;
469
+ log_unsupported_reason ( reason) ;
470
470
fallback_reasons. push ( reason. to_string ( ) ) ;
471
471
}
472
472
// OTLP
@@ -501,7 +501,7 @@ pub fn fallback(config: &Config) -> Vec<String> {
501
501
502
502
if has_otlp_config {
503
503
let reason = "otel" ;
504
- log_fallback_reason ( reason) ;
504
+ log_unsupported_reason ( reason) ;
505
505
fallback_reasons. push ( reason. to_string ( ) ) ;
506
506
}
507
507
@@ -724,15 +724,98 @@ pub mod tests {
724
724
} ;
725
725
726
726
#[ test]
727
- fn test_reject_on_opted_out ( ) {
727
+ fn test_baseline_case ( ) {
728
728
figment:: Jail :: expect_with ( |jail| {
729
729
jail. clear_env ( ) ;
730
- jail. set_env ( "DD_EXTENSION_VERSION" , "compatibility" ) ;
731
730
let _config = get_config ( Path :: new ( "" ) ) ;
732
731
Ok ( ( ) )
733
732
} ) ;
734
733
}
735
734
735
+ #[ test]
736
+ fn test_inspect_config ( ) {
737
+ struct TestCase {
738
+ name : & ' static str ,
739
+ env_vars : Vec < ( & ' static str , & ' static str ) > ,
740
+ yaml_content : Option < & ' static str > ,
741
+ expected_reasons : Vec < & ' static str > ,
742
+ }
743
+
744
+ let test_cases = vec ! [
745
+ TestCase {
746
+ name: "default config - no fallback reasons" ,
747
+ env_vars: vec![ ] ,
748
+ yaml_content: None ,
749
+ expected_reasons: vec![ ] ,
750
+ } ,
751
+ TestCase {
752
+ name: "extension_version compatibility - should fallback" ,
753
+ env_vars: vec![ ( "DD_EXTENSION_VERSION" , "compatibility" ) ] ,
754
+ yaml_content: None ,
755
+ expected_reasons: vec![ "extension_version" ] ,
756
+ } ,
757
+ TestCase {
758
+ name: "otlp config enabled - should fallback" ,
759
+ env_vars: vec![ (
760
+ "DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_GRPC_ENDPOINT" ,
761
+ "localhost:4317" ,
762
+ ) ] ,
763
+ yaml_content: None ,
764
+ expected_reasons: vec![ "otel" ] ,
765
+ } ,
766
+ TestCase {
767
+ name: "multiple fallback reasons" ,
768
+ env_vars: vec![
769
+ ( "DD_EXTENSION_VERSION" , "compatibility" ) ,
770
+ ( "DD_OTLP_CONFIG_METRICS_ENABLED" , "true" ) ,
771
+ ] ,
772
+ yaml_content: None ,
773
+ expected_reasons: vec![ "extension_version" , "otel" ] ,
774
+ } ,
775
+ TestCase {
776
+ name: "otlp config via yaml - should fallback" ,
777
+ env_vars: vec![ ] ,
778
+ yaml_content: Some (
779
+ r"
780
+ otlp_config:
781
+ receiver:
782
+ protocols:
783
+ grpc:
784
+ endpoint: localhost:4317
785
+ " ,
786
+ ) ,
787
+ expected_reasons: vec![ "otel" ] ,
788
+ } ,
789
+ ] ;
790
+
791
+ for test_case in test_cases {
792
+ figment:: Jail :: expect_with ( |jail| {
793
+ jail. clear_env ( ) ;
794
+
795
+ // Set environment variables
796
+ for ( key, value) in & test_case. env_vars {
797
+ jail. set_env ( key, value) ;
798
+ }
799
+
800
+ // Create YAML file if provided
801
+ if let Some ( yaml_content) = test_case. yaml_content {
802
+ jail. create_file ( "datadog.yaml" , yaml_content) ?;
803
+ }
804
+
805
+ let config = get_config ( Path :: new ( "" ) ) ;
806
+ let fallback_reasons = inspect_config ( & config) ;
807
+
808
+ assert_eq ! (
809
+ fallback_reasons, test_case. expected_reasons,
810
+ "Test case '{}' failed: expected {:?}, got {:?}" ,
811
+ test_case. name, test_case. expected_reasons, fallback_reasons
812
+ ) ;
813
+
814
+ Ok ( ( ) )
815
+ } ) ;
816
+ }
817
+ }
818
+
736
819
#[ test]
737
820
fn test_fallback_on_otel ( ) {
738
821
figment:: Jail :: expect_with ( |jail| {
@@ -849,17 +932,6 @@ pub mod tests {
849
932
} ) ;
850
933
}
851
934
852
- #[ test]
853
- fn test_allowed_but_disabled ( ) {
854
- figment:: Jail :: expect_with ( |jail| {
855
- jail. clear_env ( ) ;
856
- jail. set_env ( "DD_SERVERLESS_APPSEC_ENABLED" , "true" ) ;
857
-
858
- let _config = get_config ( Path :: new ( "" ) ) ;
859
- Ok ( ( ) )
860
- } ) ;
861
- }
862
-
863
935
#[ test]
864
936
fn test_precedence ( ) {
865
937
figment:: Jail :: expect_with ( |jail| {
@@ -871,7 +943,7 @@ pub mod tests {
871
943
" ,
872
944
) ?;
873
945
jail. set_env ( "DD_SITE" , "datad0g.com" ) ;
874
- let config = get_config ( Path :: new ( "" ) ) ;
946
+ let config = get_config ( Path :: new ( "" ) ) . expect ( "should parse config" ) ;
875
947
assert_eq ! ( config. site, "datad0g.com" ) ;
876
948
Ok ( ( ) )
877
949
} ) ;
0 commit comments