Skip to content

Commit 80d0355

Browse files
Add custom test fingerprint tags to ITR requests (DataDog#6195)
1 parent 76a6744 commit 80d0355

6 files changed

Lines changed: 131 additions & 47 deletions

File tree

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationsJson.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.squareup.moshi.Json;
55
import com.squareup.moshi.ToJson;
66
import datadog.trace.api.civisibility.config.Configurations;
7+
import java.util.Map;
78

89
public final class ConfigurationsJson {
910
@Json(name = "os.platform")
@@ -33,6 +34,9 @@ public final class ConfigurationsJson {
3334
@Json(name = "test.bundle")
3435
private final String testBundle;
3536

37+
@Json(name = "custom")
38+
private final Map<String, String> custom;
39+
3640
public ConfigurationsJson(
3741
String osPlatform,
3842
String osArchitecture,
@@ -41,7 +45,8 @@ public ConfigurationsJson(
4145
String runtimeVersion,
4246
String runtimeVendor,
4347
String runtimeArchitecture,
44-
String testBundle) {
48+
String testBundle,
49+
Map<String, String> custom) {
4550
this.osPlatform = osPlatform;
4651
osArch = osArchitecture;
4752
this.osArchitecture = osArchitecture;
@@ -51,6 +56,7 @@ public ConfigurationsJson(
5156
this.runtimeVendor = runtimeVendor;
5257
this.runtimeArchitecture = runtimeArchitecture;
5358
this.testBundle = testBundle;
59+
this.custom = custom;
5460
}
5561

5662
public static final class ConfigurationsJsonAdapter {
@@ -64,7 +70,8 @@ public Configurations fromJson(ConfigurationsJson configurationsJson) {
6470
configurationsJson.runtimeVersion,
6571
configurationsJson.runtimeVendor,
6672
configurationsJson.runtimeArchitecture,
67-
configurationsJson.testBundle);
73+
configurationsJson.testBundle,
74+
configurationsJson.custom);
6875
}
6976

7077
@ToJson
@@ -77,7 +84,8 @@ public ConfigurationsJson toJson(Configurations configurations) {
7784
configurations.getRuntimeVersion(),
7885
configurations.getRuntimeVendor(),
7986
configurations.getRuntimeArchitecture(),
80-
configurations.getTestBundle());
87+
configurations.getTestBundle(),
88+
configurations.getCustom());
8189
}
8290
}
8391
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ModuleExecutionSettingsFactoryImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class ModuleExecutionSettingsFactoryImpl implements ModuleExecutionSettin
3232

3333
private static final Logger LOGGER =
3434
LoggerFactory.getLogger(ModuleExecutionSettingsFactoryImpl.class);
35+
private static final String TEST_CONFIGURATION_TAG_PREFIX = "test.configuration.";
3536

3637
private final Config config;
3738
private final ConfigurationApi configurationApi;
@@ -88,11 +89,21 @@ private TracerEnvironment buildTracerEnvironment(
8889
String repositoryRoot, JvmInfo jvmInfo, @Nullable String moduleName) {
8990
GitInfo gitInfo = GitInfoProvider.INSTANCE.getGitInfo(repositoryRoot);
9091

92+
TracerEnvironment.Builder builder = TracerEnvironment.builder();
93+
for (Map.Entry<String, String> e : config.getGlobalTags().entrySet()) {
94+
String key = e.getKey();
95+
if (key.startsWith(TEST_CONFIGURATION_TAG_PREFIX)) {
96+
String configurationKey = key.substring(TEST_CONFIGURATION_TAG_PREFIX.length());
97+
String configurationValue = e.getValue();
98+
builder.customTag(configurationKey, configurationValue);
99+
}
100+
}
101+
91102
/*
92103
* IMPORTANT: JVM and OS properties should match tags
93104
* set in datadog.trace.civisibility.decorator.TestDecorator
94105
*/
95-
return TracerEnvironment.builder()
106+
return builder
96107
.service(config.getServiceName())
97108
.env(config.getEnv())
98109
.repositoryUrl(gitInfo.getRepositoryURL())

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/TracerEnvironment.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.squareup.moshi.Json;
44
import datadog.trace.api.civisibility.config.Configurations;
5+
import java.util.HashMap;
6+
import java.util.Map;
57

68
public class TracerEnvironment {
79

@@ -52,6 +54,7 @@ public static final class Builder {
5254
private String runtimeVendor;
5355
private String runtimeArchitecture;
5456
private String testBundle;
57+
private final Map<String, String> customTags = new HashMap<>();
5558

5659
public Builder service(String service) {
5760
this.service = service;
@@ -118,6 +121,11 @@ public Builder testBundle(String testBundle) {
118121
return this;
119122
}
120123

124+
public Builder customTag(String key, String value) {
125+
this.customTags.put(key, value);
126+
return this;
127+
}
128+
121129
public TracerEnvironment build() {
122130
return new TracerEnvironment(
123131
service,
@@ -133,7 +141,8 @@ public TracerEnvironment build() {
133141
runtimeVersion,
134142
runtimeVendor,
135143
runtimeArchitecture,
136-
testBundle));
144+
testBundle,
145+
customTags));
137146
}
138147
}
139148
}

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/config/ConfigurationApiImplTest.groovy

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ class ConfigurationApiImplTest extends Specification {
4747
"runtime.name" : "runtimeName",
4848
"runtime.version" : "runtimeVersion",
4949
"runtime.vendor" : "vendor",
50-
"runtime.architecture": "amd64"
50+
"runtime.architecture": "amd64",
51+
"custom": [
52+
"customTag": "customValue"
53+
]
5154
]
5255
]
5356
]
@@ -80,7 +83,10 @@ class ConfigurationApiImplTest extends Specification {
8083
"runtime.name" : "runtimeName",
8184
"runtime.version" : "runtimeVersion",
8285
"runtime.vendor" : "vendor",
83-
"runtime.architecture": "amd64"
86+
"runtime.architecture": "amd64",
87+
"custom": [
88+
"customTag": "customValue"
89+
]
8490
]
8591
]
8692
]
@@ -89,9 +95,9 @@ class ConfigurationApiImplTest extends Specification {
8995
if (expectedRequest) {
9096
response.status(200).send('{ "data": [' +
9197
'{ "id": "49968354e2091cdb", "type": "test", "attributes": ' +
92-
'{ "configurations": { "test.bundle": "testBundle-a" }, "suite": "suite-a", "name": "name-a", "parameters": "parameters-a" } },' +
98+
'{ "configurations": { "test.bundle": "testBundle-a", "custom": { "customTag": "customValue" } }, "suite": "suite-a", "name": "name-a", "parameters": "parameters-a" } },' +
9399
'{ "id": "49968354e2091cdc", "type": "test", "attributes": ' +
94-
' { "configurations": { "test.bundle": "testBundle-b" }, "suite": "suite-b", "name": "name-b", "parameters": "parameters-b" } }' +
100+
' { "configurations": { "test.bundle": "testBundle-b", "custom": { "customTag": "customValue" } }, "suite": "suite-b", "name": "name-b", "parameters": "parameters-b" } }' +
95101
'] }')
96102
} else {
97103
response.status(400).send()
@@ -127,10 +133,10 @@ class ConfigurationApiImplTest extends Specification {
127133
skippableTests == [
128134
new SkippableTest("suite-a", "name-a", "parameters-a",
129135
new Configurations(null, null, null, null, null,
130-
null, null, "testBundle-a")),
136+
null, null, "testBundle-a", Collections.singletonMap("customTag", "customValue"))),
131137
new SkippableTest("suite-b", "name-b", "parameters-b",
132138
new Configurations(null, null, null, null, null,
133-
null, null, "testBundle-b"))
139+
null, null, "testBundle-b", Collections.singletonMap("customTag", "customValue")))
134140
]
135141
}
136142

@@ -156,6 +162,7 @@ class ConfigurationApiImplTest extends Specification {
156162
.runtimeVersion("runtimeVersion")
157163
.runtimeVendor("vendor")
158164
.runtimeArchitecture("amd64")
165+
.customTag("customTag", "customValue")
159166
.build()
160167
}
161168
}

dd-smoke-tests/maven/src/test/groovy/datadog/smoketest/MavenSmokeTest.groovy

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
package datadog.smoketest
22

3+
34
import com.fasterxml.jackson.databind.ObjectMapper
45
import datadog.trace.agent.test.server.http.TestHttpServer
56
import datadog.trace.api.Config
67
import datadog.trace.api.config.CiVisibilityConfig
78
import datadog.trace.api.config.GeneralConfig
89
import datadog.trace.test.util.MultipartRequestParser
910
import datadog.trace.util.Strings
11+
import okhttp3.OkHttpClient
12+
import okhttp3.Request
13+
import okhttp3.Response
1014
import org.apache.maven.wrapper.MavenWrapperMain
1115
import org.msgpack.jackson.dataformat.MessagePackFactory
16+
import org.slf4j.Logger
17+
import org.slf4j.LoggerFactory
18+
import org.w3c.dom.Document
19+
import org.w3c.dom.NodeList
1220
import spock.lang.AutoCleanup
1321
import spock.lang.Shared
1422
import spock.lang.Specification
1523
import spock.lang.TempDir
1624
import spock.util.concurrent.PollingConditions
1725

26+
import javax.xml.parsers.DocumentBuilder
27+
import javax.xml.parsers.DocumentBuilderFactory
1828
import java.nio.file.FileVisitResult
1929
import java.nio.file.Files
2030
import java.nio.file.Path
@@ -31,6 +41,35 @@ import static org.hamcrest.Matchers.not
3141

3242
class MavenSmokeTest extends Specification {
3343

44+
private static final Logger LOGGER = LoggerFactory.getLogger(MavenSmokeTest.class)
45+
46+
private static final String LATEST_MAVEN_VERSION = getLatestMavenVersion()
47+
48+
private static String getLatestMavenVersion() {
49+
OkHttpClient client = new OkHttpClient()
50+
Request request = new Request.Builder().url("https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/maven-metadata.xml").build()
51+
try (Response response = client.newCall(request).execute()) {
52+
if (response.successful) {
53+
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance()
54+
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder()
55+
Document doc = dBuilder.parse(response.body().byteStream())
56+
doc.getDocumentElement().normalize()
57+
58+
NodeList versionList = doc.getElementsByTagName("latest")
59+
if (versionList.getLength() > 0) {
60+
return versionList.item(0).getTextContent()
61+
}
62+
} else {
63+
LOGGER.warn("Could not get latest maven version, response from repo.maven.apache.org is ${response.code()}: ${response.body().string()}")
64+
}
65+
} catch (Exception e) {
66+
LOGGER.warn("Could not get latest maven version", e)
67+
}
68+
def hardcodedLatestVersion = "4.0.0-alpha-8"
69+
LOGGER.warn("Will run the 'latest' tests with hard-coded version ${hardcodedLatestVersion}")
70+
return hardcodedLatestVersion
71+
}
72+
3473
private static final String TEST_SERVICE_NAME = "test-maven-service"
3574
private static final String TEST_ENVIRONMENT_NAME = "integration-test"
3675
private static final String JAVAC_PLUGIN_VERSION = Config.get().ciVisibilityCompilerPluginVersion
@@ -80,14 +119,14 @@ class MavenSmokeTest extends Specification {
80119

81120
prefix("/api/v2/ci/tests/skippable") {
82121
response.status(200).send('{ "data": [{' +
83-
' "id": "d230520a0561ee2f",' +
84-
' "type": "test",' +
85-
' "attributes": {' +
86-
' "configurations": {},' +
87-
' "name": "test_to_skip_with_itr",' +
88-
' "suite": "datadog.smoke.TestSucceed"' +
89-
' }' +
90-
'}] }')
122+
' "id": "d230520a0561ee2f",' +
123+
' "type": "test",' +
124+
' "attributes": {' +
125+
' "configurations": {},' +
126+
' "name": "test_to_skip_with_itr",' +
127+
' "suite": "datadog.smoke.TestSucceed"' +
128+
' }' +
129+
'}] }')
91130
}
92131
}
93132
}
@@ -112,7 +151,7 @@ class MavenSmokeTest extends Specification {
112151
verifyEventsAndCoverages(mavenVersion)
113152

114153
where:
115-
mavenVersion << ["3.2.1", "3.2.5", "3.3.9", "3.5.4", "3.6.3", "3.8.8", "3.9.4", "4.0.0-alpha-7"]
154+
mavenVersion << ["3.2.1", "3.2.5", "3.3.9", "3.5.4", "3.6.3", "3.8.8", "3.9.5", LATEST_MAVEN_VERSION]
116155
}
117156

118157
def "test maven run with jacoco and argLine, v#mavenVersion"() {
@@ -130,7 +169,7 @@ class MavenSmokeTest extends Specification {
130169
verifyEventsAndCoverages(mavenVersion)
131170

132171
where:
133-
mavenVersion << ["3.9.4"]
172+
mavenVersion << ["3.9.5"]
134173
}
135174

136175
private verifyEventsAndCoverages(String mavenVersion) {
@@ -302,20 +341,20 @@ class MavenSmokeTest extends Specification {
302341

303342
private void copyFolder(Path src, Path dest) throws IOException {
304343
Files.walkFileTree(src, new SimpleFileVisitor<Path>() {
305-
@Override
306-
FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
307-
throws IOException {
308-
Files.createDirectories(dest.resolve(src.relativize(dir)))
309-
return FileVisitResult.CONTINUE
310-
}
344+
@Override
345+
FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
346+
throws IOException {
347+
Files.createDirectories(dest.resolve(src.relativize(dir)))
348+
return FileVisitResult.CONTINUE
349+
}
311350

312-
@Override
313-
FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
314-
throws IOException {
315-
Files.copy(file, dest.resolve(src.relativize(file)))
316-
return FileVisitResult.CONTINUE
317-
}
318-
})
351+
@Override
352+
FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
353+
throws IOException {
354+
Files.copy(file, dest.resolve(src.relativize(file)))
355+
return FileVisitResult.CONTINUE
356+
}
357+
})
319358

320359
// creating empty .git directory so that the tracer could detect projectFolder as repo root
321360
Files.createDirectory(projectHome.resolve(".git"))
@@ -401,16 +440,16 @@ class MavenSmokeTest extends Specification {
401440
if (runWithAgent) {
402441
def agentShadowJar = System.getProperty("datadog.smoketest.agent.shadowJar.path")
403442
def agentArgument = "-javaagent:${agentShadowJar}=" +
404-
"${Strings.propertyNameToSystemPropertyName(GeneralConfig.ENV)}=${TEST_ENVIRONMENT_NAME}," +
405-
"${Strings.propertyNameToSystemPropertyName(GeneralConfig.SERVICE_NAME)}=${TEST_SERVICE_NAME}," +
406-
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_ENABLED)}=true," +
407-
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED)}=true," +
408-
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_CIPROVIDER_INTEGRATION_ENABLED)}=false," +
409-
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_SOURCE_DATA_ROOT_CHECK_ENABLED)}=false," +
410-
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_UPLOAD_ENABLED)}=false," +
411-
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COVERAGE_SEGMENTS_ENABLED)}=true," +
412-
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COMPILER_PLUGIN_VERSION)}=${JAVAC_PLUGIN_VERSION}," +
413-
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_URL)}=${intakeServer.address.toString()}"
443+
"${Strings.propertyNameToSystemPropertyName(GeneralConfig.ENV)}=${TEST_ENVIRONMENT_NAME}," +
444+
"${Strings.propertyNameToSystemPropertyName(GeneralConfig.SERVICE_NAME)}=${TEST_SERVICE_NAME}," +
445+
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_ENABLED)}=true," +
446+
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED)}=true," +
447+
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_CIPROVIDER_INTEGRATION_ENABLED)}=false," +
448+
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_SOURCE_DATA_ROOT_CHECK_ENABLED)}=false," +
449+
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_UPLOAD_ENABLED)}=false," +
450+
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COVERAGE_SEGMENTS_ENABLED)}=true," +
451+
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COMPILER_PLUGIN_VERSION)}=${JAVAC_PLUGIN_VERSION}," +
452+
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_URL)}=${intakeServer.address.toString()}"
414453
arguments += agentArgument.toString()
415454
}
416455
return arguments

0 commit comments

Comments
 (0)