Skip to content

Commit 7108ba0

Browse files
Set test session name on test/suite/module/session events (#7603)
1 parent 57d9846 commit 7108ba0

File tree

369 files changed

+4347
-10684
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

369 files changed

+4347
-10684
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ private static BuildSystemSession.Factory buildSystemSessionFactory(
187187

188188
repoServices.gitDataUploader.startOrObserveGitDataUpload();
189189

190-
TestDecorator testDecorator = new TestDecoratorImpl(buildSystemName, repoServices.ciTags);
190+
String sessionName = services.config.getCiVisibilitySessionName();
191+
TestDecorator testDecorator =
192+
new TestDecoratorImpl(buildSystemName, sessionName, startCommand, repoServices.ciTags);
191193

192194
String signalServerHost = services.config.getCiVisibilitySignalServerHost();
193195
int signalServerPort = services.config.getCiVisibilitySignalServerPort();
@@ -223,7 +225,11 @@ private static TestFrameworkSession.Factory childTestFrameworkSessionFactory(
223225
long parentProcessSessionId = ProcessHierarchyUtils.getParentSessionId();
224226
long parentProcessModuleId = ProcessHierarchyUtils.getParentModuleId();
225227

226-
TestDecorator testDecorator = new TestDecoratorImpl(component, repoServices.ciTags);
228+
String sessionName = services.config.getCiVisibilitySessionName();
229+
String testCommand = services.config.getCiVisibilityTestCommand();
230+
TestDecorator testDecorator =
231+
new TestDecoratorImpl(component, sessionName, testCommand, repoServices.ciTags);
232+
227233
ExecutionStrategy executionStrategy =
228234
new ExecutionStrategy(services.config, executionSettings);
229235
return new ProxyTestSession(
@@ -250,7 +256,10 @@ private static TestFrameworkSession.Factory headlessTestFrameworkEssionFactory(
250256
return (String projectName, String component, Long startTime) -> {
251257
repoServices.gitDataUploader.startOrObserveGitDataUpload();
252258

253-
TestDecorator testDecorator = new TestDecoratorImpl(component, repoServices.ciTags);
259+
String sessionName = services.config.getCiVisibilitySessionName();
260+
TestDecorator testDecorator =
261+
new TestDecoratorImpl(component, sessionName, projectName, repoServices.ciTags);
262+
254263
ExecutionStrategy executionStrategy =
255264
new ExecutionStrategy(services.config, executionSettings);
256265
return new HeadlessTestSession(
@@ -272,7 +281,11 @@ private static CIVisibility.SessionFactory manualApiSessionFactory(
272281
CiVisibilityServices services) {
273282
return (String projectName, Path projectRoot, String component, Long startTime) -> {
274283
CiVisibilityRepoServices repoServices = services.repoServices(projectRoot);
275-
TestDecorator testDecorator = new TestDecoratorImpl(component, repoServices.ciTags);
284+
285+
String sessionName = services.config.getCiVisibilitySessionName();
286+
TestDecorator testDecorator =
287+
new TestDecoratorImpl(component, sessionName, projectName, repoServices.ciTags);
288+
276289
ExecutionSettings executionSettings =
277290
repoServices.executionSettingsFactory.create(JvmInfo.CURRENT_JVM, null);
278291
CiVisibilityCoverageServices.Child coverageServices =

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

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

33
import datadog.trace.api.Config;
4+
import datadog.trace.api.civisibility.CiVisibilityWellKnownTags;
45
import datadog.trace.api.civisibility.config.TestIdentifier;
56
import datadog.trace.api.civisibility.config.TestMetadata;
67
import datadog.trace.api.git.GitInfo;
@@ -79,19 +80,16 @@ private TracerEnvironment buildTracerEnvironment(
7980
}
8081
}
8182

82-
/*
83-
* IMPORTANT: JVM and OS properties should match tags
84-
* set in datadog.trace.civisibility.decorator.TestDecoratorImpl
85-
*/
83+
CiVisibilityWellKnownTags wellKnownTags = config.getCiVisibilityWellKnownTags();
8684
return builder
8785
.service(config.getServiceName())
8886
.env(config.getEnv())
8987
.repositoryUrl(gitInfo.getRepositoryURL())
9088
.branch(gitInfo.getBranch())
9189
.sha(gitInfo.getCommit().getSha())
92-
.osPlatform(System.getProperty("os.name"))
93-
.osArchitecture(System.getProperty("os.arch"))
94-
.osVersion(System.getProperty("os.version"))
90+
.osPlatform(wellKnownTags.getOsPlatform().toString())
91+
.osArchitecture(wellKnownTags.getOsArch().toString())
92+
.osVersion(wellKnownTags.getOsVersion().toString())
9593
.runtimeName(jvmInfo.getName())
9694
.runtimeVersion(jvmInfo.getVersion())
9795
.runtimeVendor(jvmInfo.getVendor())

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
package datadog.trace.civisibility.config;
22

3+
import datadog.trace.api.Config;
4+
import datadog.trace.api.civisibility.CiVisibilityWellKnownTags;
35
import datadog.trace.civisibility.ipc.Serializer;
46
import java.nio.ByteBuffer;
57
import java.util.Objects;
68

79
public class JvmInfo {
810

9-
public static final JvmInfo CURRENT_JVM =
10-
new JvmInfo(
11-
System.getProperty("java.runtime.name"),
12-
System.getProperty("java.version"),
13-
System.getProperty("java.vendor"));
11+
public static final JvmInfo CURRENT_JVM;
12+
13+
static {
14+
Config config = Config.get();
15+
CiVisibilityWellKnownTags wellKnownTags = config.getCiVisibilityWellKnownTags();
16+
CURRENT_JVM =
17+
new JvmInfo(
18+
wellKnownTags.getRuntimeName().toString(),
19+
wellKnownTags.getRuntimeVersion().toString(),
20+
wellKnownTags.getRuntimeVendor().toString());
21+
}
1422

1523
private final String name;
1624
private final String version;

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/decorator/TestDecoratorImpl.java

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,34 @@
55
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
66
import datadog.trace.bootstrap.instrumentation.api.Tags;
77
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
8-
import datadog.trace.civisibility.config.JvmInfo;
8+
import datadog.trace.util.Strings;
99
import java.util.Map;
1010

1111
public class TestDecoratorImpl implements TestDecorator {
1212

1313
private static final UTF8BytesString CIAPP_TEST_ORIGIN = UTF8BytesString.create("ciapp-test");
1414

1515
private final String component;
16+
private final String sessionName;
1617
private final Map<String, String> ciTags;
1718

18-
public TestDecoratorImpl(String component, Map<String, String> ciTags) {
19+
public TestDecoratorImpl(
20+
String component, String sessionName, String testCommand, Map<String, String> ciTags) {
1921
this.component = component;
2022
this.ciTags = ciTags;
23+
if (Strings.isNotBlank(sessionName)) {
24+
this.sessionName = sessionName;
25+
} else {
26+
String ciJobName = ciTags.get(Tags.CI_JOB_NAME);
27+
this.sessionName =
28+
Strings.isNotBlank(ciJobName) ? ciJobName + "-" + testCommand : testCommand;
29+
}
2130
}
2231

2332
protected String testType() {
2433
return TEST_TYPE;
2534
}
2635

27-
protected String runtimeName() {
28-
return JvmInfo.CURRENT_JVM.getName();
29-
}
30-
31-
protected String runtimeVendor() {
32-
return JvmInfo.CURRENT_JVM.getVendor();
33-
}
34-
35-
protected String runtimeVersion() {
36-
return JvmInfo.CURRENT_JVM.getVersion();
37-
}
38-
39-
protected String osArch() {
40-
return System.getProperty("os.arch");
41-
}
42-
43-
protected String osPlatform() {
44-
return System.getProperty("os.name");
45-
}
46-
47-
protected String osVersion() {
48-
return System.getProperty("os.version");
49-
}
50-
5136
protected UTF8BytesString origin() {
5237
return CIAPP_TEST_ORIGIN;
5338
}
@@ -59,24 +44,11 @@ public CharSequence component() {
5944

6045
@Override
6146
public AgentSpan afterStart(final AgentSpan span) {
62-
/*
63-
* IMPORTANT: JVM and OS tags should match properties
64-
* set in datadog.trace.civisibility.config.ExecutionSettingsFactory
65-
*
66-
* Moreover, logic that populates these tags cannot be changed,
67-
* as they are used to establish correspondence between
68-
* executions of the same test case
69-
*/
70-
span.setTag(Tags.TEST_TYPE, testType());
7147
span.setSamplingPriority(PrioritySampling.SAMPLER_KEEP);
72-
span.setTag(Tags.RUNTIME_NAME, runtimeName());
73-
span.setTag(Tags.RUNTIME_VENDOR, runtimeVendor());
74-
span.setTag(Tags.RUNTIME_VERSION, runtimeVersion());
75-
span.setTag(Tags.OS_ARCHITECTURE, osArch());
76-
span.setTag(Tags.OS_PLATFORM, osPlatform());
77-
span.setTag(Tags.OS_VERSION, osVersion());
7848
span.setTag(DDTags.ORIGIN_KEY, CIAPP_TEST_ORIGIN);
49+
span.setTag(Tags.TEST_TYPE, testType());
7950
span.setTag(Tags.COMPONENT, component());
51+
span.setTag(Tags.TEST_SESSION_NAME, sessionName);
8052

8153
for (final Map.Entry<String, String> ciTag : ciTags.entrySet()) {
8254
span.setTag(ciTag.getKey(), ciTag.getValue());

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/buildsystem/BuildSystemModuleImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public <T extends CoverageCalculator> BuildSystemModuleImpl(
9898
new BuildModuleSettings(
9999
getPropertiesPropagatedToChildProcess(
100100
moduleName,
101+
startCommand,
101102
classpath,
102103
jacocoAgent,
103104
signalServerAddress,
@@ -109,6 +110,7 @@ public <T extends CoverageCalculator> BuildSystemModuleImpl(
109110

110111
private Map<String, String> getPropertiesPropagatedToChildProcess(
111112
String moduleName,
113+
String startCommand,
112114
@Nullable Collection<Path> classpath,
113115
@Nullable JavaAgent jacocoAgent,
114116
InetSocketAddress signalServerAddress,
@@ -172,6 +174,9 @@ private Map<String, String> getPropertiesPropagatedToChildProcess(
172174
propagatedSystemProperties.put(
173175
Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_MODULE_NAME),
174176
moduleName);
177+
propagatedSystemProperties.put(
178+
Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_TEST_COMMAND),
179+
startCommand);
175180

176181
propagatedSystemProperties.put(
177182
Strings.propertyNameToSystemPropertyName(

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/decorator/TestDecoratorImplTest.groovy

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,16 @@ class TestDecoratorImplTest extends Specification {
1212

1313
def "test afterStart"() {
1414
setup:
15-
def decorator = newDecorator()
15+
def decorator = new TestDecoratorImpl("test-component", "session-name", "test-command", ["ci-tag-1": "value", "ci-tag-2": "another value"])
1616

1717
when:
1818
decorator.afterStart(span)
1919

2020
then:
21+
1 * span.setTag(Tags.TEST_SESSION_NAME, "session-name")
2122
1 * span.setTag(Tags.COMPONENT, "test-component")
2223
1 * span.setTag(Tags.TEST_TYPE, decorator.testType())
2324
1 * span.setSamplingPriority(PrioritySampling.SAMPLER_KEEP)
24-
1 * span.setTag(Tags.RUNTIME_NAME, decorator.runtimeName())
25-
1 * span.setTag(Tags.RUNTIME_VENDOR, decorator.runtimeVendor())
26-
1 * span.setTag(Tags.RUNTIME_VERSION, decorator.runtimeVersion())
27-
1 * span.setTag(Tags.OS_ARCHITECTURE, decorator.osArch())
28-
1 * span.setTag(Tags.OS_PLATFORM, decorator.osPlatform())
29-
1 * span.setTag(Tags.OS_VERSION, decorator.osVersion())
3025
1 * span.setTag(DDTags.ORIGIN_KEY, decorator.origin())
3126
1 * span.setTag("ci-tag-1", "value")
3227
1 * span.setTag("ci-tag-2", "another value")
@@ -40,7 +35,20 @@ class TestDecoratorImplTest extends Specification {
4035
serviceName << ["test-service", "other-service", null]
4136
}
4237

43-
static newDecorator() {
44-
new TestDecoratorImpl("test-component", ["ci-tag-1": "value", "ci-tag-2": "another value"])
38+
def "test session name: #sessionName, #ciJobName, #testCommand"() {
39+
setup:
40+
def decorator = new TestDecoratorImpl("test-component", sessionName, testCommand, [(Tags.CI_JOB_NAME): ciJobName])
41+
42+
when:
43+
decorator.afterStart(span)
44+
45+
then:
46+
1 * span.setTag(Tags.TEST_SESSION_NAME, expectedSessionName)
47+
48+
where:
49+
sessionName | ciJobName | testCommand | expectedSessionName
50+
"session-name" | "ci-job-name" | "test-command" | "session-name"
51+
null | "ci-job-name" | "test-command" | "ci-job-name-test-command"
52+
null | null | "test-command" | "test-command"
4553
}
4654
}

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/domain/TestImplTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class TestImplTest extends DDSpecification {
135135
def testFramework = TestFrameworkInstrumentation.OTHER
136136
def config = Config.get()
137137
def metricCollector = Stub(CiVisibilityMetricCollectorImpl)
138-
def testDecorator = new TestDecoratorImpl("component", [:])
138+
def testDecorator = new TestDecoratorImpl("component", "session-name", "test-command", [:])
139139
def methodLinesResolver = { it -> MethodLinesResolver.MethodLines.EMPTY }
140140
def codeowners = NoCodeowners.INSTANCE
141141
new TestImpl(

dd-java-agent/agent-ci-visibility/src/testFixtures/groovy/datadog/trace/civisibility/CiVisibilityInstrumentationTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ abstract class CiVisibilityInstrumentationTest extends AgentTestRunner {
129129
TestFrameworkSession.Factory testFrameworkSessionFactory = (String projectName, String component, Long startTime) -> {
130130
def config = Config.get()
131131
def ciTags = [(DUMMY_CI_TAG): DUMMY_CI_TAG_VALUE]
132-
TestDecorator testDecorator = new TestDecoratorImpl(component, ciTags)
132+
TestDecorator testDecorator = new TestDecoratorImpl(component, "session-name", "test-command", ciTags)
133133
return new HeadlessTestSession(
134134
projectName,
135135
startTime,
@@ -150,7 +150,7 @@ abstract class CiVisibilityInstrumentationTest extends AgentTestRunner {
150150
BuildSystemSession.Factory buildSystemSessionFactory = (String projectName, Path projectRoot, String startCommand, String component, Long startTime) -> {
151151
def config = Config.get()
152152
def ciTags = [(DUMMY_CI_TAG): DUMMY_CI_TAG_VALUE]
153-
TestDecorator testDecorator = new TestDecoratorImpl(component, ciTags)
153+
TestDecorator testDecorator = new TestDecoratorImpl(component, "session-name", "test-command", ciTags)
154154
ModuleSignalRouter moduleSignalRouter = new ModuleSignalRouter()
155155
SignalServer signalServer = new SignalServer()
156156
RepoIndexBuilder repoIndexBuilder = Stub(RepoIndexBuilder)
@@ -269,7 +269,7 @@ abstract class CiVisibilityInstrumentationTest extends AgentTestRunner {
269269
}
270270

271271
def getEventsAsJson(List<List<DDSpan>> traces) {
272-
return getSpansAsJson(new CiTestCycleMapperV1(Config.get().getWellKnownTags(), false), traces)
272+
return getSpansAsJson(new CiTestCycleMapperV1(Config.get().getCiVisibilityWellKnownTags(), false), traces)
273273
}
274274

275275
def getCoveragesAsJson(List<List<DDSpan>> traces) {

dd-java-agent/agent-ci-visibility/src/testFixtures/groovy/datadog/trace/civisibility/CiVisibilityTestUtils.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ abstract class CiVisibilityTestUtils {
3636
path("content.meta.['error.message']"),
3737
path("content.meta.library_version"),
3838
path("content.meta.runtime-id"),
39+
path("content.meta.['_dd.tracer_host']"),
3940
// Different events might or might not have the same start or duration.
4041
// Regardless, the values of these fields should be treated as different
4142
path("content.start", false),

dd-java-agent/instrumentation/junit-4.10/cucumber-junit-4/src/test/resources/test-efd-known-test/coverages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"files" : [ {
66
"filename" : "org/example/cucumber/calculator/basic_arithmetic.feature"
77
} ]
8-
} ]
8+
} ]

0 commit comments

Comments
 (0)