Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom test fingerprint tags to ITR requests #6195

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.squareup.moshi.Json;
import com.squareup.moshi.ToJson;
import datadog.trace.api.civisibility.config.Configurations;
import java.util.Map;

public final class ConfigurationsJson {
@Json(name = "os.platform")
Expand Down Expand Up @@ -33,6 +34,9 @@ public final class ConfigurationsJson {
@Json(name = "test.bundle")
private final String testBundle;

@Json(name = "custom")
private final Map<String, String> custom;

public ConfigurationsJson(
String osPlatform,
String osArchitecture,
Expand All @@ -41,7 +45,8 @@ public ConfigurationsJson(
String runtimeVersion,
String runtimeVendor,
String runtimeArchitecture,
String testBundle) {
String testBundle,
Map<String, String> custom) {
this.osPlatform = osPlatform;
osArch = osArchitecture;
this.osArchitecture = osArchitecture;
Expand All @@ -51,6 +56,7 @@ public ConfigurationsJson(
this.runtimeVendor = runtimeVendor;
this.runtimeArchitecture = runtimeArchitecture;
this.testBundle = testBundle;
this.custom = custom;
}

public static final class ConfigurationsJsonAdapter {
Expand All @@ -64,7 +70,8 @@ public Configurations fromJson(ConfigurationsJson configurationsJson) {
configurationsJson.runtimeVersion,
configurationsJson.runtimeVendor,
configurationsJson.runtimeArchitecture,
configurationsJson.testBundle);
configurationsJson.testBundle,
configurationsJson.custom);
}

@ToJson
Expand All @@ -77,7 +84,8 @@ public ConfigurationsJson toJson(Configurations configurations) {
configurations.getRuntimeVersion(),
configurations.getRuntimeVendor(),
configurations.getRuntimeArchitecture(),
configurations.getTestBundle());
configurations.getTestBundle(),
configurations.getCustom());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ModuleExecutionSettingsFactoryImpl implements ModuleExecutionSettin

private static final Logger LOGGER =
LoggerFactory.getLogger(ModuleExecutionSettingsFactoryImpl.class);
private static final String TEST_CONFIGURATION_TAG_PREFIX = "test.configuration.";

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

TracerEnvironment.Builder builder = TracerEnvironment.builder();
for (Map.Entry<String, String> e : config.getGlobalTags().entrySet()) {
String key = e.getKey();
if (key.startsWith(TEST_CONFIGURATION_TAG_PREFIX)) {
String configurationKey = key.substring(TEST_CONFIGURATION_TAG_PREFIX.length());
String configurationValue = e.getValue();
builder.customTag(configurationKey, configurationValue);
}
}

/*
* IMPORTANT: JVM and OS properties should match tags
* set in datadog.trace.civisibility.decorator.TestDecorator
*/
return TracerEnvironment.builder()
return builder
.service(config.getServiceName())
.env(config.getEnv())
.repositoryUrl(gitInfo.getRepositoryURL())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.squareup.moshi.Json;
import datadog.trace.api.civisibility.config.Configurations;
import java.util.HashMap;
import java.util.Map;

public class TracerEnvironment {

Expand Down Expand Up @@ -52,6 +54,7 @@ public static final class Builder {
private String runtimeVendor;
private String runtimeArchitecture;
private String testBundle;
private final Map<String, String> customTags = new HashMap<>();

public Builder service(String service) {
this.service = service;
Expand Down Expand Up @@ -118,6 +121,11 @@ public Builder testBundle(String testBundle) {
return this;
}

public Builder customTag(String key, String value) {
this.customTags.put(key, value);
return this;
}

public TracerEnvironment build() {
return new TracerEnvironment(
service,
Expand All @@ -133,7 +141,8 @@ public TracerEnvironment build() {
runtimeVersion,
runtimeVendor,
runtimeArchitecture,
testBundle));
testBundle,
customTags));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class ConfigurationApiImplTest extends Specification {
"runtime.name" : "runtimeName",
"runtime.version" : "runtimeVersion",
"runtime.vendor" : "vendor",
"runtime.architecture": "amd64"
"runtime.architecture": "amd64",
"custom": [
"customTag": "customValue"
]
]
]
]
Expand Down Expand Up @@ -80,7 +83,10 @@ class ConfigurationApiImplTest extends Specification {
"runtime.name" : "runtimeName",
"runtime.version" : "runtimeVersion",
"runtime.vendor" : "vendor",
"runtime.architecture": "amd64"
"runtime.architecture": "amd64",
"custom": [
"customTag": "customValue"
]
]
]
]
Expand All @@ -89,9 +95,9 @@ class ConfigurationApiImplTest extends Specification {
if (expectedRequest) {
response.status(200).send('{ "data": [' +
'{ "id": "49968354e2091cdb", "type": "test", "attributes": ' +
'{ "configurations": { "test.bundle": "testBundle-a" }, "suite": "suite-a", "name": "name-a", "parameters": "parameters-a" } },' +
'{ "configurations": { "test.bundle": "testBundle-a", "custom": { "customTag": "customValue" } }, "suite": "suite-a", "name": "name-a", "parameters": "parameters-a" } },' +
'{ "id": "49968354e2091cdc", "type": "test", "attributes": ' +
' { "configurations": { "test.bundle": "testBundle-b" }, "suite": "suite-b", "name": "name-b", "parameters": "parameters-b" } }' +
' { "configurations": { "test.bundle": "testBundle-b", "custom": { "customTag": "customValue" } }, "suite": "suite-b", "name": "name-b", "parameters": "parameters-b" } }' +
'] }')
} else {
response.status(400).send()
Expand Down Expand Up @@ -127,10 +133,10 @@ class ConfigurationApiImplTest extends Specification {
skippableTests == [
new SkippableTest("suite-a", "name-a", "parameters-a",
new Configurations(null, null, null, null, null,
null, null, "testBundle-a")),
null, null, "testBundle-a", Collections.singletonMap("customTag", "customValue"))),
new SkippableTest("suite-b", "name-b", "parameters-b",
new Configurations(null, null, null, null, null,
null, null, "testBundle-b"))
null, null, "testBundle-b", Collections.singletonMap("customTag", "customValue")))
]
}

Expand All @@ -156,6 +162,7 @@ class ConfigurationApiImplTest extends Specification {
.runtimeVersion("runtimeVersion")
.runtimeVendor("vendor")
.runtimeArchitecture("amd64")
.customTag("customTag", "customValue")
.build()
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
package datadog.smoketest


import com.fasterxml.jackson.databind.ObjectMapper
import datadog.trace.agent.test.server.http.TestHttpServer
import datadog.trace.api.Config
import datadog.trace.api.config.CiVisibilityConfig
import datadog.trace.api.config.GeneralConfig
import datadog.trace.test.util.MultipartRequestParser
import datadog.trace.util.Strings
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.apache.maven.wrapper.MavenWrapperMain
import org.msgpack.jackson.dataformat.MessagePackFactory
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.w3c.dom.Document
import org.w3c.dom.NodeList
import spock.lang.AutoCleanup
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.TempDir
import spock.util.concurrent.PollingConditions

import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.DocumentBuilderFactory
import java.nio.file.FileVisitResult
import java.nio.file.Files
import java.nio.file.Path
Expand All @@ -31,6 +41,35 @@ import static org.hamcrest.Matchers.not

class MavenSmokeTest extends Specification {

private static final Logger LOGGER = LoggerFactory.getLogger(MavenSmokeTest.class)

private static final String LATEST_MAVEN_VERSION = getLatestMavenVersion()

private static String getLatestMavenVersion() {
OkHttpClient client = new OkHttpClient()
Request request = new Request.Builder().url("https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/maven-metadata.xml").build()
try (Response response = client.newCall(request).execute()) {
if (response.successful) {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance()
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder()
Document doc = dBuilder.parse(response.body().byteStream())
doc.getDocumentElement().normalize()

NodeList versionList = doc.getElementsByTagName("latest")
if (versionList.getLength() > 0) {
return versionList.item(0).getTextContent()
}
} else {
LOGGER.warn("Could not get latest maven version, response from repo.maven.apache.org is ${response.code()}: ${response.body().string()}")
}
} catch (Exception e) {
LOGGER.warn("Could not get latest maven version", e)
}
def hardcodedLatestVersion = "4.0.0-alpha-8"
LOGGER.warn("Will run the 'latest' tests with hard-coded version ${hardcodedLatestVersion}")
return hardcodedLatestVersion
}

private static final String TEST_SERVICE_NAME = "test-maven-service"
private static final String TEST_ENVIRONMENT_NAME = "integration-test"
private static final String JAVAC_PLUGIN_VERSION = Config.get().ciVisibilityCompilerPluginVersion
Expand Down Expand Up @@ -80,14 +119,14 @@ class MavenSmokeTest extends Specification {

prefix("/api/v2/ci/tests/skippable") {
response.status(200).send('{ "data": [{' +
' "id": "d230520a0561ee2f",' +
' "type": "test",' +
' "attributes": {' +
' "configurations": {},' +
' "name": "test_to_skip_with_itr",' +
' "suite": "datadog.smoke.TestSucceed"' +
' }' +
'}] }')
' "id": "d230520a0561ee2f",' +
' "type": "test",' +
' "attributes": {' +
' "configurations": {},' +
' "name": "test_to_skip_with_itr",' +
' "suite": "datadog.smoke.TestSucceed"' +
' }' +
'}] }')
}
}
}
Expand All @@ -112,7 +151,7 @@ class MavenSmokeTest extends Specification {
verifyEventsAndCoverages(mavenVersion)

where:
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"]
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]
}

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

where:
mavenVersion << ["3.9.4"]
mavenVersion << ["3.9.5"]
}

private verifyEventsAndCoverages(String mavenVersion) {
Expand Down Expand Up @@ -302,20 +341,20 @@ class MavenSmokeTest extends Specification {

private void copyFolder(Path src, Path dest) throws IOException {
Files.walkFileTree(src, new SimpleFileVisitor<Path>() {
@Override
FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
throws IOException {
Files.createDirectories(dest.resolve(src.relativize(dir)))
return FileVisitResult.CONTINUE
}
@Override
FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
throws IOException {
Files.createDirectories(dest.resolve(src.relativize(dir)))
return FileVisitResult.CONTINUE
}

@Override
FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
Files.copy(file, dest.resolve(src.relativize(file)))
return FileVisitResult.CONTINUE
}
})
@Override
FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
Files.copy(file, dest.resolve(src.relativize(file)))
return FileVisitResult.CONTINUE
}
})

// creating empty .git directory so that the tracer could detect projectFolder as repo root
Files.createDirectory(projectHome.resolve(".git"))
Expand Down Expand Up @@ -401,16 +440,16 @@ class MavenSmokeTest extends Specification {
if (runWithAgent) {
def agentShadowJar = System.getProperty("datadog.smoketest.agent.shadowJar.path")
def agentArgument = "-javaagent:${agentShadowJar}=" +
"${Strings.propertyNameToSystemPropertyName(GeneralConfig.ENV)}=${TEST_ENVIRONMENT_NAME}," +
"${Strings.propertyNameToSystemPropertyName(GeneralConfig.SERVICE_NAME)}=${TEST_SERVICE_NAME}," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_ENABLED)}=true," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED)}=true," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_CIPROVIDER_INTEGRATION_ENABLED)}=false," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_SOURCE_DATA_ROOT_CHECK_ENABLED)}=false," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_UPLOAD_ENABLED)}=false," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COVERAGE_SEGMENTS_ENABLED)}=true," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COMPILER_PLUGIN_VERSION)}=${JAVAC_PLUGIN_VERSION}," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_URL)}=${intakeServer.address.toString()}"
"${Strings.propertyNameToSystemPropertyName(GeneralConfig.ENV)}=${TEST_ENVIRONMENT_NAME}," +
"${Strings.propertyNameToSystemPropertyName(GeneralConfig.SERVICE_NAME)}=${TEST_SERVICE_NAME}," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_ENABLED)}=true," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED)}=true," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_CIPROVIDER_INTEGRATION_ENABLED)}=false," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_SOURCE_DATA_ROOT_CHECK_ENABLED)}=false," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_UPLOAD_ENABLED)}=false," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COVERAGE_SEGMENTS_ENABLED)}=true," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_COMPILER_PLUGIN_VERSION)}=${JAVAC_PLUGIN_VERSION}," +
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_URL)}=${intakeServer.address.toString()}"
arguments += agentArgument.toString()
}
return arguments
Expand Down
Loading
Loading