11package datadog .trace .bootstrap .config .provider ;
22
3- import datadog .trace .bootstrap .config .provider .stableconfigyaml .ConfigurationMap ;
4- import datadog .trace .bootstrap .config .provider .stableconfigyaml .Rule ;
5- import datadog .trace .bootstrap .config .provider .stableconfigyaml .Selector ;
6- import datadog .trace .bootstrap .config .provider .stableconfigyaml .StableConfigYaml ;
3+ import datadog .trace .bootstrap .config .provider .stableconfig .Rule ;
4+ import datadog .trace .bootstrap .config .provider .stableconfig .Selector ;
5+ import datadog .trace .bootstrap .config .provider .stableconfig .StableConfig ;
76import datadog .yaml .YamlParser ;
87import java .io .IOException ;
98import java .nio .charset .StandardCharsets ;
109import java .nio .file .Files ;
1110import java .nio .file .Paths ;
1211import java .util .Collections ;
13- import java .util .HashMap ;
12+ import java .util .LinkedHashMap ;
1413import java .util .List ;
14+ import java .util .Map ;
1515import java .util .function .BiPredicate ;
1616import org .slf4j .Logger ;
1717import org .slf4j .LoggerFactory ;
@@ -41,26 +41,28 @@ public static StableConfigSource.StableConfig parse(String filePath) throws IOEx
4141 try {
4242 String content = new String (Files .readAllBytes (Paths .get (filePath )), StandardCharsets .UTF_8 );
4343 String processedContent = processTemplate (content );
44- StableConfigYaml data = YamlParser .parse (processedContent , StableConfigYaml .class );
44+ Object parsedYaml = YamlParser .parse (processedContent );
45+ StableConfig data = new StableConfig (parsedYaml );
4546
46- String configId = data .getConfig_id ();
47- ConfigurationMap configMap = data .getApm_configuration_default ();
48- List <Rule > rules = data .getApm_configuration_rules ();
47+ String configId = data .getConfigId ();
48+ Map < String , Object > configMap = data .getApmConfigurationDefault ();
49+ List <Rule > rules = data .getApmConfigurationRules ();
4950
5051 if (!rules .isEmpty ()) {
5152 for (Rule rule : rules ) {
5253 // Use the first matching rule
5354 if (doesRuleMatch (rule )) {
5455 // Merge configs found in apm_configuration_rules with those found in
5556 // apm_configuration_default
56- configMap .putAll (rule .getConfiguration ());
57- return createStableConfig (configId , configMap );
57+ Map <String , Object > mergedConfigMap = new LinkedHashMap <>(configMap );
58+ mergedConfigMap .putAll (rule .getConfiguration ());
59+ return new StableConfigSource .StableConfig (configId , mergedConfigMap );
5860 }
5961 }
6062 }
6163 // If configs were found in apm_configuration_default, use them
6264 if (!configMap .isEmpty ()) {
63- return createStableConfig (configId , configMap );
65+ return new StableConfigSource . StableConfig (configId , configMap );
6466 }
6567
6668 // If there's a configId but no configMap, use configId but return an empty map
@@ -69,10 +71,7 @@ public static StableConfigSource.StableConfig parse(String filePath) throws IOEx
6971 }
7072
7173 } catch (IOException e ) {
72- log .debug (
73- "Stable configuration file either not found or not readable at filepath {}. Error: {}" ,
74- filePath ,
75- e .getMessage ());
74+ log .debug ("Failed to read the stable configuration file: {}" , filePath , e );
7675 }
7776 return StableConfigSource .StableConfig .EMPTY ;
7877 }
@@ -91,12 +90,6 @@ private static boolean doesRuleMatch(Rule rule) {
9190 return true ; // Return true if all selectors match
9291 }
9392
94- /** Creates a StableConfig object from the provided configId and configMap. */
95- private static StableConfigSource .StableConfig createStableConfig (
96- String configId , ConfigurationMap configMap ) {
97- return new StableConfigSource .StableConfig (configId , new HashMap <>(configMap ));
98- }
99-
10093 private static boolean validOperatorForLanguageOrigin (String operator ) {
10194 operator = operator .toLowerCase ();
10295 // "exists" is not valid
0 commit comments