22
33import datadog .environment .EnvironmentVariables ;
44import datadog .trace .api .telemetry .ConfigInversionMetricCollectorProvider ;
5+ import java .util .ArrayList ;
56import java .util .Collections ;
67import java .util .HashMap ;
78import java .util .List ;
89import java .util .Locale ;
910import java .util .Map ;
11+ import java .util .Set ;
12+ import java .util .concurrent .ConcurrentHashMap ;
1013import org .slf4j .Logger ;
1114import org .slf4j .LoggerFactory ;
1215
@@ -15,7 +18,7 @@ private ConfigHelper() {}
1518
1619 /** Config Inversion strictness policy for enforcement of undocumented environment variables */
1720 public enum StrictnessPolicy {
18- STRICT ,
21+ STRICT_TEST ,
1922 WARNING ,
2023 TEST ;
2124
@@ -49,6 +52,9 @@ public String toString() {
4952 // Default to production source
5053 private SupportedConfigurationSource configSource = new SupportedConfigurationSource ();
5154
55+ // Collects unsupported config keys encountered in STRICT_TEST mode
56+ private final Set <String > unsupportedConfigs = ConcurrentHashMap .newKeySet ();
57+
5258 public static ConfigHelper get () {
5359 return INSTANCE ;
5460 }
@@ -75,9 +81,18 @@ void resetCache() {
7581 void resetToDefaults () {
7682 configSource = new SupportedConfigurationSource ();
7783 this .configInversionStrict = StrictnessPolicy .WARNING ;
84+ unsupportedConfigs .clear ();
7885 resetCache ();
7986 }
8087
88+ /** Returns and clears the set of unsupported config keys encountered in STRICT_TEST mode. */
89+ public List <String > drainUnsupportedConfigs () {
90+ List <String > result = new ArrayList <>(unsupportedConfigs );
91+ unsupportedConfigs .clear ();
92+ Collections .sort (result );
93+ return result ;
94+ }
95+
8196 public static Map <String , String > env () {
8297 return get ().getEnvironmentVariables ();
8398 }
@@ -142,8 +157,13 @@ public String getEnvironmentVariable(String name) {
142157 ConfigInversionMetricCollectorProvider .get ().setUndocumentedEnvVarMetric (name );
143158 }
144159
145- if (configInversionStrict == StrictnessPolicy .STRICT ) {
146- return null ; // If strict mode is enabled, return null for unsupported configs
160+ if (configInversionStrict == StrictnessPolicy .STRICT_TEST ) {
161+ unsupportedConfigs .add (name );
162+ throw new IllegalArgumentException (
163+ "Unsupported configuration: "
164+ + name
165+ + " is not in GeneratedSupportedConfigurations. "
166+ + "Add it to metadata/supported-configurations.json or remove the usage." );
147167 }
148168 }
149169
0 commit comments