Skip to content

Commit bce9eaf

Browse files
Implement configuration error tagging for all backend requests (#10963)
feat: include configuration error tagging for all requests ci: trigger Co-authored-by: daniel.mohedano <daniel.mohedano@datadoghq.com>
1 parent 78288e9 commit bce9eaf

File tree

17 files changed

+222
-71
lines changed

17 files changed

+222
-71
lines changed

dd-java-agent/agent-ci-visibility/civisibility-instrumentation-test-fixtures/src/main/groovy/datadog/trace/civisibility/CiVisibilityInstrumentationTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ abstract class CiVisibilityInstrumentationTest extends InstrumentationSpecificat
249249
settings.disabledTests,
250250
settings.attemptToFixTests,
251251
settings.diff,
252-
false)
252+
ConfigurationErrors.NONE)
253253
}
254254
}
255255

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class CiVisibilitySettings {
2424
null,
2525
false);
2626

27-
public static final CiVisibilitySettings REQUEST_ERROR =
27+
public static final CiVisibilitySettings SETTINGS_REQUEST_ERROR =
2828
new CiVisibilitySettings(
2929
false,
3030
false,
@@ -52,7 +52,7 @@ public class CiVisibilitySettings {
5252
private final EarlyFlakeDetectionSettings earlyFlakeDetectionSettings;
5353
private final TestManagementSettings testManagementSettings;
5454
@Nullable private final String defaultBranch;
55-
private final boolean requestError;
55+
private final boolean settingsRequestError;
5656

5757
CiVisibilitySettings(
5858
boolean itrEnabled,
@@ -67,7 +67,7 @@ public class CiVisibilitySettings {
6767
EarlyFlakeDetectionSettings earlyFlakeDetectionSettings,
6868
TestManagementSettings testManagementSettings,
6969
@Nullable String defaultBranch,
70-
boolean requestError) {
70+
boolean settingsRequestError) {
7171
this.itrEnabled = itrEnabled;
7272
this.codeCoverage = codeCoverage;
7373
this.testsSkipping = testsSkipping;
@@ -80,7 +80,7 @@ public class CiVisibilitySettings {
8080
this.earlyFlakeDetectionSettings = earlyFlakeDetectionSettings;
8181
this.testManagementSettings = testManagementSettings;
8282
this.defaultBranch = defaultBranch;
83-
this.requestError = requestError;
83+
this.settingsRequestError = settingsRequestError;
8484
}
8585

8686
public boolean isItrEnabled() {
@@ -132,8 +132,8 @@ public String getDefaultBranch() {
132132
return defaultBranch;
133133
}
134134

135-
public boolean isRequestError() {
136-
return requestError;
135+
public boolean isSettingsRequestError() {
136+
return settingsRequestError;
137137
}
138138

139139
@Override
@@ -157,7 +157,7 @@ public boolean equals(Object o) {
157157
&& Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings)
158158
&& Objects.equals(testManagementSettings, that.testManagementSettings)
159159
&& Objects.equals(defaultBranch, that.defaultBranch)
160-
&& requestError == that.requestError;
160+
&& settingsRequestError == that.settingsRequestError;
161161
}
162162

163163
@Override
@@ -175,7 +175,7 @@ public int hashCode() {
175175
earlyFlakeDetectionSettings,
176176
testManagementSettings,
177177
defaultBranch,
178-
requestError);
178+
settingsRequestError);
179179
}
180180

181181
public interface Factory {
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package datadog.trace.civisibility.config;
2+
3+
import datadog.trace.api.DDTags;
4+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
5+
import datadog.trace.civisibility.ipc.serialization.Serializer;
6+
import java.nio.ByteBuffer;
7+
import java.util.Objects;
8+
9+
/** Tracks which CI Visibility backend requests failed. */
10+
public class ConfigurationErrors {
11+
12+
public static final ConfigurationErrors NONE =
13+
new ConfigurationErrors(false, false, false, false, false);
14+
15+
private static final int SETTINGS_FLAG = 1;
16+
private static final int SKIPPABLE_TESTS_FLAG = 2;
17+
private static final int FLAKY_TESTS_FLAG = 4;
18+
private static final int KNOWN_TESTS_FLAG = 8;
19+
private static final int TEST_MANAGEMENT_TESTS_FLAG = 16;
20+
21+
private final boolean settings;
22+
private final boolean skippableTests;
23+
private final boolean flakyTests;
24+
private final boolean knownTests;
25+
private final boolean testManagementTests;
26+
27+
public ConfigurationErrors(
28+
boolean settings,
29+
boolean skippableTests,
30+
boolean flakyTests,
31+
boolean knownTests,
32+
boolean testManagementTests) {
33+
this.settings = settings;
34+
this.skippableTests = skippableTests;
35+
this.flakyTests = flakyTests;
36+
this.knownTests = knownTests;
37+
this.testManagementTests = testManagementTests;
38+
}
39+
40+
public boolean hasAny() {
41+
return settings || skippableTests || flakyTests || knownTests || testManagementTests;
42+
}
43+
44+
public void applyTags(AgentSpan span) {
45+
if (settings) {
46+
span.setTag(DDTags.CI_LIBRARY_CONFIGURATION_ERROR_SETTINGS, true);
47+
}
48+
if (skippableTests) {
49+
span.setTag(DDTags.CI_LIBRARY_CONFIGURATION_ERROR_SKIPPABLE_TESTS, true);
50+
}
51+
if (flakyTests) {
52+
span.setTag(DDTags.CI_LIBRARY_CONFIGURATION_ERROR_FLAKY_TESTS, true);
53+
}
54+
if (knownTests) {
55+
span.setTag(DDTags.CI_LIBRARY_CONFIGURATION_ERROR_KNOWN_TESTS, true);
56+
}
57+
if (testManagementTests) {
58+
span.setTag(DDTags.CI_LIBRARY_CONFIGURATION_ERROR_TEST_MANAGEMENT_TESTS, true);
59+
}
60+
}
61+
62+
public static void serialize(Serializer s, ConfigurationErrors errors) {
63+
byte flags =
64+
(byte)
65+
((errors.settings ? SETTINGS_FLAG : 0)
66+
| (errors.skippableTests ? SKIPPABLE_TESTS_FLAG : 0)
67+
| (errors.flakyTests ? FLAKY_TESTS_FLAG : 0)
68+
| (errors.knownTests ? KNOWN_TESTS_FLAG : 0)
69+
| (errors.testManagementTests ? TEST_MANAGEMENT_TESTS_FLAG : 0));
70+
s.write(flags);
71+
}
72+
73+
public static ConfigurationErrors deserialize(ByteBuffer buffer) {
74+
byte flags = Serializer.readByte(buffer);
75+
if (flags == 0) {
76+
return NONE;
77+
}
78+
return new ConfigurationErrors(
79+
(flags & SETTINGS_FLAG) != 0,
80+
(flags & SKIPPABLE_TESTS_FLAG) != 0,
81+
(flags & FLAKY_TESTS_FLAG) != 0,
82+
(flags & KNOWN_TESTS_FLAG) != 0,
83+
(flags & TEST_MANAGEMENT_TESTS_FLAG) != 0);
84+
}
85+
86+
@Override
87+
public boolean equals(Object o) {
88+
if (this == o) {
89+
return true;
90+
}
91+
if (o == null || getClass() != o.getClass()) {
92+
return false;
93+
}
94+
ConfigurationErrors that = (ConfigurationErrors) o;
95+
return settings == that.settings
96+
&& skippableTests == that.skippableTests
97+
&& flakyTests == that.flakyTests
98+
&& knownTests == that.knownTests
99+
&& testManagementTests == that.testManagementTests;
100+
}
101+
102+
@Override
103+
public int hashCode() {
104+
return Objects.hash(settings, skippableTests, flakyTests, knownTests, testManagementTests);
105+
}
106+
}

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public class ExecutionSettings {
3939
Collections.emptyList(),
4040
Collections.emptyList(),
4141
LineDiff.EMPTY,
42-
false);
42+
ConfigurationErrors.NONE);
4343

44-
public static final ExecutionSettings REQUEST_ERROR =
44+
public static final ExecutionSettings SETTINGS_REQUEST_ERROR =
4545
new ExecutionSettings(
4646
false,
4747
false,
@@ -61,7 +61,7 @@ public class ExecutionSettings {
6161
Collections.emptyList(),
6262
Collections.emptyList(),
6363
LineDiff.EMPTY,
64-
true);
64+
new ConfigurationErrors(true, false, false, false, false));
6565

6666
private final boolean itrEnabled;
6767
private final boolean codeCoverageEnabled;
@@ -78,7 +78,7 @@ public class ExecutionSettings {
7878
@Nonnull private final Map<TestFQN, Integer> testSettings;
7979
@Nonnull private final Map<TestSetting, Integer> settingsCount;
8080
@Nonnull private final Diff pullRequestDiff;
81-
private final boolean configurationError;
81+
@Nonnull private final ConfigurationErrors configurationErrors;
8282

8383
public ExecutionSettings(
8484
boolean itrEnabled,
@@ -99,7 +99,7 @@ public ExecutionSettings(
9999
@Nonnull Collection<TestFQN> disabledTests,
100100
@Nonnull Collection<TestFQN> attemptToFixTests,
101101
@Nonnull Diff pullRequestDiff,
102-
boolean configurationError) {
102+
@Nonnull ConfigurationErrors configurationErrors) {
103103
this.itrEnabled = itrEnabled;
104104
this.codeCoverageEnabled = codeCoverageEnabled;
105105
this.testSkippingEnabled = testSkippingEnabled;
@@ -113,7 +113,7 @@ public ExecutionSettings(
113113
this.skippableTests = skippableTests;
114114
this.skippableTestsCoverage = skippableTestsCoverage;
115115
this.pullRequestDiff = pullRequestDiff;
116-
this.configurationError = configurationError;
116+
this.configurationErrors = configurationErrors;
117117

118118
testSettings = new HashMap<>();
119119
if (flakyTests != null) {
@@ -154,7 +154,7 @@ private ExecutionSettings(
154154
@Nonnull Map<TestFQN, Integer> testSettings,
155155
@Nonnull EnumMap<TestSetting, Integer> settingsCount,
156156
@Nonnull Diff pullRequestDiff,
157-
boolean configurationError) {
157+
@Nonnull ConfigurationErrors configurationErrors) {
158158
this.itrEnabled = itrEnabled;
159159
this.codeCoverageEnabled = codeCoverageEnabled;
160160
this.testSkippingEnabled = testSkippingEnabled;
@@ -170,7 +170,7 @@ private ExecutionSettings(
170170
this.testSettings = testSettings;
171171
this.settingsCount = settingsCount;
172172
this.pullRequestDiff = pullRequestDiff;
173-
this.configurationError = configurationError;
173+
this.configurationErrors = configurationErrors;
174174
}
175175

176176
/**
@@ -277,8 +277,9 @@ public Diff getPullRequestDiff() {
277277
return pullRequestDiff;
278278
}
279279

280-
public boolean isConfigurationError() {
281-
return configurationError;
280+
@Nonnull
281+
public ConfigurationErrors getConfigurationErrors() {
282+
return configurationErrors;
282283
}
283284

284285
@Override
@@ -305,7 +306,7 @@ public boolean equals(Object o) {
305306
&& Objects.equals(testSettings, that.testSettings)
306307
&& Objects.equals(settingsCount, that.settingsCount)
307308
&& Objects.equals(pullRequestDiff, that.pullRequestDiff)
308-
&& configurationError == that.configurationError;
309+
&& Objects.equals(configurationErrors, that.configurationErrors);
309310
}
310311

311312
@Override
@@ -326,7 +327,7 @@ public int hashCode() {
326327
testSettings,
327328
settingsCount,
328329
pullRequestDiff,
329-
configurationError);
330+
configurationErrors);
330331
}
331332

332333
public static class Serializer {
@@ -338,7 +339,6 @@ public static class Serializer {
338339
private static final int IMPACTED_TESTS_DETECTION_ENABLED_FLAG = 16;
339340
private static final int CODE_COVERAGE_REPORT_UPLOAD_ENABLED_FLAG = 32;
340341
private static final int FAILED_TEST_REPLAY_ENABLED_FLAG = 64;
341-
private static final int CONFIGURATION_ERROR_FLAG = 128;
342342

343343
public static ByteBuffer serialize(ExecutionSettings settings) {
344344
datadog.trace.civisibility.ipc.serialization.Serializer s =
@@ -356,10 +356,11 @@ public static ByteBuffer serialize(ExecutionSettings settings) {
356356
| (settings.codeCoverageReportUploadEnabled
357357
? CODE_COVERAGE_REPORT_UPLOAD_ENABLED_FLAG
358358
: 0)
359-
| (settings.failedTestReplayEnabled ? FAILED_TEST_REPLAY_ENABLED_FLAG : 0)
360-
| (settings.configurationError ? CONFIGURATION_ERROR_FLAG : 0));
359+
| (settings.failedTestReplayEnabled ? FAILED_TEST_REPLAY_ENABLED_FLAG : 0));
361360
s.write(flags);
362361

362+
ConfigurationErrors.serialize(s, settings.configurationErrors);
363+
363364
EarlyFlakeDetectionSettings.Serializer.serialize(s, settings.earlyFlakeDetectionSettings);
364365

365366
TestManagementSettings.Serializer.serialize(s, settings.testManagementSettings);
@@ -399,7 +400,8 @@ public static ExecutionSettings deserialize(ByteBuffer buffer) {
399400
boolean codeCoverageReportUploadEnabled =
400401
(flags & CODE_COVERAGE_REPORT_UPLOAD_ENABLED_FLAG) != 0;
401402
boolean failedTestReplayEnabled = (flags & FAILED_TEST_REPLAY_ENABLED_FLAG) != 0;
402-
boolean configurationError = (flags & CONFIGURATION_ERROR_FLAG) != 0;
403+
404+
ConfigurationErrors configurationErrors = ConfigurationErrors.deserialize(buffer);
403405

404406
EarlyFlakeDetectionSettings earlyFlakeDetectionSettings =
405407
EarlyFlakeDetectionSettings.Serializer.deserialize(buffer);
@@ -452,7 +454,7 @@ public static ExecutionSettings deserialize(ByteBuffer buffer) {
452454
testSettings,
453455
settingsCount,
454456
diff,
455-
configurationError);
457+
configurationErrors);
456458
}
457459
}
458460
}

0 commit comments

Comments
 (0)