Skip to content

Commit 372c808

Browse files
obtain test management settings from settings request
1 parent eef31bc commit 372c808

File tree

9 files changed

+164
-9
lines changed

9 files changed

+164
-9
lines changed

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ public class CiVisibilitySettings {
99

1010
public static final CiVisibilitySettings DEFAULT =
1111
new CiVisibilitySettings(
12-
false, false, false, false, false, false, false, EarlyFlakeDetectionSettings.DEFAULT);
12+
false,
13+
false,
14+
false,
15+
false,
16+
false,
17+
false,
18+
false,
19+
EarlyFlakeDetectionSettings.DEFAULT,
20+
TestManagementSettings.DEFAULT);
1321

1422
private final boolean itrEnabled;
1523
private final boolean codeCoverage;
@@ -19,6 +27,7 @@ public class CiVisibilitySettings {
1927
private final boolean impactedTestsDetectionEnabled;
2028
private final boolean knownTestsEnabled;
2129
private final EarlyFlakeDetectionSettings earlyFlakeDetectionSettings;
30+
private final TestManagementSettings testManagementSettings;
2231

2332
CiVisibilitySettings(
2433
boolean itrEnabled,
@@ -28,7 +37,8 @@ public class CiVisibilitySettings {
2837
boolean flakyTestRetriesEnabled,
2938
boolean impactedTestsDetectionEnabled,
3039
boolean knownTestsEnabled,
31-
EarlyFlakeDetectionSettings earlyFlakeDetectionSettings) {
40+
EarlyFlakeDetectionSettings earlyFlakeDetectionSettings,
41+
TestManagementSettings testManagementSettings) {
3242
this.itrEnabled = itrEnabled;
3343
this.codeCoverage = codeCoverage;
3444
this.testsSkipping = testsSkipping;
@@ -37,6 +47,7 @@ public class CiVisibilitySettings {
3747
this.impactedTestsDetectionEnabled = impactedTestsDetectionEnabled;
3848
this.knownTestsEnabled = knownTestsEnabled;
3949
this.earlyFlakeDetectionSettings = earlyFlakeDetectionSettings;
50+
this.testManagementSettings = testManagementSettings;
4051
}
4152

4253
public boolean isItrEnabled() {
@@ -71,6 +82,10 @@ public EarlyFlakeDetectionSettings getEarlyFlakeDetectionSettings() {
7182
return earlyFlakeDetectionSettings;
7283
}
7384

85+
public TestManagementSettings getTestManagementSettings() {
86+
return testManagementSettings;
87+
}
88+
7489
@Override
7590
public boolean equals(Object o) {
7691
if (this == o) {
@@ -87,7 +102,8 @@ public boolean equals(Object o) {
87102
&& flakyTestRetriesEnabled == that.flakyTestRetriesEnabled
88103
&& impactedTestsDetectionEnabled == that.impactedTestsDetectionEnabled
89104
&& knownTestsEnabled == that.knownTestsEnabled
90-
&& Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings);
105+
&& Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings)
106+
&& Objects.equals(testManagementSettings, that.testManagementSettings);
91107
}
92108

93109
@Override
@@ -100,7 +116,8 @@ public int hashCode() {
100116
flakyTestRetriesEnabled,
101117
impactedTestsDetectionEnabled,
102118
knownTestsEnabled,
103-
earlyFlakeDetectionSettings);
119+
earlyFlakeDetectionSettings,
120+
testManagementSettings);
104121
}
105122

106123
public interface Factory {
@@ -126,7 +143,9 @@ public CiVisibilitySettings fromJson(Map<String, Object> json) {
126143
getBoolean(json, "impacted_tests_enabled", false),
127144
getBoolean(json, "known_tests_enabled", false),
128145
EarlyFlakeDetectionSettingsJsonAdapter.INSTANCE.fromJson(
129-
(Map<String, Object>) json.get("early_flake_detection")));
146+
(Map<String, Object>) json.get("early_flake_detection")),
147+
TestManagementSettingsJsonAdapter.INSTANCE.fromJson(
148+
(Map<String, Object>) json.get("test_management")));
130149
}
131150

132151
private static boolean getBoolean(
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package datadog.trace.civisibility.config;
2+
3+
import java.util.Objects;
4+
5+
public class TestManagementSettings {
6+
7+
public static final TestManagementSettings DEFAULT =
8+
new TestManagementSettings(false, -1);
9+
10+
private final boolean enabled;
11+
private int attemptToFixRetries;
12+
13+
public TestManagementSettings(boolean enabled, int attemptToFixRetries) {
14+
this.enabled = enabled;
15+
this.attemptToFixRetries = attemptToFixRetries;
16+
}
17+
18+
public boolean isEnabled() {
19+
return enabled;
20+
}
21+
22+
public int getAttemptToFixRetries() {
23+
return attemptToFixRetries;
24+
}
25+
26+
public void setAttemptToFixRetries(int value) {
27+
attemptToFixRetries = value;
28+
}
29+
30+
@Override
31+
public boolean equals(Object o) {
32+
if (this == o) {
33+
return true;
34+
}
35+
if (o == null || getClass() != o.getClass()) {
36+
return false;
37+
}
38+
39+
TestManagementSettings that = (TestManagementSettings) o;
40+
return enabled == that.enabled && attemptToFixRetries == that.attemptToFixRetries;
41+
}
42+
43+
@Override
44+
public int hashCode() {
45+
return Objects.hash(enabled, attemptToFixRetries);
46+
}
47+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package datadog.trace.civisibility.config;
2+
3+
import com.squareup.moshi.FromJson;
4+
5+
import java.util.Map;
6+
7+
public class TestManagementSettingsJsonAdapter {
8+
public static final TestManagementSettingsJsonAdapter INSTANCE = new TestManagementSettingsJsonAdapter();
9+
10+
@FromJson
11+
public TestManagementSettings fromJson(Map<String, Object> json) {
12+
if (json == null) {
13+
return TestManagementSettings.DEFAULT;
14+
}
15+
16+
Boolean enabled = (Boolean) json.get("enabled");
17+
Double attemptToFixRetries = (Double) json.get("attempt_to_fix_retries");
18+
19+
return new TestManagementSettings(
20+
enabled != null ? enabled : false,
21+
attemptToFixRetries != null ? attemptToFixRetries.intValue() : -1
22+
);
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package datadog.trace.civisibility.config;
2+
3+
import datadog.trace.civisibility.ipc.serialization.Serializer;
4+
5+
import java.nio.ByteBuffer;
6+
7+
public class TestManagementSettingsSerializer {
8+
public static void serialize(Serializer serializer, TestManagementSettings settings) {
9+
if (!settings.isEnabled()) {
10+
serializer.write((byte) 0);
11+
return;
12+
}
13+
serializer.write((byte) 1);
14+
serializer.write(settings.getAttemptToFixRetries());
15+
}
16+
17+
public static TestManagementSettings deserialize(ByteBuffer buf) {
18+
boolean enabled = Serializer.readByte(buf) != 0;
19+
if (!enabled) {
20+
return TestManagementSettings.DEFAULT;
21+
}
22+
23+
int attemptToFixRetries = Serializer.readInt(buf);
24+
return new TestManagementSettings(enabled, attemptToFixRetries);
25+
}
26+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ class ConfigurationApiImplTest extends Specification {
5454

5555
where:
5656
agentless | compression | expectedSettings
57-
false | false | new CiVisibilitySettings(false, false, false, false, false, false, false, EarlyFlakeDetectionSettings.DEFAULT)
58-
false | true | new CiVisibilitySettings(true, true, true, true, true, true, true, EarlyFlakeDetectionSettings.DEFAULT)
59-
true | false | new CiVisibilitySettings(false, true, false, true, false, true, false, new EarlyFlakeDetectionSettings(true, [new EarlyFlakeDetectionSettings.ExecutionsByDuration(1000, 3)], 10))
57+
false | false | new CiVisibilitySettings(false, false, false, false, false, false, false, EarlyFlakeDetectionSettings.DEFAULT, TestManagementSettings.DEFAULT)
58+
false | true | new CiVisibilitySettings(true, true, true, true, true, true, true, EarlyFlakeDetectionSettings.DEFAULT, TestManagementSettings.DEFAULT)
59+
true | false | new CiVisibilitySettings(false, true, false, true, false, true, false, new EarlyFlakeDetectionSettings(true, [new EarlyFlakeDetectionSettings.ExecutionsByDuration(1000, 3)], 10), new TestManagementSettings(true, 10))
6060
true | true | new CiVisibilitySettings(false, false, true, true, false, false, true, new EarlyFlakeDetectionSettings(true, [
6161
new EarlyFlakeDetectionSettings.ExecutionsByDuration(5000, 3),
6262
new EarlyFlakeDetectionSettings.ExecutionsByDuration(120000, 2)
63-
], 10))
63+
], 10), new TestManagementSettings(true, 20))
6464
}
6565

6666
def "test skippable tests request"() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package datadog.trace.civisibility.config
2+
3+
import datadog.trace.civisibility.ipc.serialization.Serializer
4+
import spock.lang.Specification
5+
6+
class TestManagementSettingsSerializerTest extends Specification {
7+
def "test TestManagementSettings serialization: #iterationIndex"() {
8+
when:
9+
Serializer s = new Serializer()
10+
TestManagementSettingsSerializer.serialize(s, settings)
11+
12+
def buffer = s.flush()
13+
def deserialized = TestManagementSettingsSerializer.deserialize(buffer)
14+
15+
then:
16+
deserialized == settings
17+
18+
where:
19+
settings << [
20+
TestManagementSettings.DEFAULT,
21+
new TestManagementSettings(true, 10),
22+
]
23+
}
24+
}

dd-trace-api/src/main/java/datadog/trace/api/ConfigDefaults.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public final class ConfigDefaults {
163163
static final int DEFAULT_CIVISIBILITY_SIGNAL_SERVER_PORT = 0;
164164
static final List<String> DEFAULT_CIVISIBILITY_RESOURCE_FOLDER_NAMES =
165165
asList("/resources/", "/java/", "/groovy/", "/kotlin/", "/scala/");
166+
public static final int DEFAULT_TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES = -1;
166167

167168
static final boolean DEFAULT_REMOTE_CONFIG_ENABLED = true;
168169
static final boolean DEFAULT_REMOTE_CONFIG_INTEGRITY_CHECK_ENABLED = false;

dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public final class CiVisibilityConfig {
7777
public static final String CIVISIBILITY_REMOTE_ENV_VARS_PROVIDER_KEY =
7878
"civisibility.remote.env.vars.provider.key";
7979
public static final String CIVISIBILITY_TEST_ORDER = "civisibility.test.order";
80+
public static final String TEST_MANAGEMENT_ENABLED = "test.management.enabled";
81+
public static final String TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES = "test.management.attempt.to.fix.retries";
8082

8183
/* COVERAGE SETTINGS */
8284
public static final String CIVISIBILITY_CODE_COVERAGE_ENABLED =

internal-api/src/main/java/datadog/trace/api/Config.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ public static String getHostName() {
373373
private final String ciVisibilityRemoteEnvVarsProviderUrl;
374374
private final String ciVisibilityRemoteEnvVarsProviderKey;
375375
private final String ciVisibilityTestOrder;
376+
private final boolean ciVisibilityTestManagementEnabled;
377+
private final int ciVisibilityTestManagementAttemptToFixRetries;
376378

377379
private final boolean remoteConfigEnabled;
378380
private final boolean remoteConfigIntegrityCheckEnabled;
@@ -1522,6 +1524,8 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
15221524
ciVisibilityRemoteEnvVarsProviderKey =
15231525
configProvider.getString(CIVISIBILITY_REMOTE_ENV_VARS_PROVIDER_KEY);
15241526
ciVisibilityTestOrder = configProvider.getString(CIVISIBILITY_TEST_ORDER);
1527+
ciVisibilityTestManagementEnabled = configProvider.getBoolean(TEST_MANAGEMENT_ENABLED, true);
1528+
ciVisibilityTestManagementAttemptToFixRetries = configProvider.getInteger(TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES, DEFAULT_TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES);
15251529

15261530
remoteConfigEnabled =
15271531
configProvider.getBoolean(
@@ -2979,6 +2983,14 @@ public String getCiVisibilityTestOrder() {
29792983
return ciVisibilityTestOrder;
29802984
}
29812985

2986+
public boolean isCiVisibilityTestManagementEnabled() {
2987+
return ciVisibilityTestManagementEnabled;
2988+
}
2989+
2990+
public int getCiVisibilityTestManagementAttemptToFixRetries() {
2991+
return ciVisibilityTestManagementAttemptToFixRetries;
2992+
}
2993+
29822994
public String getAppSecRulesFile() {
29832995
return appSecRulesFile;
29842996
}

0 commit comments

Comments
 (0)