Skip to content

Commit 39a540b

Browse files
committed
Migrate from snakeyaml to snakeyaml-engine
1 parent d5d53cd commit 39a540b

File tree

16 files changed

+79
-120
lines changed

16 files changed

+79
-120
lines changed

components/cli/build.gradle.kts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
plugins {
2-
id("me.champeau.jmh")
3-
}
4-
51
apply(from = "$rootDir/gradle/java.gradle")
6-
7-
jmh {
8-
version = "1.28"
9-
}
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
plugins {
2-
id("me.champeau.jmh")
3-
}
4-
51
apply(from = "$rootDir/gradle/java.gradle")
62

7-
jmh {
8-
version = "1.28"
9-
}
10-
113
val excludedClassesInstructionCoverage by extra {
124
listOf("datadog.context.ContextProviders") // covered by forked test
135
}

components/yaml/build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ plugins {
44

55
apply(from = "$rootDir/gradle/java.gradle")
66

7-
jmh {
8-
version = "1.28"
9-
}
10-
11-
// https://repo1.maven.org/maven2/org/yaml/snakeyaml/2.4/snakeyaml-2.4.pom
127
dependencies {
13-
implementation("org.yaml", "snakeyaml", "2.4")
8+
implementation("org.snakeyaml", "snakeyaml-engine", "2.9")
149
}
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package datadog.yaml;
22

3-
import org.yaml.snakeyaml.Yaml;
3+
import org.snakeyaml.engine.v2.api.Load;
4+
import org.snakeyaml.engine.v2.api.LoadSettings;
45

56
public class YamlParser {
6-
// Supports clazz == null for default yaml parsing
7-
public static <T> T parse(String content, Class<T> clazz) {
8-
Yaml yaml = new Yaml();
9-
if (clazz == null) {
10-
return yaml.load(content);
11-
} else {
12-
return yaml.loadAs(content, clazz);
13-
}
7+
public static Object parse(String content) {
8+
LoadSettings settings = LoadSettings.builder().setAllowDuplicateKeys(true).build();
9+
Load yaml = new Load(settings);
10+
return yaml.loadFromString(content);
1411
}
1512
}

dd-java-agent/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ext.generalShadowJarConfig = {
3838
// used to report our own dependencies, but we should remove the top-level metadata
3939
// of vendored packages because those could trigger unwanted framework checks.
4040
exclude '/META-INF/maven/org.slf4j/**'
41-
exclude '/META-INF/maven/org.yaml/**'
41+
exclude '/META-INF/maven/org.snakeyaml/**'
4242
exclude '**/META-INF/maven/**/pom.xml'
4343
exclude '**/META-INF/proguard/'
4444
exclude '**/META-INF/*.kotlin_module'
@@ -66,7 +66,7 @@ ext.generalShadowJarConfig = {
6666

6767
// Prevents conflict with other instances, but doesn't relocate instrumentation
6868
if (!projectName.equals('instrumentation')) {
69-
relocate 'org.yaml.snakeyaml', 'datadog.snakeyaml'
69+
relocate 'org.snakeyaml.engine', 'datadog.snakeyaml.engine'
7070
relocate 'okhttp3', 'datadog.okhttp3'
7171
relocate 'okio', 'datadog.okio'
7272
}

dd-java-agent/instrumentation/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ subprojects { Project subProj ->
6060
jdkCompile = "main_${name}Implementation"
6161
}
6262
configurations.muzzleBootstrap {
63-
exclude group: 'org.yaml', module : 'snakeyaml' // we vendor this in the agent jar
63+
exclude group: 'org.snakeyaml', module : 'snakeyaml-engine' // we vendor this in the agent jar
6464
}
6565
dependencies {
6666
// Apply common dependencies for instrumentation.

dd-java-agent/testing/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ excludedClassesCoverage += [
3939
]
4040

4141
configurations.api {
42-
exclude group: 'org.yaml', module: 'snakeyaml' // we vendor this in the agent jar
42+
exclude group: 'org.snakeyaml', module: 'snakeyaml-engine' // we vendor this in the agent jar
4343
}
4444

4545
dependencies {

gradle/dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ final class CachedData {
5252
exclude(dependency('cafe.cryptography::'))
5353

5454
// snakeyaml and its transitives
55-
exclude(dependency('org.yaml:snakeyaml'))
55+
exclude(dependency('org.snakeyaml:snakeyaml'))
5656
}
5757
]
5858
}

internal-api/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ dependencies {
251251
// it contains annotations that are also present in the instrumented application classes
252252
api "com.datadoghq:dd-javac-plugin-client:0.2.2"
253253

254-
testImplementation("org.yaml:snakeyaml:2.4")
254+
testImplementation("org.snakeyaml:snakeyaml-engine:2.9")
255255
testImplementation project(":utils:test-utils")
256256
testImplementation("org.assertj:assertj-core:3.20.2")
257257
testImplementation libs.bundles.junit5

internal-api/src/main/java/datadog/trace/bootstrap/config/provider/StableConfigParser.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package datadog.trace.bootstrap.config.provider;
22

3-
import datadog.trace.bootstrap.config.provider.stableconfigyaml.ConfigurationMap;
43
import datadog.trace.bootstrap.config.provider.stableconfigyaml.Rule;
54
import datadog.trace.bootstrap.config.provider.stableconfigyaml.Selector;
65
import datadog.trace.bootstrap.config.provider.stableconfigyaml.StableConfigYaml;
@@ -10,8 +9,9 @@
109
import java.nio.file.Files;
1110
import java.nio.file.Paths;
1211
import java.util.Collections;
13-
import java.util.HashMap;
12+
import java.util.LinkedHashMap;
1413
import java.util.List;
14+
import java.util.Map;
1515
import java.util.function.BiPredicate;
1616
import org.slf4j.Logger;
1717
import org.slf4j.LoggerFactory;
@@ -41,10 +41,11 @@ 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+
StableConfigYaml data = new StableConfigYaml(parsedYaml);
4546

4647
String configId = data.getConfig_id();
47-
ConfigurationMap configMap = data.getApm_configuration_default();
48+
Map<String, Object> configMap = data.getApm_configuration_default();
4849
List<Rule> rules = data.getApm_configuration_rules();
4950

5051
if (!rules.isEmpty()) {
@@ -53,14 +54,16 @@ public static StableConfigSource.StableConfig parse(String filePath) throws IOEx
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(
66+
configId, new LinkedHashMap<String, Object>(configMap));
6467
}
6568

6669
// If there's a configId but no configMap, use configId but return an empty map
@@ -91,12 +94,6 @@ private static boolean doesRuleMatch(Rule rule) {
9194
return true; // Return true if all selectors match
9295
}
9396

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-
10097
private static boolean validOperatorForLanguageOrigin(String operator) {
10198
operator = operator.toLowerCase();
10299
// "exists" is not valid

0 commit comments

Comments
 (0)