Skip to content

Commit 96110c6

Browse files
set test management tag if enabled on session end rebase fix
1 parent 3f1837b commit 96110c6

File tree

10 files changed

+116
-18
lines changed

10 files changed

+116
-18
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class BuildSystemModuleImpl extends AbstractTestModule implements BuildSy
4646

4747
private final LongAdder testsSkipped = new LongAdder();
4848

49-
private volatile boolean codeCoverageEnabled;
5049
private volatile boolean testSkippingEnabled;
5150

5251
public <T extends CoverageCalculator> BuildSystemModuleImpl(
@@ -168,6 +167,10 @@ private Map<String, String> getPropertiesPropagatedToChildProcess(
168167
CiVisibilityConfig.CIVISIBILITY_EARLY_FLAKE_DETECTION_ENABLED),
169168
Boolean.toString(executionSettings.getEarlyFlakeDetectionSettings().isEnabled()));
170169

170+
propagatedSystemProperties.put(
171+
Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.TEST_MANAGEMENT_ENABLED),
172+
Boolean.toString(executionSettings.getTestManagementSettings().isEnabled()));
173+
171174
// explicitly disable build instrumentation in child processes,
172175
// because some projects run "embedded" Maven/Gradle builds as part of their integration tests,
173176
// and we don't want to show those as if they were regular build executions
@@ -252,7 +255,7 @@ public BuildModuleSettings getSettings() {
252255
*/
253256
private SignalResponse onModuleExecutionResultReceived(ModuleExecutionResult result) {
254257
if (result.isCoverageEnabled()) {
255-
codeCoverageEnabled = true;
258+
setTag(Tags.TEST_CODE_COVERAGE_ENABLED, true);
256259
}
257260
if (result.isTestSkippingEnabled()) {
258261
testSkippingEnabled = true;
@@ -264,6 +267,10 @@ private SignalResponse onModuleExecutionResultReceived(ModuleExecutionResult res
264267
}
265268
}
266269

270+
if (result.isTestManagementEnabled()) {
271+
setTag(Tags.TEST_TEST_MANAGEMENT_ENABLED, true);
272+
}
273+
267274
testsSkipped.add(result.getTestsSkippedTotal());
268275

269276
SpanUtils.mergeTestFrameworks(span, result.getTestFrameworks());
@@ -273,10 +280,6 @@ private SignalResponse onModuleExecutionResultReceived(ModuleExecutionResult res
273280

274281
@Override
275282
public void end(@Nullable Long endTime) {
276-
if (codeCoverageEnabled) {
277-
setTag(Tags.TEST_CODE_COVERAGE_ENABLED, true);
278-
}
279-
280283
if (testSkippingEnabled) {
281284
setTag(Tags.TEST_ITR_TESTS_SKIPPING_ENABLED, true);
282285
setTag(Tags.TEST_ITR_TESTS_SKIPPING_TYPE, "test");

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ private void onModuleFinish(AgentSpan moduleSpan) {
195195
SpanUtils.propagateTag(span, moduleSpan, Tags.TEST_ITR_TESTS_SKIPPING_TYPE);
196196
SpanUtils.propagateTag(span, moduleSpan, Tags.TEST_ITR_TESTS_SKIPPING_COUNT, Long::sum);
197197
SpanUtils.propagateTag(span, moduleSpan, DDTags.CI_ITR_TESTS_SKIPPED, Boolean::logicalOr);
198+
199+
SpanUtils.propagateTag(span, moduleSpan, Tags.TEST_TEST_MANAGEMENT_ENABLED, Boolean::logicalOr);
198200
}
199201
}
200202

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import datadog.trace.civisibility.codeowners.Codeowners;
1616
import datadog.trace.civisibility.config.EarlyFlakeDetectionSettings;
1717
import datadog.trace.civisibility.config.ExecutionSettings;
18+
import datadog.trace.civisibility.config.TestManagementSettings;
1819
import datadog.trace.civisibility.coverage.percentage.child.ChildProcessCoverageReporter;
1920
import datadog.trace.civisibility.decorator.TestDecorator;
2021
import datadog.trace.civisibility.domain.InstrumentationType;
@@ -148,6 +149,8 @@ private void sendModuleExecutionResult() {
148149
boolean earlyFlakeDetectionEnabled = earlyFlakeDetectionSettings.isEnabled();
149150
boolean earlyFlakeDetectionFaulty =
150151
earlyFlakeDetectionEnabled && executionStrategy.isEFDLimitReached();
152+
TestManagementSettings testManagementSettings = executionSettings.getTestManagementSettings();
153+
boolean testManagementEnabled = testManagementSettings.isEnabled();
151154
long testsSkippedTotal = executionResults.getTestsSkippedByItr();
152155

153156
signalClient.send(
@@ -158,6 +161,7 @@ private void sendModuleExecutionResult() {
158161
testSkippingEnabled,
159162
earlyFlakeDetectionEnabled,
160163
earlyFlakeDetectionFaulty,
164+
testManagementEnabled,
161165
testsSkippedTotal,
162166
new TreeSet<>(testFrameworks)));
163167

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/domain/headless/HeadlessTestSession.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,13 @@ protected Collection<TagValue> additionalTelemetryTags() {
101101
}
102102
return Collections.emptySet();
103103
}
104+
105+
@Override
106+
public void end(@Nullable Long endTime) {
107+
if (executionStrategy.getExecutionSettings().getTestManagementSettings().isEnabled()) {
108+
span.setTag(Tags.TEST_TEST_MANAGEMENT_ENABLED, true);
109+
}
110+
111+
super.end(endTime);
112+
}
104113
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ public class ModuleExecutionResult extends ModuleSignal {
1212
private static final int TEST_SKIPPING_ENABLED_FLAG = 2;
1313
private static final int EARLY_FLAKE_DETECTION_ENABLED_FLAG = 4;
1414
private static final int EARLY_FLAKE_DETECTION_FAULTY_FLAG = 8;
15+
private static final int TEST_MANAGEMENT_ENABLED_FLAG = 16;
1516

1617
private final boolean coverageEnabled;
1718
private final boolean testSkippingEnabled;
1819
private final boolean earlyFlakeDetectionEnabled;
1920
private final boolean earlyFlakeDetectionFaulty;
21+
private final boolean testManagementEnabled;
2022
private final long testsSkippedTotal;
2123
private final Collection<TestFramework> testFrameworks;
2224

@@ -27,13 +29,15 @@ public ModuleExecutionResult(
2729
boolean testSkippingEnabled,
2830
boolean earlyFlakeDetectionEnabled,
2931
boolean earlyFlakeDetectionFaulty,
32+
boolean testManagementEnabled,
3033
long testsSkippedTotal,
3134
Collection<TestFramework> testFrameworks) {
3235
super(sessionId, moduleId);
3336
this.coverageEnabled = coverageEnabled;
3437
this.testSkippingEnabled = testSkippingEnabled;
3538
this.earlyFlakeDetectionEnabled = earlyFlakeDetectionEnabled;
3639
this.earlyFlakeDetectionFaulty = earlyFlakeDetectionFaulty;
40+
this.testManagementEnabled = testManagementEnabled;
3741
this.testsSkippedTotal = testsSkippedTotal;
3842
this.testFrameworks = testFrameworks;
3943
}
@@ -54,6 +58,10 @@ public boolean isEarlyFlakeDetectionFaulty() {
5458
return earlyFlakeDetectionFaulty;
5559
}
5660

61+
public boolean isTestManagementEnabled() {
62+
return testManagementEnabled;
63+
}
64+
5765
public long getTestsSkippedTotal() {
5866
return testsSkippedTotal;
5967
}
@@ -131,6 +139,9 @@ public ByteBuffer serialize() {
131139
if (earlyFlakeDetectionFaulty) {
132140
flags |= EARLY_FLAKE_DETECTION_FAULTY_FLAG;
133141
}
142+
if (testManagementEnabled) {
143+
flags |= TEST_MANAGEMENT_ENABLED_FLAG;
144+
}
134145
s.write(flags);
135146

136147
s.write(testsSkippedTotal);
@@ -148,6 +159,7 @@ public static ModuleExecutionResult deserialize(ByteBuffer buffer) {
148159
boolean testSkippingEnabled = (flags & TEST_SKIPPING_ENABLED_FLAG) != 0;
149160
boolean earlyFlakeDetectionEnabled = (flags & EARLY_FLAKE_DETECTION_ENABLED_FLAG) != 0;
150161
boolean earlyFlakeDetectionFaulty = (flags & EARLY_FLAKE_DETECTION_FAULTY_FLAG) != 0;
162+
boolean testManagementEnabled = (flags & TEST_MANAGEMENT_ENABLED_FLAG) != 0;
151163

152164
long testsSkippedTotal = Serializer.readLong(buffer);
153165
Collection<TestFramework> testFrameworks =
@@ -160,6 +172,7 @@ public static ModuleExecutionResult deserialize(ByteBuffer buffer) {
160172
testSkippingEnabled,
161173
earlyFlakeDetectionEnabled,
162174
earlyFlakeDetectionFaulty,
175+
testManagementEnabled,
163176
testsSkippedTotal,
164177
testFrameworks);
165178
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package datadog.trace.civisibility.domain.headless
2+
3+
import datadog.trace.agent.test.asserts.ListWriterAssert
4+
import datadog.trace.api.Config
5+
import datadog.trace.api.DDSpanTypes
6+
import datadog.trace.api.civisibility.coverage.CoverageStore
7+
import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector
8+
import datadog.trace.api.civisibility.telemetry.tag.Provider
9+
import datadog.trace.bootstrap.instrumentation.api.Tags
10+
import datadog.trace.civisibility.codeowners.Codeowners
11+
import datadog.trace.civisibility.config.ExecutionSettings
12+
import datadog.trace.civisibility.config.TestManagementSettings
13+
import datadog.trace.civisibility.decorator.TestDecorator
14+
import datadog.trace.civisibility.domain.SpanWriterTest
15+
import datadog.trace.civisibility.source.LinesResolver
16+
import datadog.trace.civisibility.source.SourcePathResolver
17+
import datadog.trace.civisibility.test.ExecutionStrategy
18+
19+
class HeadlessTestSessionTest extends SpanWriterTest {
20+
21+
def "test tags are populated correctly in span"() {
22+
setup:
23+
def session = givenAHeadlessTestSession()
24+
25+
when:
26+
session.end(null)
27+
28+
then:
29+
ListWriterAssert.assertTraces(TEST_WRITER, 1, false, {
30+
trace(1) {
31+
span(0) {
32+
spanType DDSpanTypes.TEST_SESSION_END
33+
tags(false) {
34+
"$Tags.TEST_TEST_MANAGEMENT_ENABLED" true
35+
}
36+
}
37+
}
38+
})
39+
}
40+
41+
42+
private HeadlessTestSession givenAHeadlessTestSession() {
43+
def executionSettings = Stub(ExecutionSettings)
44+
executionSettings.getTestManagementSettings() >> new TestManagementSettings(true, 10)
45+
46+
def executionStrategy = new ExecutionStrategy(Stub(Config), executionSettings, Stub(SourcePathResolver), Stub(LinesResolver))
47+
48+
new HeadlessTestSession(
49+
"project-name",
50+
null,
51+
Provider.UNSUPPORTED,
52+
Stub(Config),
53+
Stub(CiVisibilityMetricCollector),
54+
Stub(TestDecorator),
55+
Stub(SourcePathResolver),
56+
Stub(Codeowners),
57+
Stub(LinesResolver),
58+
Stub(CoverageStore.Factory),
59+
executionStrategy
60+
)
61+
}
62+
}

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/ModuleExecutionResultTest.groovy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class ModuleExecutionResultTest extends Specification {
1616

1717
where:
1818
signal << [
19-
new ModuleExecutionResult(DDTraceId.from(12345), 67890, false, false, false, false, 0, Collections.emptyList()),
20-
new ModuleExecutionResult(DDTraceId.from(12345), 67890, true, false, true, true, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))),
21-
new ModuleExecutionResult(DDTraceId.from(12345), 67890, false, true, true, false, 2, Arrays.asList(new TestFramework("junit", "4.13.2"), new TestFramework("junit", "5.9.2"))),
22-
new ModuleExecutionResult(DD128bTraceId.from(12345, 67890), 67890, false, false, false, true, 3, Arrays.asList(new TestFramework("junit", null), new TestFramework("junit", "5.9.2"))),
23-
new ModuleExecutionResult(DD128bTraceId.from(12345, 67890), 67890, true, true, true, true, Integer.MAX_VALUE, Arrays.asList(new TestFramework("junit", "4.13.2"), new TestFramework(null, "5.9.2")))
19+
new ModuleExecutionResult(DDTraceId.from(12345), 67890, false, false, false, false, false, 0, Collections.emptyList()),
20+
new ModuleExecutionResult(DDTraceId.from(12345), 67890, true, false, true, true, true, 1, Collections.singletonList(new TestFramework("junit", "4.13.2"))),
21+
new ModuleExecutionResult(DDTraceId.from(12345), 67890, false, true, true, false, false, 2, Arrays.asList(new TestFramework("junit", "4.13.2"), new TestFramework("junit", "5.9.2"))),
22+
new ModuleExecutionResult(DD128bTraceId.from(12345, 67890), 67890, false, false, false, true, true, 3, Arrays.asList(new TestFramework("junit", null), new TestFramework("junit", "5.9.2"))),
23+
new ModuleExecutionResult(DD128bTraceId.from(12345, 67890), 67890, true, true, true, true, true, Integer.MAX_VALUE, Arrays.asList(new TestFramework("junit", "4.13.2"), new TestFramework(null, "5.9.2")))
2424
]
2525
}
2626
}

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/ipc/SignalServerTest.groovy

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SignalServerTest extends Specification {
1212
def "test message send and receive"() {
1313
given:
1414
def signalProcessed = new AtomicBoolean(false)
15-
def signal = new ModuleExecutionResult(DDTraceId.from(123), 456, true, true, false, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2")))
15+
def signal = new ModuleExecutionResult(DDTraceId.from(123), 456, true, true, false, false, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2")))
1616
def server = new SignalServer()
1717
def received = new ArrayList()
1818

@@ -41,8 +41,8 @@ class SignalServerTest extends Specification {
4141

4242
def "test multiple messages send and receive"() {
4343
given:
44-
def signalA = new ModuleExecutionResult(DDTraceId.from(123), 456, false, false, false, false, 0, Collections.singletonList(new TestFramework("junit", "4.13.2")))
45-
def signalB = new ModuleExecutionResult(DDTraceId.from(234), 567, true, true, false, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2")))
44+
def signalA = new ModuleExecutionResult(DDTraceId.from(123), 456, false, false, false, false, false, 0, Collections.singletonList(new TestFramework("junit", "4.13.2")))
45+
def signalB = new ModuleExecutionResult(DDTraceId.from(234), 567, true, true, false, false, true, 1, Collections.singletonList(new TestFramework("junit", "4.13.2")))
4646
def server = new SignalServer()
4747
def received = new ArrayList()
4848

@@ -70,8 +70,8 @@ class SignalServerTest extends Specification {
7070

7171
def "test multiple clients send and receive"() {
7272
given:
73-
def signalA = new ModuleExecutionResult(DDTraceId.from(123), 456, true, false, true, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2")))
74-
def signalB = new ModuleExecutionResult(DDTraceId.from(234), 567, false, true, false, true, 0, Collections.singletonList(new TestFramework("junit", "4.13.2")))
73+
def signalA = new ModuleExecutionResult(DDTraceId.from(123), 456, true, false, true, false, true, 1, Collections.singletonList(new TestFramework("junit", "4.13.2")))
74+
def signalB = new ModuleExecutionResult(DDTraceId.from(234), 567, false, true, false, true, false, 0, Collections.singletonList(new TestFramework("junit", "4.13.2")))
7575
def server = new SignalServer()
7676
def received = new ArrayList()
7777

@@ -118,7 +118,7 @@ class SignalServerTest extends Specification {
118118
when:
119119
def address = server.getAddress()
120120
try (def client = new SignalClient(address, clientTimeoutMillis)) {
121-
client.send(new ModuleExecutionResult(DDTraceId.from(123), 456, false, false, false, false, 0, Collections.singletonList(new TestFramework("junit", "4.13.2"))))
121+
client.send(new ModuleExecutionResult(DDTraceId.from(123), 456, false, false, false, false, false, 0, Collections.singletonList(new TestFramework("junit", "4.13.2"))))
122122
}
123123

124124
then:
@@ -130,7 +130,7 @@ class SignalServerTest extends Specification {
130130

131131
def "test error response receipt"() {
132132
given:
133-
def signal = new ModuleExecutionResult(DDTraceId.from(123), 456, true, true, false, false, 1, Collections.singletonList(new TestFramework("junit", "4.13.2")))
133+
def signal = new ModuleExecutionResult(DDTraceId.from(123), 456, true, true, false, false, true, 1, Collections.singletonList(new TestFramework("junit", "4.13.2")))
134134
def server = new SignalServer()
135135

136136
def errorResponse = new ErrorResponse("An error occurred while processing the signal")

dd-java-agent/agent-ci-visibility/src/test/resources/datadog/trace/civisibility/config/settings-response.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
</#list>
1919
},
2020
"faulty_session_threshold": ${settings.earlyFlakeDetectionSettings.faultySessionThreshold}
21+
},
22+
"test_management": {
23+
"enabled": ${settings.testManagementSettings.enabled?c},
24+
"attempt_to_fix_retries": ${settings.testManagementSettings.attemptToFixRetries}
2125
}
2226
}
2327
}

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/Tags.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class Tags {
9898
public static final String TEST_IS_MODIFIED = "test.is_modified";
9999
public static final String TEST_HAS_FAILED_ALL_RETRIES = "test.has_failed_all_retries";
100100
public static final String TEST_MANAGEMENT_IS_QUARANTINED = "test.management.is_quarantined";
101+
public static final String TEST_TEST_MANAGEMENT_ENABLED = "test.test_management.enabled";
101102

102103
public static final String CI_PROVIDER_NAME = "ci.provider.name";
103104
public static final String CI_PIPELINE_ID = "ci.pipeline.id";

0 commit comments

Comments
 (0)