Skip to content

Commit 4dea16f

Browse files
authored
Merge branch 'master' into alejandro.gonzalez/Configuration-to-Disable-APM-Tracing
2 parents c3dfa0b + 429031c commit 4dea16f

File tree

63 files changed

+1849
-408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1849
-408
lines changed

Diff for: .circleci/config.continue.yml.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ instrumentation_modules: &instrumentation_modules "dd-java-agent/instrumentation
3636
debugger_modules: &debugger_modules "dd-java-agent/agent-debugger|dd-java-agent/agent-bootstrap|dd-java-agent/agent-builder|internal-api|communication|dd-trace-core"
3737
profiling_modules: &profiling_modules "dd-java-agent/agent-profiling"
3838

39-
default_system_tests_commit: &default_system_tests_commit 8384a3947b9881d0fcdb5ac937b80aad9a70d4d4
39+
default_system_tests_commit: &default_system_tests_commit 35bb7f9753dc82b7c8e4a8276bf6f0ccad0e5dc3
4040

4141
parameters:
4242
nightly:

Diff for: .gitlab/benchmarks.yml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
rules:
99
- if: '$POPULATE_CACHE'
1010
when: never
11+
- if: '$CI_COMMIT_TAG =~ /^v?[0-9]+\.[0-9]+\.[0-9]+$/'
12+
when: manual
13+
allow_failure: true
1114
- when: on_success
1215
script:
1316
- export ARTIFACTS_DIR="$(pwd)/reports" && mkdir -p "${ARTIFACTS_DIR}"

Diff for: dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApi.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package datadog.trace.civisibility.config;
22

3-
import datadog.trace.api.civisibility.config.TestIdentifier;
3+
import datadog.trace.api.civisibility.config.TestFQN;
44
import java.io.IOException;
55
import java.util.Collection;
66
import java.util.Collections;
@@ -22,13 +22,19 @@ public SkippableTests getSkippableTests(TracerEnvironment tracerEnvironment) {
2222
}
2323

2424
@Override
25-
public Map<String, Collection<TestIdentifier>> getFlakyTestsByModule(
25+
public Map<String, Collection<TestFQN>> getFlakyTestsByModule(
2626
TracerEnvironment tracerEnvironment) {
2727
return Collections.emptyMap();
2828
}
2929

3030
@Override
31-
public Map<String, Collection<TestIdentifier>> getKnownTestsByModule(
31+
public Map<String, Collection<TestFQN>> getKnownTestsByModule(
32+
TracerEnvironment tracerEnvironment) {
33+
return Collections.emptyMap();
34+
}
35+
36+
@Override
37+
public Map<TestSetting, Map<String, Collection<TestFQN>>> getTestManagementTestsByModule(
3238
TracerEnvironment tracerEnvironment) {
3339
return Collections.emptyMap();
3440
}
@@ -43,12 +49,15 @@ public ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) {
4349

4450
SkippableTests getSkippableTests(TracerEnvironment tracerEnvironment) throws IOException;
4551

46-
Map<String, Collection<TestIdentifier>> getFlakyTestsByModule(TracerEnvironment tracerEnvironment)
52+
Map<String, Collection<TestFQN>> getFlakyTestsByModule(TracerEnvironment tracerEnvironment)
4753
throws IOException;
4854

4955
@Nullable
50-
Map<String, Collection<TestIdentifier>> getKnownTestsByModule(TracerEnvironment tracerEnvironment)
56+
Map<String, Collection<TestFQN>> getKnownTestsByModule(TracerEnvironment tracerEnvironment)
5157
throws IOException;
5258

59+
Map<TestSetting, Map<String, Collection<TestFQN>>> getTestManagementTestsByModule(
60+
TracerEnvironment tracerEnvironment) throws IOException;
61+
5362
ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) throws IOException;
5463
}

Diff for: dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ConfigurationApiImpl.java

+163-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import datadog.communication.BackendApi;
99
import datadog.communication.http.OkHttpUtils;
1010
import datadog.trace.api.civisibility.config.Configurations;
11+
import datadog.trace.api.civisibility.config.TestFQN;
1112
import datadog.trace.api.civisibility.config.TestIdentifier;
1213
import datadog.trace.api.civisibility.config.TestMetadata;
1314
import datadog.trace.api.civisibility.telemetry.CiVisibilityCountMetric;
@@ -54,6 +55,7 @@ public class ConfigurationApiImpl implements ConfigurationApi {
5455
private static final String CHANGED_FILES_URI = "ci/tests/diffs";
5556
private static final String FLAKY_TESTS_URI = "ci/libraries/tests/flaky";
5657
private static final String KNOWN_TESTS_URI = "ci/libraries/tests";
58+
private static final String TEST_MANAGEMENT_TESTS_URI = "test/libraries/test-management/tests";
5759

5860
private final BackendApi backendApi;
5961
private final CiVisibilityMetricCollector metricCollector;
@@ -63,6 +65,7 @@ public class ConfigurationApiImpl implements ConfigurationApi {
6365
private final JsonAdapter<EnvelopeDto<CiVisibilitySettings>> settingsResponseAdapter;
6466
private final JsonAdapter<MultiEnvelopeDto<TestIdentifierJson>> testIdentifiersResponseAdapter;
6567
private final JsonAdapter<EnvelopeDto<KnownTestsDto>> testFullNamesResponseAdapter;
68+
private final JsonAdapter<EnvelopeDto<TestManagementTestsDto>> testManagementTestsResponseAdapter;
6669
private final JsonAdapter<EnvelopeDto<ChangedFiles>> changedFilesResponseAdapter;
6770

6871
public ConfigurationApiImpl(BackendApi backendApi, CiVisibilityMetricCollector metricCollector) {
@@ -105,6 +108,11 @@ public ConfigurationApiImpl(BackendApi backendApi, CiVisibilityMetricCollector m
105108
ConfigurationApiImpl.class, EnvelopeDto.class, KnownTestsDto.class);
106109
testFullNamesResponseAdapter = moshi.adapter(testFullNamesResponseType);
107110

111+
ParameterizedType testManagementTestsResponseType =
112+
Types.newParameterizedTypeWithOwner(
113+
ConfigurationApiImpl.class, EnvelopeDto.class, TestManagementTestsDto.class);
114+
testManagementTestsResponseAdapter = moshi.adapter(testManagementTestsResponseType);
115+
108116
ParameterizedType changedFilesResponseAdapterType =
109117
Types.newParameterizedTypeWithOwner(
110118
ConfigurationApiImpl.class, EnvelopeDto.class, ChangedFiles.class);
@@ -202,8 +210,8 @@ public SkippableTests getSkippableTests(TracerEnvironment tracerEnvironment) thr
202210
}
203211

204212
@Override
205-
public Map<String, Collection<TestIdentifier>> getFlakyTestsByModule(
206-
TracerEnvironment tracerEnvironment) throws IOException {
213+
public Map<String, Collection<TestFQN>> getFlakyTestsByModule(TracerEnvironment tracerEnvironment)
214+
throws IOException {
207215
OkHttpUtils.CustomListener telemetryListener =
208216
new TelemetryListener.Builder(metricCollector)
209217
.requestCount(CiVisibilityCountMetric.FLAKY_TESTS_REQUEST)
@@ -231,15 +239,15 @@ public Map<String, Collection<TestIdentifier>> getFlakyTestsByModule(
231239
Configurations requestConf = tracerEnvironment.getConfigurations();
232240

233241
int flakyTestsCount = 0;
234-
Map<String, Collection<TestIdentifier>> testIdentifiers = new HashMap<>();
242+
Map<String, Collection<TestFQN>> testIdentifiers = new HashMap<>();
235243
for (DataDto<TestIdentifierJson> dataDto : response) {
236244
TestIdentifierJson testIdentifierJson = dataDto.getAttributes();
237245
Configurations conf = testIdentifierJson.getConfigurations();
238246
String moduleName =
239247
(conf != null && conf.getTestBundle() != null ? conf : requestConf).getTestBundle();
240248
testIdentifiers
241249
.computeIfAbsent(moduleName, k -> new HashSet<>())
242-
.add(testIdentifierJson.toTestIdentifier());
250+
.add(testIdentifierJson.toTestIdentifier().toFQN());
243251
flakyTestsCount++;
244252
}
245253

@@ -249,8 +257,8 @@ public Map<String, Collection<TestIdentifier>> getFlakyTestsByModule(
249257

250258
@Nullable
251259
@Override
252-
public Map<String, Collection<TestIdentifier>> getKnownTestsByModule(
253-
TracerEnvironment tracerEnvironment) throws IOException {
260+
public Map<String, Collection<TestFQN>> getKnownTestsByModule(TracerEnvironment tracerEnvironment)
261+
throws IOException {
254262
OkHttpUtils.CustomListener telemetryListener =
255263
new TelemetryListener.Builder(metricCollector)
256264
.requestCount(CiVisibilityCountMetric.KNOWN_TESTS_REQUEST)
@@ -276,10 +284,10 @@ public Map<String, Collection<TestIdentifier>> getKnownTestsByModule(
276284
return parseTestIdentifiers(knownTests);
277285
}
278286

279-
private Map<String, Collection<TestIdentifier>> parseTestIdentifiers(KnownTestsDto knownTests) {
287+
private Map<String, Collection<TestFQN>> parseTestIdentifiers(KnownTestsDto knownTests) {
280288
int knownTestsCount = 0;
281289

282-
Map<String, Collection<TestIdentifier>> testIdentifiers = new HashMap<>();
290+
Map<String, Collection<TestFQN>> testIdentifiers = new HashMap<>();
283291
for (Map.Entry<String, Map<String, List<String>>> e : knownTests.tests.entrySet()) {
284292
String moduleName = e.getKey();
285293
Map<String, List<String>> testsBySuiteName = e.getValue();
@@ -292,7 +300,7 @@ private Map<String, Collection<TestIdentifier>> parseTestIdentifiers(KnownTestsD
292300
for (String testName : testNames) {
293301
testIdentifiers
294302
.computeIfAbsent(moduleName, k -> new HashSet<>())
295-
.add(new TestIdentifier(suiteName, testName, null));
303+
.add(new TestFQN(suiteName, testName));
296304
}
297305
}
298306
}
@@ -309,6 +317,90 @@ private Map<String, Collection<TestIdentifier>> parseTestIdentifiers(KnownTestsD
309317
: null;
310318
}
311319

320+
@Override
321+
public Map<TestSetting, Map<String, Collection<TestFQN>>> getTestManagementTestsByModule(
322+
TracerEnvironment tracerEnvironment) throws IOException {
323+
OkHttpUtils.CustomListener telemetryListener =
324+
new TelemetryListener.Builder(metricCollector)
325+
.requestCount(CiVisibilityCountMetric.TEST_MANAGEMENT_TESTS_REQUEST)
326+
.requestErrors(CiVisibilityCountMetric.TEST_MANAGEMENT_TESTS_REQUEST_ERRORS)
327+
.requestDuration(CiVisibilityDistributionMetric.TEST_MANAGEMENT_TESTS_REQUEST_MS)
328+
.responseBytes(CiVisibilityDistributionMetric.TEST_MANAGEMENT_TESTS_RESPONSE_BYTES)
329+
.build();
330+
331+
String uuid = uuidGenerator.get();
332+
EnvelopeDto<TracerEnvironment> request =
333+
new EnvelopeDto<>(new DataDto<>(uuid, "ci_app_libraries_tests_request", tracerEnvironment));
334+
String json = requestAdapter.toJson(request);
335+
RequestBody requestBody = RequestBody.create(JSON, json);
336+
TestManagementTestsDto testManagementTestsDto =
337+
backendApi.post(
338+
TEST_MANAGEMENT_TESTS_URI,
339+
requestBody,
340+
is ->
341+
testManagementTestsResponseAdapter.fromJson(Okio.buffer(Okio.source(is)))
342+
.data
343+
.attributes,
344+
telemetryListener,
345+
false);
346+
347+
return parseTestManagementTests(testManagementTestsDto);
348+
}
349+
350+
private Map<TestSetting, Map<String, Collection<TestFQN>>> parseTestManagementTests(
351+
TestManagementTestsDto testsManagementTestsDto) {
352+
int testManagementTestsCount = 0;
353+
354+
Map<String, Collection<TestFQN>> quarantinedTestsByModule = new HashMap<>();
355+
Map<String, Collection<TestFQN>> disabledTestsByModule = new HashMap<>();
356+
Map<String, Collection<TestFQN>> attemptToFixTestsByModule = new HashMap<>();
357+
358+
for (Map.Entry<String, TestManagementTestsDto.Suites> e :
359+
testsManagementTestsDto.getModules().entrySet()) {
360+
String moduleName = e.getKey();
361+
Map<String, TestManagementTestsDto.Tests> testsBySuiteName = e.getValue().getSuites();
362+
363+
for (Map.Entry<String, TestManagementTestsDto.Tests> se : testsBySuiteName.entrySet()) {
364+
String suiteName = se.getKey();
365+
Map<String, TestManagementTestsDto.Properties> tests = se.getValue().getTests();
366+
367+
testManagementTestsCount += tests.size();
368+
369+
for (Map.Entry<String, TestManagementTestsDto.Properties> te : tests.entrySet()) {
370+
String testName = te.getKey();
371+
TestManagementTestsDto.Properties properties = te.getValue();
372+
if (properties.isQuarantined()) {
373+
quarantinedTestsByModule
374+
.computeIfAbsent(moduleName, k -> new HashSet<>())
375+
.add(new TestFQN(suiteName, testName));
376+
}
377+
if (properties.isDisabled()) {
378+
disabledTestsByModule
379+
.computeIfAbsent(moduleName, k -> new HashSet<>())
380+
.add(new TestFQN(suiteName, testName));
381+
}
382+
if (properties.isAttemptToFix()) {
383+
attemptToFixTestsByModule
384+
.computeIfAbsent(moduleName, k -> new HashSet<>())
385+
.add(new TestFQN(suiteName, testName));
386+
}
387+
}
388+
}
389+
}
390+
391+
Map<TestSetting, Map<String, Collection<TestFQN>>> testsByTypeByModule = new HashMap<>();
392+
testsByTypeByModule.put(TestSetting.QUARANTINED, quarantinedTestsByModule);
393+
testsByTypeByModule.put(TestSetting.DISABLED, disabledTestsByModule);
394+
testsByTypeByModule.put(TestSetting.ATTEMPT_TO_FIX, attemptToFixTestsByModule);
395+
396+
LOGGER.debug("Received {} test management tests in total", testManagementTestsCount);
397+
metricCollector.add(
398+
CiVisibilityDistributionMetric.TEST_MANAGEMENT_TESTS_RESPONSE_TESTS,
399+
testManagementTestsCount);
400+
401+
return testsByTypeByModule;
402+
}
403+
312404
@Override
313405
public ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) throws IOException {
314406
OkHttpUtils.CustomListener telemetryListener =
@@ -427,4 +519,66 @@ private KnownTestsDto(Map<String, Map<String, List<String>>> tests) {
427519
this.tests = tests;
428520
}
429521
}
522+
523+
private static final class TestManagementTestsDto {
524+
private static final class Properties {
525+
private final Map<String, Boolean> properties;
526+
527+
private Properties(Map<String, Boolean> properties) {
528+
this.properties = properties;
529+
}
530+
531+
public Boolean isQuarantined() {
532+
return properties != null
533+
? properties.getOrDefault(TestSetting.QUARANTINED.asString(), false)
534+
: false;
535+
}
536+
537+
public Boolean isDisabled() {
538+
return properties != null
539+
? properties.getOrDefault(TestSetting.DISABLED.asString(), false)
540+
: false;
541+
}
542+
543+
public Boolean isAttemptToFix() {
544+
return properties != null
545+
? properties.getOrDefault(TestSetting.ATTEMPT_TO_FIX.asString(), false)
546+
: false;
547+
}
548+
}
549+
550+
private static final class Tests {
551+
private final Map<String, Properties> tests;
552+
553+
private Tests(Map<String, Properties> tests) {
554+
this.tests = tests;
555+
}
556+
557+
public Map<String, Properties> getTests() {
558+
return tests != null ? tests : Collections.emptyMap();
559+
}
560+
}
561+
562+
private static final class Suites {
563+
private final Map<String, Tests> suites;
564+
565+
private Suites(Map<String, Tests> suites) {
566+
this.suites = suites;
567+
}
568+
569+
public Map<String, Tests> getSuites() {
570+
return suites != null ? suites : Collections.emptyMap();
571+
}
572+
}
573+
574+
private final Map<String, Suites> modules;
575+
576+
private TestManagementTestsDto(Map<String, Suites> modules) {
577+
this.modules = modules;
578+
}
579+
580+
public Map<String, Suites> getModules() {
581+
return modules != null ? modules : Collections.emptyMap();
582+
}
583+
}
430584
}

0 commit comments

Comments
 (0)