Skip to content

Commit 2dfc8ee

Browse files
mtoffl01mcculls
andauthored
Support targeting services with configurations in stable configuration file (#8526)
Co-authored-by: Stuart McCulloch <[email protected]>
1 parent 8adba3f commit 2dfc8ee

File tree

19 files changed

+574
-175
lines changed

19 files changed

+574
-175
lines changed

components/yaml/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id("me.champeau.jmh")
3+
}
4+
5+
apply(from = "$rootDir/gradle/java.gradle")
6+
7+
jmh {
8+
version = "1.28"
9+
}
10+
11+
// https://repo1.maven.org/maven2/org/yaml/snakeyaml/2.4/snakeyaml-2.4.pom
12+
dependencies {
13+
implementation("org.yaml", "snakeyaml", "2.4")
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package datadog.yaml;
2+
3+
import java.io.FileInputStream;
4+
import java.io.IOException;
5+
import org.yaml.snakeyaml.Yaml;
6+
7+
public class YamlParser {
8+
// Supports clazz == null for default yaml parsing
9+
public static <T> T parse(String filePath, Class<T> clazz) throws IOException {
10+
Yaml yaml = new Yaml();
11+
try (FileInputStream fis = new FileInputStream(filePath)) {
12+
if (clazz == null) {
13+
return yaml.load(fis);
14+
} else {
15+
return yaml.loadAs(fis, clazz);
16+
}
17+
}
18+
}
19+
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public final class Constants {
1616
public static final String[] BOOTSTRAP_PACKAGE_PREFIXES = {
1717
"datadog.slf4j",
1818
"datadog.json",
19+
"datadog.yaml",
1920
"datadog.context",
2021
"datadog.cli",
2122
"datadog.appsec.api",

dd-java-agent/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ ext.generalShadowJarConfig = {
5959

6060
final String projectName = "${project.name}"
6161

62-
// Prevents conflict with other OkHttp instances, but don't relocate instrumentation
62+
// Prevents conflict with other instances, but doesn't relocate instrumentation
6363
if (!projectName.equals('instrumentation')) {
64+
relocate 'org.yaml.snakeyaml', 'datadog.snakeyaml'
6465
relocate 'okhttp3', 'datadog.okhttp3'
6566
relocate 'okio', 'datadog.okio'
6667
}

dd-java-agent/instrumentation/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ subprojects { Project subProj ->
5959
def name = "java$version.majorVersion"
6060
jdkCompile = "main_${name}Implementation"
6161
}
62+
configurations.muzzleBootstrap {
63+
exclude group: 'org.yaml', module : 'snakeyaml' // we vendor this in the agent jar
64+
}
6265
dependencies {
6366
// Apply common dependencies for instrumentation.
6467
implementation project(':dd-trace-api')

dd-java-agent/instrumentation/snakeyaml/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ addTestSuiteForDir('latestDepTest', 'test')
1818

1919
dependencies {
2020
compileOnly group: 'org.yaml', name: 'snakeyaml', version: '1.33'
21-
testImplementation group: 'org.yaml', name: 'snakeyaml', version: '1.33'
21+
22+
testImplementation('org.yaml:snakeyaml') {
23+
version {
24+
strictly "[1.4, 2.0)"
25+
prefer '1.33'
26+
}
27+
}
2228

2329
latestDepTestImplementation group: 'org.yaml', name: 'snakeyaml', version: '1.+'
2430
}

dd-java-agent/testing/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ excludedClassesCoverage += [
3838
'datadog.trace.agent.test.TestProfilingContextIntegration.TestQueueTiming'
3939
]
4040

41+
configurations.api {
42+
exclude group: 'org.yaml', module: 'snakeyaml' // we vendor this in the agent jar
43+
}
44+
4145
dependencies {
4246
api libs.bytebuddy
4347
api libs.bytebuddyagent

dd-java-agent/testing/src/main/groovy/datadog/trace/agent/test/SpockRunner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class SpockRunner extends JUnitPlatform {
3939
public static final String[] BOOTSTRAP_PACKAGE_PREFIXES_COPY = {
4040
"datadog.slf4j",
4141
"datadog.json",
42+
"datadog.yaml",
4243
"datadog.context",
4344
"datadog.cli",
4445
"datadog.appsec.api",

gradle/dependencies.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class CachedData {
1818
exclude(project(':communication'))
1919
exclude(project(':components:context'))
2020
exclude(project(':components:json'))
21+
exclude(project(':components:yaml'))
2122
exclude(project(':components:cli'))
2223
exclude(project(':remote-config:remote-config-api'))
2324
exclude(project(':remote-config:remote-config-core'))
@@ -49,6 +50,9 @@ final class CachedData {
4950

5051
// cafe_crypto and its transitives
5152
exclude(dependency('cafe.cryptography::'))
53+
54+
// snakeyaml and its transitives
55+
exclude(dependency('org.yaml:snakeyaml'))
5256
}
5357
]
5458
}

internal-api/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,22 @@ dependencies {
239239
api project(':dd-trace-api')
240240
api libs.slf4j
241241
api project(':components:context')
242+
api project(':components:yaml')
242243
api project(':components:cli')
243244
api project(":utils:time-utils")
244245

245246
// has to be loaded by system classloader:
246247
// it contains annotations that are also present in the instrumented application classes
247248
api "com.datadoghq:dd-javac-plugin-client:0.2.2"
248249

250+
testImplementation("org.yaml:snakeyaml:2.4")
249251
testImplementation project(":utils:test-utils")
250252
testImplementation("org.assertj:assertj-core:3.20.2")
251253
testImplementation libs.bundles.junit5
252254
testImplementation group: 'org.junit.vintage', name: 'junit-vintage-engine', version: libs.versions.junit5.get()
253255
testImplementation libs.commons.math
254256
testImplementation libs.bundles.mockito
255257
testImplementation libs.truth
256-
testImplementation 'org.yaml:snakeyaml:2.0'
257258
}
258259

259260
jmh {

0 commit comments

Comments
 (0)