Skip to content

Receive test management settings from CIVis settings request #8331

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

Merged
merged 10 commits into from
Feb 5, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private TestEventsHandlerFactory(
services, repoServices, coverageServices, executionSettings);
} else {
sessionFactory =
headlessTestFrameworkEssionFactory(
headlessTestFrameworkSessionFactory(
services, repoServices, coverageServices, executionSettings);
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ private static TestFrameworkSession.Factory childTestFrameworkSessionFactory(
};
}

private static TestFrameworkSession.Factory headlessTestFrameworkEssionFactory(
private static TestFrameworkSession.Factory headlessTestFrameworkSessionFactory(
CiVisibilityServices services,
CiVisibilityRepoServices repoServices,
CiVisibilityCoverageServices.Child coverageServices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ public class CiVisibilitySettings {

public static final CiVisibilitySettings DEFAULT =
new CiVisibilitySettings(
false, false, false, false, false, false, false, EarlyFlakeDetectionSettings.DEFAULT);
false,
false,
false,
false,
false,
false,
false,
EarlyFlakeDetectionSettings.DEFAULT,
TestManagementSettings.DEFAULT);

private final boolean itrEnabled;
private final boolean codeCoverage;
Expand All @@ -19,6 +27,7 @@ public class CiVisibilitySettings {
private final boolean impactedTestsDetectionEnabled;
private final boolean knownTestsEnabled;
private final EarlyFlakeDetectionSettings earlyFlakeDetectionSettings;
private final TestManagementSettings testManagementSettings;

CiVisibilitySettings(
boolean itrEnabled,
Expand All @@ -28,7 +37,8 @@ public class CiVisibilitySettings {
boolean flakyTestRetriesEnabled,
boolean impactedTestsDetectionEnabled,
boolean knownTestsEnabled,
EarlyFlakeDetectionSettings earlyFlakeDetectionSettings) {
EarlyFlakeDetectionSettings earlyFlakeDetectionSettings,
TestManagementSettings testManagementSettings) {
this.itrEnabled = itrEnabled;
this.codeCoverage = codeCoverage;
this.testsSkipping = testsSkipping;
Expand All @@ -37,6 +47,7 @@ public class CiVisibilitySettings {
this.impactedTestsDetectionEnabled = impactedTestsDetectionEnabled;
this.knownTestsEnabled = knownTestsEnabled;
this.earlyFlakeDetectionSettings = earlyFlakeDetectionSettings;
this.testManagementSettings = testManagementSettings;
}

public boolean isItrEnabled() {
Expand Down Expand Up @@ -71,6 +82,10 @@ public EarlyFlakeDetectionSettings getEarlyFlakeDetectionSettings() {
return earlyFlakeDetectionSettings;
}

public TestManagementSettings getTestManagementSettings() {
return testManagementSettings;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -87,7 +102,8 @@ public boolean equals(Object o) {
&& flakyTestRetriesEnabled == that.flakyTestRetriesEnabled
&& impactedTestsDetectionEnabled == that.impactedTestsDetectionEnabled
&& knownTestsEnabled == that.knownTestsEnabled
&& Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings);
&& Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings)
&& Objects.equals(testManagementSettings, that.testManagementSettings);
}

@Override
Expand All @@ -100,7 +116,8 @@ public int hashCode() {
flakyTestRetriesEnabled,
impactedTestsDetectionEnabled,
knownTestsEnabled,
earlyFlakeDetectionSettings);
earlyFlakeDetectionSettings,
testManagementSettings);
}

public interface Factory {
Expand All @@ -126,7 +143,9 @@ public CiVisibilitySettings fromJson(Map<String, Object> json) {
getBoolean(json, "impacted_tests_enabled", false),
getBoolean(json, "known_tests_enabled", false),
EarlyFlakeDetectionSettingsJsonAdapter.INSTANCE.fromJson(
(Map<String, Object>) json.get("early_flake_detection")));
(Map<String, Object>) json.get("early_flake_detection")),
TestManagementSettingsJsonAdapter.INSTANCE.fromJson(
(Map<String, Object>) json.get("test_management")));
}

private static boolean getBoolean(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import datadog.trace.api.civisibility.telemetry.tag.ItrSkipEnabled;
import datadog.trace.api.civisibility.telemetry.tag.KnownTestsEnabled;
import datadog.trace.api.civisibility.telemetry.tag.RequireGit;
import datadog.trace.api.civisibility.telemetry.tag.TestManagementEnabled;
import datadog.trace.civisibility.communication.TelemetryListener;
import datadog.trace.util.RandomUtils;
import java.io.File;
Expand Down Expand Up @@ -146,6 +147,7 @@ public CiVisibilitySettings getSettings(TracerEnvironment tracerEnvironment) thr
settings.isFlakyTestRetriesEnabled() ? FlakyTestRetriesEnabled.TRUE : null,
settings.isKnownTestsEnabled() ? KnownTestsEnabled.TRUE : null,
settings.isImpactedTestsDetectionEnabled() ? ImpactedTestsDetectionEnabled.TRUE : null,
settings.getTestManagementSettings().isEnabled() ? TestManagementEnabled.TRUE : null,
settings.isGitUploadRequired() ? RequireGit.TRUE : null);

return settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ExecutionSettings {
false,
false,
EarlyFlakeDetectionSettings.DEFAULT,
TestManagementSettings.DEFAULT,
null,
Collections.emptyMap(),
Collections.emptyMap(),
Expand All @@ -39,6 +40,7 @@ public class ExecutionSettings {
private final boolean flakyTestRetriesEnabled;
private final boolean impactedTestsDetectionEnabled;
@Nonnull private final EarlyFlakeDetectionSettings earlyFlakeDetectionSettings;
@Nonnull private final TestManagementSettings testManagementSettings;
@Nullable private final String itrCorrelationId;
@Nonnull private final Map<TestIdentifier, TestMetadata> skippableTests;
@Nonnull private final Map<String, BitSet> skippableTestsCoverage;
Expand All @@ -54,6 +56,7 @@ public ExecutionSettings(
boolean flakyTestRetriesEnabled,
boolean impactedTestsDetectionEnabled,
@Nonnull EarlyFlakeDetectionSettings earlyFlakeDetectionSettings,
@Nonnull TestManagementSettings testManagementSettings,
@Nullable String itrCorrelationId,
@Nonnull Map<TestIdentifier, TestMetadata> skippableTests,
@Nonnull Map<String, BitSet> skippableTestsCoverage,
Expand All @@ -67,6 +70,7 @@ public ExecutionSettings(
this.flakyTestRetriesEnabled = flakyTestRetriesEnabled;
this.impactedTestsDetectionEnabled = impactedTestsDetectionEnabled;
this.earlyFlakeDetectionSettings = earlyFlakeDetectionSettings;
this.testManagementSettings = testManagementSettings;
this.itrCorrelationId = itrCorrelationId;
this.skippableTests = skippableTests;
this.skippableTestsCoverage = skippableTestsCoverage;
Expand Down Expand Up @@ -105,6 +109,11 @@ public EarlyFlakeDetectionSettings getEarlyFlakeDetectionSettings() {
return earlyFlakeDetectionSettings;
}

@Nonnull
public TestManagementSettings getTestManagementSettings() {
return testManagementSettings;
}

@Nullable
public String getItrCorrelationId() {
return itrCorrelationId;
Expand Down Expand Up @@ -162,6 +171,7 @@ public boolean equals(Object o) {
&& codeCoverageEnabled == that.codeCoverageEnabled
&& testSkippingEnabled == that.testSkippingEnabled
&& Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings)
&& Objects.equals(testManagementSettings, that.testManagementSettings)
&& Objects.equals(itrCorrelationId, that.itrCorrelationId)
&& Objects.equals(skippableTests, that.skippableTests)
&& Objects.equals(skippableTestsCoverage, that.skippableTestsCoverage)
Expand All @@ -178,6 +188,7 @@ public int hashCode() {
codeCoverageEnabled,
testSkippingEnabled,
earlyFlakeDetectionSettings,
testManagementSettings,
itrCorrelationId,
skippableTests,
skippableTestsCoverage,
Expand Down Expand Up @@ -211,6 +222,8 @@ public static ByteBuffer serialize(ExecutionSettings settings) {

EarlyFlakeDetectionSettingsSerializer.serialize(s, settings.earlyFlakeDetectionSettings);

TestManagementSettingsSerializer.serialize(s, settings.testManagementSettings);

s.write(settings.itrCorrelationId);
s.write(
settings.skippableTests,
Expand Down Expand Up @@ -238,6 +251,9 @@ public static ExecutionSettings deserialize(ByteBuffer buffer) {
EarlyFlakeDetectionSettings earlyFlakeDetectionSettings =
EarlyFlakeDetectionSettingsSerializer.deserialize(buffer);

TestManagementSettings testManagementSettings =
TestManagementSettingsSerializer.deserialize(buffer);

String itrCorrelationId = Serializer.readString(buffer);

Map<TestIdentifier, TestMetadata> skippableTests =
Expand All @@ -262,6 +278,7 @@ public static ExecutionSettings deserialize(ByteBuffer buffer) {
flakyTestRetriesEnabled,
impactedTestsDetectionEnabled,
earlyFlakeDetectionSettings,
testManagementSettings,
itrCorrelationId,
skippableTests,
skippableTestsCoverage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ private Map<String, ExecutionSettings> doCreate(
CiVisibilitySettings::isKnownTestsEnabled,
Config::isCiVisibilityKnownTestsRequestEnabled);

TestManagementSettings testManagementSettings = getTestManagementSettings(settings);

LOGGER.info(
"CI Visibility settings ({}, {}/{}/{}):\n"
+ "Intelligent Test Runner - {},\n"
Expand All @@ -186,7 +188,8 @@ private Map<String, ExecutionSettings> doCreate(
+ "Early flakiness detection - {},\n"
+ "Impacted tests detection - {},\n"
+ "Known tests marking - {},\n"
+ "Auto test retries - {}",
+ "Auto test retries - {},\n"
+ "Test Management - {}",
repositoryRoot,
tracerEnvironment.getConfigurations().getRuntimeName(),
tracerEnvironment.getConfigurations().getRuntimeVersion(),
Expand All @@ -197,7 +200,8 @@ private Map<String, ExecutionSettings> doCreate(
earlyFlakeDetectionEnabled,
impactedTestsEnabled,
knownTestsRequest,
flakyTestRetriesEnabled);
flakyTestRetriesEnabled,
testManagementSettings.isEnabled());

Future<SkippableTests> skippableTestsFuture =
executor.submit(() -> getSkippableTests(tracerEnvironment, itrEnabled));
Expand Down Expand Up @@ -228,6 +232,7 @@ private Map<String, ExecutionSettings> doCreate(
earlyFlakeDetectionEnabled
? settings.getEarlyFlakeDetectionSettings()
: EarlyFlakeDetectionSettings.DEFAULT,
testManagementSettings,
skippableTests.getCorrelationId(),
skippableTests
.getIdentifiersByModule()
Expand Down Expand Up @@ -270,6 +275,26 @@ private boolean isFeatureEnabled(
return remoteSetting.apply(ciVisibilitySettings) && killSwitch.apply(config);
}

@Nonnull
private TestManagementSettings getTestManagementSettings(CiVisibilitySettings settings) {
boolean testManagementEnabled =
isFeatureEnabled(
settings,
s -> s.getTestManagementSettings().isEnabled(),
Config::isCiVisibilityTestManagementEnabled);

if (!testManagementEnabled) {
return TestManagementSettings.DEFAULT;
}

Integer retries = config.getCiVisibilityTestManagementAttemptToFixRetries();
if (retries != null) {
return new TestManagementSettings(true, retries);
}

return settings.getTestManagementSettings();
}

@Nonnull
private SkippableTests getSkippableTests(
TracerEnvironment tracerEnvironment, boolean itrEnabled) {
Expand Down Expand Up @@ -302,7 +327,6 @@ private SkippableTests getSkippableTests(
Thread.currentThread().interrupt();
LOGGER.error("Interrupted while waiting for git data upload", e);
return SkippableTests.EMPTY;

} catch (Exception e) {
LOGGER.error("Could not obtain list of skippable tests, will proceed without skipping", e);
return SkippableTests.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package datadog.trace.civisibility.config;

import java.util.Objects;

public class TestManagementSettings {

public static final TestManagementSettings DEFAULT = new TestManagementSettings(false, -1);

private final boolean enabled;
private final int attemptToFixRetries;

public TestManagementSettings(boolean enabled, int attemptToFixRetries) {
this.enabled = enabled;
this.attemptToFixRetries = attemptToFixRetries;
}

public boolean isEnabled() {
return enabled;
}

public int getAttemptToFixRetries() {
return attemptToFixRetries;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

TestManagementSettings that = (TestManagementSettings) o;
return enabled == that.enabled && attemptToFixRetries == that.attemptToFixRetries;
}

@Override
public int hashCode() {
return Objects.hash(enabled, attemptToFixRetries);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package datadog.trace.civisibility.config;

import com.squareup.moshi.FromJson;
import java.util.Map;

public class TestManagementSettingsJsonAdapter {
public static final TestManagementSettingsJsonAdapter INSTANCE =
new TestManagementSettingsJsonAdapter();

@FromJson
public TestManagementSettings fromJson(Map<String, Object> json) {
if (json == null) {
return TestManagementSettings.DEFAULT;
}

Boolean enabled = (Boolean) json.get("enabled");
Double attemptToFixRetries = (Double) json.get("attempt_to_fix_retries");

return new TestManagementSettings(
enabled != null ? enabled : false,
attemptToFixRetries != null ? attemptToFixRetries.intValue() : -1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package datadog.trace.civisibility.config;

import datadog.trace.civisibility.ipc.serialization.Serializer;
import java.nio.ByteBuffer;

public class TestManagementSettingsSerializer {
public static void serialize(Serializer serializer, TestManagementSettings settings) {
if (!settings.isEnabled()) {
serializer.write((byte) 0);
return;
}
serializer.write((byte) 1);
serializer.write(settings.getAttemptToFixRetries());
}

public static TestManagementSettings deserialize(ByteBuffer buf) {
boolean enabled = Serializer.readByte(buf) != 0;
if (!enabled) {
return TestManagementSettings.DEFAULT;
}

int attemptToFixRetries = Serializer.readInt(buf);
return new TestManagementSettings(enabled, attemptToFixRetries);
}
}
Loading
Loading