-
Notifications
You must be signed in to change notification settings - Fork 333
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
Changes from 7 commits
372c808
1397b1a
3f1837b
96110c6
e6028c5
97d9ca1
8d43f9d
73a3b86
bd2aa39
e78edfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package datadog.trace.civisibility.config; | ||
|
|
||
| import datadog.trace.api.Config; | ||
| import datadog.trace.api.ConfigDefaults; | ||
| import datadog.trace.api.civisibility.CIConstants; | ||
| import datadog.trace.api.civisibility.CiVisibilityWellKnownTags; | ||
| import datadog.trace.api.civisibility.config.TestIdentifier; | ||
|
|
@@ -27,6 +28,7 @@ | |
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.ThreadFactory; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Function; | ||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
@@ -177,6 +179,17 @@ private Map<String, ExecutionSettings> doCreate( | |
| settings, | ||
| CiVisibilitySettings::isKnownTestsEnabled, | ||
| Config::isCiVisibilityKnownTestsRequestEnabled); | ||
| boolean testManagementEnabled = | ||
| isFeatureEnabled( | ||
| settings, | ||
| s -> s.getTestManagementSettings().isEnabled(), | ||
| Config::isCiVisibilityTestManagementEnabled); | ||
| if (testManagementEnabled) { | ||
| overrideIntegerSetting( | ||
| Config::getCiVisibilityTestManagementAttemptToFixRetries, | ||
| value -> value != ConfigDefaults.DEFAULT_TEST_MANAGEMENT_ATTEMPT_TO_FIX_RETRIES, | ||
| value -> settings.getTestManagementSettings().setAttemptToFixRetries(value)); | ||
| } | ||
|
|
||
| LOGGER.info( | ||
| "CI Visibility settings ({}, {}/{}/{}):\n" | ||
|
|
@@ -186,7 +199,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(), | ||
|
|
@@ -197,7 +211,8 @@ private Map<String, ExecutionSettings> doCreate( | |
| earlyFlakeDetectionEnabled, | ||
| impactedTestsEnabled, | ||
| knownTestsRequest, | ||
| flakyTestRetriesEnabled); | ||
| flakyTestRetriesEnabled, | ||
| testManagementEnabled); | ||
|
|
||
| Future<SkippableTests> skippableTestsFuture = | ||
| executor.submit(() -> getSkippableTests(tracerEnvironment, itrEnabled)); | ||
|
|
@@ -228,6 +243,9 @@ private Map<String, ExecutionSettings> doCreate( | |
| earlyFlakeDetectionEnabled | ||
| ? settings.getEarlyFlakeDetectionSettings() | ||
| : EarlyFlakeDetectionSettings.DEFAULT, | ||
| testManagementEnabled | ||
| ? settings.getTestManagementSettings() | ||
| : TestManagementSettings.DEFAULT, | ||
| skippableTests.getCorrelationId(), | ||
| skippableTests | ||
| .getIdentifiersByModule() | ||
|
|
@@ -270,6 +288,16 @@ private boolean isFeatureEnabled( | |
| return remoteSetting.apply(ciVisibilitySettings) && killSwitch.apply(config); | ||
| } | ||
|
|
||
| private void overrideIntegerSetting( | ||
| Function<Config, Integer> valueGetter, | ||
| Function<Integer, Boolean> overrideCheck, | ||
| Consumer<Integer> overrideAction) { | ||
| Integer value = valueGetter.apply(config); | ||
| if (value != null && overrideCheck.apply(value)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that we want to apply the overriding local value only if it's different from the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought having a very generic way of overriding values might be beneficial in the future, but it might not make much sense for now as it is only used in this specific scenario. Overriding (or, better yet, creating a new instance as the next comment indicates) would be much clearer if the Config field was an Integer with |
||
| overrideAction.accept(value); | ||
| } | ||
| } | ||
|
|
||
| @Nonnull | ||
| private SkippableTests getSkippableTests( | ||
| TracerEnvironment tracerEnvironment, boolean itrEnabled) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| 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 int attemptToFixRetries; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be better to make the class immutable (marking both fields as |
||
|
|
||
| public TestManagementSettings(boolean enabled, int attemptToFixRetries) { | ||
| this.enabled = enabled; | ||
| this.attemptToFixRetries = attemptToFixRetries; | ||
| } | ||
|
|
||
| public boolean isEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| public int getAttemptToFixRetries() { | ||
| return attemptToFixRetries; | ||
| } | ||
|
|
||
| public void setAttemptToFixRetries(int value) { | ||
| attemptToFixRetries = value; | ||
| } | ||
|
|
||
| @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); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.