Skip to content

Commit 63ce8fb

Browse files
authored
Merge branch 'master' into alejandro.gonzalez/api-sec-jersey-response-schema
2 parents 51304cd + df6adb3 commit 63ce8fb

File tree

213 files changed

+1472
-1060
lines changed

Some content is hidden

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

213 files changed

+1472
-1060
lines changed

benchmark/README.MD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ This directory contains different types of benchmarks.
44

55
## Running Benchmarks via Docker
66

7-
Docker allows the execution of benchmarks without needing to install and configure your development environment. For example, package installation and installation of sirun is performed automatically.
7+
Docker allows the execution of benchmarks without needing to install and configure your development environment. For example, package installation and installation of sirun are performed automatically.
88

9-
In order to run benchmarks using Docker, issue the following command from the benchmark folder of the project:
9+
In order to run benchmarks using Docker, issue the following command from the `benchmark/` folder of this project:
1010

1111
```sh
1212
./run.sh
1313
```
1414

15-
Once it finishes, the reports will be available in the reports folder.
15+
If you run into storage errors (e.g. running out of disk space), try removing all unused Docker containers, networks, and images with `docker system prune -af` before running the script again. Once finished, the reports will be available in the `benchmark/reports/` folder. Note that the script can take ~40 minutes to run.
1616

1717
### Running specific benchmarks
1818

19-
If you want to run only a specific category of benchmarks you can do it via arguments:
19+
If you want to run only a specific category of benchmarks, you can do so via arguments:
2020

2121
1. Run startup benchmarks
2222
```sh

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ buildscript {
1313
}
1414

1515
plugins {
16-
id "datadog.gradle-debug"
17-
id "datadog.dependency-locking"
16+
id 'datadog.gradle-debug'
17+
id 'datadog.dependency-locking'
1818

19-
id "com.diffplug.spotless" version "6.13.0"
19+
id 'com.diffplug.spotless' version '6.13.0'
2020
id 'com.github.spotbugs' version '5.0.14'
21-
id "de.thetaphi.forbiddenapis" version "3.8"
21+
id 'de.thetaphi.forbiddenapis' version '3.8'
2222

2323
id 'pl.allegro.tech.build.axion-release' version '1.14.4'
2424
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
2525

26-
id "com.gradleup.shadow" version "8.3.6" apply false
27-
id "me.champeau.jmh" version "0.7.0" apply false
26+
id 'com.gradleup.shadow' version '8.3.6' apply false
27+
id 'me.champeau.jmh' version '0.7.0' apply false
2828
id 'org.gradle.playframework' version '0.13' apply false
2929
id 'info.solidsoft.pitest' version '1.9.11' apply false
3030
}

buildSrc/src/test/groovy/CallSiteInstrumentationPluginTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CallSiteInstrumentationPluginTest extends Specification {
1010
plugins {
1111
id 'java'
1212
id 'call-site-instrumentation'
13-
id("com.diffplug.spotless") version "6.13.0"
13+
id 'com.diffplug.spotless' version '6.13.0'
1414
}
1515
1616
sourceCompatibility = JavaVersion.VERSION_1_8

dd-java-agent/agent-bootstrap/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The shadowJar of this project will be injected into the JVM's bootstrap classloader
22
plugins {
3-
id "com.gradleup.shadow"
3+
id 'com.gradleup.shadow'
44
id 'me.champeau.jmh'
55
}
66

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public CIInfo buildCIInfo() {
9494
@Override
9595
public PullRequestInfo buildPullRequestInfo() {
9696
String baseRef = environment.get(GITHUB_BASE_REF);
97-
if (!Strings.isNotBlank(baseRef)) {
97+
if (Strings.isBlank(baseRef)) {
9898
return PullRequestInfo.EMPTY;
9999
}
100100

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

Lines changed: 0 additions & 28 deletions
This file was deleted.

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
@@ -4,6 +4,7 @@
44
import java.nio.file.Path;
55
import java.util.Map;
66
import java.util.Objects;
7+
import javax.annotation.Nullable;
78

89
public class CiVisibilitySettings {
910

@@ -17,7 +18,8 @@ public class CiVisibilitySettings {
1718
false,
1819
false,
1920
EarlyFlakeDetectionSettings.DEFAULT,
20-
TestManagementSettings.DEFAULT);
21+
TestManagementSettings.DEFAULT,
22+
null);
2123

2224
private final boolean itrEnabled;
2325
private final boolean codeCoverage;
@@ -28,6 +30,7 @@ public class CiVisibilitySettings {
2830
private final boolean knownTestsEnabled;
2931
private final EarlyFlakeDetectionSettings earlyFlakeDetectionSettings;
3032
private final TestManagementSettings testManagementSettings;
33+
@Nullable private final String defaultBranch;
3134

3235
CiVisibilitySettings(
3336
boolean itrEnabled,
@@ -38,7 +41,8 @@ public class CiVisibilitySettings {
3841
boolean impactedTestsDetectionEnabled,
3942
boolean knownTestsEnabled,
4043
EarlyFlakeDetectionSettings earlyFlakeDetectionSettings,
41-
TestManagementSettings testManagementSettings) {
44+
TestManagementSettings testManagementSettings,
45+
@Nullable String defaultBranch) {
4246
this.itrEnabled = itrEnabled;
4347
this.codeCoverage = codeCoverage;
4448
this.testsSkipping = testsSkipping;
@@ -48,6 +52,7 @@ public class CiVisibilitySettings {
4852
this.knownTestsEnabled = knownTestsEnabled;
4953
this.earlyFlakeDetectionSettings = earlyFlakeDetectionSettings;
5054
this.testManagementSettings = testManagementSettings;
55+
this.defaultBranch = defaultBranch;
5156
}
5257

5358
public boolean isItrEnabled() {
@@ -86,6 +91,11 @@ public TestManagementSettings getTestManagementSettings() {
8691
return testManagementSettings;
8792
}
8893

94+
@Nullable
95+
public String getDefaultBranch() {
96+
return defaultBranch;
97+
}
98+
8999
@Override
90100
public boolean equals(Object o) {
91101
if (this == o) {
@@ -103,7 +113,8 @@ public boolean equals(Object o) {
103113
&& impactedTestsDetectionEnabled == that.impactedTestsDetectionEnabled
104114
&& knownTestsEnabled == that.knownTestsEnabled
105115
&& Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings)
106-
&& Objects.equals(testManagementSettings, that.testManagementSettings);
116+
&& Objects.equals(testManagementSettings, that.testManagementSettings)
117+
&& Objects.equals(defaultBranch, that.defaultBranch);
107118
}
108119

109120
@Override
@@ -117,7 +128,8 @@ public int hashCode() {
117128
impactedTestsDetectionEnabled,
118129
knownTestsEnabled,
119130
earlyFlakeDetectionSettings,
120-
testManagementSettings);
131+
testManagementSettings,
132+
defaultBranch);
121133
}
122134

123135
public interface Factory {
@@ -145,13 +157,20 @@ public CiVisibilitySettings fromJson(Map<String, Object> json) {
145157
EarlyFlakeDetectionSettings.JsonAdapter.INSTANCE.fromJson(
146158
(Map<String, Object>) json.get("early_flake_detection")),
147159
TestManagementSettings.JsonAdapter.INSTANCE.fromJson(
148-
(Map<String, Object>) json.get("test_management")));
160+
(Map<String, Object>) json.get("test_management")),
161+
getString(json, "default_branch", null));
149162
}
150163

151164
private static boolean getBoolean(
152165
Map<String, Object> json, String fieldName, boolean defaultValue) {
153166
Object value = json.get(fieldName);
154167
return value instanceof Boolean ? (Boolean) value : defaultValue;
155168
}
169+
170+
private static String getString(
171+
Map<String, Object> json, String fieldName, String defaultValue) {
172+
Object value = json.get(fieldName);
173+
return value instanceof String ? (String) value : defaultValue;
174+
}
156175
}
157176
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ public Map<TestSetting, Map<String, Collection<TestFQN>>> getTestManagementTests
3838
TracerEnvironment tracerEnvironment) {
3939
return Collections.emptyMap();
4040
}
41-
42-
@Override
43-
public ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) {
44-
return ChangedFiles.EMPTY;
45-
}
4641
};
4742

4843
CiVisibilitySettings getSettings(TracerEnvironment tracerEnvironment) throws IOException;
@@ -58,6 +53,4 @@ Map<String, Collection<TestFQN>> getKnownTestsByModule(TracerEnvironment tracerE
5853

5954
Map<TestSetting, Map<String, Collection<TestFQN>>> getTestManagementTestsByModule(
6055
TracerEnvironment tracerEnvironment) throws IOException;
61-
62-
ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) throws IOException;
6356
}

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

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public class ConfigurationApiImpl implements ConfigurationApi {
5353

5454
private static final String SETTINGS_URI = "libraries/tests/services/setting";
5555
private static final String SKIPPABLE_TESTS_URI = "ci/tests/skippable";
56-
private static final String CHANGED_FILES_URI = "ci/tests/diffs";
5756
private static final String FLAKY_TESTS_URI = "ci/libraries/tests/flaky";
5857
private static final String KNOWN_TESTS_URI = "ci/libraries/tests";
5958
private static final String TEST_MANAGEMENT_TESTS_URI = "test/libraries/test-management/tests";
@@ -68,7 +67,6 @@ public class ConfigurationApiImpl implements ConfigurationApi {
6867
private final JsonAdapter<EnvelopeDto<KnownTestsDto>> testFullNamesResponseAdapter;
6968
private final JsonAdapter<EnvelopeDto<TestManagementDto>> testManagementRequestAdapter;
7069
private final JsonAdapter<EnvelopeDto<TestManagementTestsDto>> testManagementTestsResponseAdapter;
71-
private final JsonAdapter<EnvelopeDto<ChangedFiles>> changedFilesResponseAdapter;
7270

7371
public ConfigurationApiImpl(BackendApi backendApi, CiVisibilityMetricCollector metricCollector) {
7472
this(backendApi, metricCollector, () -> RandomUtils.randomUUID().toString());
@@ -119,11 +117,6 @@ public ConfigurationApiImpl(BackendApi backendApi, CiVisibilityMetricCollector m
119117
Types.newParameterizedTypeWithOwner(
120118
ConfigurationApiImpl.class, EnvelopeDto.class, TestManagementTestsDto.class);
121119
testManagementTestsResponseAdapter = moshi.adapter(testManagementTestsResponseType);
122-
123-
ParameterizedType changedFilesResponseAdapterType =
124-
Types.newParameterizedTypeWithOwner(
125-
ConfigurationApiImpl.class, EnvelopeDto.class, ChangedFiles.class);
126-
changedFilesResponseAdapter = moshi.adapter(changedFilesResponseAdapterType);
127120
}
128121

129122
@Override
@@ -416,37 +409,6 @@ private Map<TestSetting, Map<String, Collection<TestFQN>>> parseTestManagementTe
416409
return testsByTypeByModule;
417410
}
418411

419-
@Override
420-
public ChangedFiles getChangedFiles(TracerEnvironment tracerEnvironment) throws IOException {
421-
OkHttpUtils.CustomListener telemetryListener =
422-
new TelemetryListener.Builder(metricCollector)
423-
.requestCount(CiVisibilityCountMetric.IMPACTED_TESTS_DETECTION_REQUEST)
424-
.requestErrors(CiVisibilityCountMetric.IMPACTED_TESTS_DETECTION_REQUEST_ERRORS)
425-
.requestDuration(CiVisibilityDistributionMetric.IMPACTED_TESTS_DETECTION_REQUEST_MS)
426-
.responseBytes(CiVisibilityDistributionMetric.IMPACTED_TESTS_DETECTION_RESPONSE_BYTES)
427-
.build();
428-
429-
String uuid = uuidGenerator.get();
430-
EnvelopeDto<TracerEnvironment> request =
431-
new EnvelopeDto<>(new DataDto<>(uuid, "ci_app_tests_diffs_request", tracerEnvironment));
432-
String json = requestAdapter.toJson(request);
433-
RequestBody requestBody = RequestBody.create(JSON, json);
434-
ChangedFiles changedFiles =
435-
backendApi.post(
436-
CHANGED_FILES_URI,
437-
requestBody,
438-
is ->
439-
changedFilesResponseAdapter.fromJson(Okio.buffer(Okio.source(is))).data.attributes,
440-
telemetryListener,
441-
false);
442-
443-
int filesCount = changedFiles.getFiles().size();
444-
LOGGER.debug("Received {} changed files", filesCount);
445-
metricCollector.add(
446-
CiVisibilityDistributionMetric.IMPACTED_TESTS_DETECTION_RESPONSE_FILES, filesCount);
447-
return changedFiles;
448-
}
449-
450412
private static final class EnvelopeDto<T> {
451413
private final DataDto<T> data;
452414

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

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import datadog.trace.api.git.GitInfoProvider;
99
import datadog.trace.civisibility.ci.PullRequestInfo;
1010
import datadog.trace.civisibility.diff.Diff;
11-
import datadog.trace.civisibility.diff.FileDiff;
1211
import datadog.trace.civisibility.diff.LineDiff;
1312
import datadog.trace.civisibility.git.tree.GitClient;
1413
import datadog.trace.civisibility.git.tree.GitDataUploader;
@@ -215,7 +214,8 @@ private Map<String, ExecutionSettings> doCreate(
215214
getTestManagementTestsByModule(
216215
tracerEnvironment, testManagementSettings.isEnabled()));
217216
Future<Diff> pullRequestDiffFuture =
218-
executor.submit(() -> getPullRequestDiff(tracerEnvironment, impactedTestsEnabled));
217+
executor.submit(
218+
() -> getPullRequestDiff(impactedTestsEnabled, settings.getDefaultBranch()));
219219

220220
SkippableTests skippableTests = skippableTestsFuture.get();
221221
Map<String, Collection<TestFQN>> flakyTestsByModule = flakyTestsFuture.get();
@@ -404,8 +404,7 @@ private Map<TestSetting, Map<String, Collection<TestFQN>>> getTestManagementTest
404404
}
405405

406406
@Nonnull
407-
private Diff getPullRequestDiff(
408-
TracerEnvironment tracerEnvironment, boolean impactedTestsDetectionEnabled) {
407+
private Diff getPullRequestDiff(boolean impactedTestsDetectionEnabled, String defaultBranch) {
409408
if (!impactedTestsDetectionEnabled) {
410409
return LineDiff.EMPTY;
411410
}
@@ -414,49 +413,25 @@ private Diff getPullRequestDiff(
414413
if (repositoryRoot != null) {
415414
// ensure repo is not shallow before attempting to get git diff
416415
gitRepoUnshallow.unshallow();
417-
Diff diff =
418-
gitClient.getGitDiff(
419-
pullRequestInfo.getPullRequestBaseBranchSha(),
420-
pullRequestInfo.getGitCommitHeadSha());
416+
417+
String baseCommitSha = pullRequestInfo.getPullRequestBaseBranchSha();
418+
if (baseCommitSha == null) {
419+
baseCommitSha =
420+
gitClient.getBaseCommitSha(pullRequestInfo.getPullRequestBaseBranch(), defaultBranch);
421+
}
422+
423+
Diff diff = gitClient.getGitDiff(baseCommitSha, pullRequestInfo.getGitCommitHeadSha());
421424
if (diff != null) {
422425
return diff;
423426
}
424427
}
425-
426428
} catch (InterruptedException e) {
427429
LOGGER.error("Interrupted while getting git diff for PR: {}", pullRequestInfo, e);
428430
Thread.currentThread().interrupt();
429-
430431
} catch (Exception e) {
431432
LOGGER.error("Could not get git diff for PR: {}", pullRequestInfo, e);
432433
}
433434

434-
if (config.isCiVisibilityImpactedTestsBackendRequestEnabled()) {
435-
try {
436-
ChangedFiles changedFiles = configurationApi.getChangedFiles(tracerEnvironment);
437-
438-
// attempting to use base SHA returned by the backend to calculate git diff
439-
if (repositoryRoot != null) {
440-
// ensure repo is not shallow before attempting to get git diff
441-
gitRepoUnshallow.unshallow();
442-
Diff diff = gitClient.getGitDiff(changedFiles.getBaseSha(), tracerEnvironment.getSha());
443-
if (diff != null) {
444-
return diff;
445-
}
446-
}
447-
448-
// falling back to file-level granularity
449-
return new FileDiff(changedFiles.getFiles());
450-
451-
} catch (InterruptedException e) {
452-
LOGGER.error("Interrupted while getting git diff for: {}", tracerEnvironment, e);
453-
Thread.currentThread().interrupt();
454-
455-
} catch (Exception e) {
456-
LOGGER.error("Could not get git diff for: {}", tracerEnvironment, e);
457-
}
458-
}
459-
460435
return LineDiff.EMPTY;
461436
}
462437

0 commit comments

Comments
 (0)