Skip to content

Commit

Permalink
Disable backend requests for impacted tests data (#8391)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-tkachenko-datadog authored Feb 14, 2025
1 parent 053a36f commit acf173a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,28 +431,30 @@ private Diff getPullRequestDiff(
LOGGER.error("Could not get git diff for PR: {}", pullRequestInfo, e);
}

try {
ChangedFiles changedFiles = configurationApi.getChangedFiles(tracerEnvironment);

// attempting to use base SHA returned by the backend to calculate git diff
if (repositoryRoot != null) {
// ensure repo is not shallow before attempting to get git diff
gitRepoUnshallow.unshallow();
Diff diff = gitClient.getGitDiff(changedFiles.getBaseSha(), tracerEnvironment.getSha());
if (diff != null) {
return diff;
if (config.isCiVisibilityImpactedTestsBackendRequestEnabled()) {
try {
ChangedFiles changedFiles = configurationApi.getChangedFiles(tracerEnvironment);

// attempting to use base SHA returned by the backend to calculate git diff
if (repositoryRoot != null) {
// ensure repo is not shallow before attempting to get git diff
gitRepoUnshallow.unshallow();
Diff diff = gitClient.getGitDiff(changedFiles.getBaseSha(), tracerEnvironment.getSha());
if (diff != null) {
return diff;
}
}
}

// falling back to file-level granularity
return new FileDiff(changedFiles.getFiles());
// falling back to file-level granularity
return new FileDiff(changedFiles.getFiles());

} catch (InterruptedException e) {
LOGGER.error("Interrupted while getting git diff for: {}", tracerEnvironment, e);
Thread.currentThread().interrupt();
} catch (InterruptedException e) {
LOGGER.error("Interrupted while getting git diff for: {}", tracerEnvironment, e);
Thread.currentThread().interrupt();

} catch (Exception e) {
LOGGER.error("Could not get git diff for: {}", tracerEnvironment, e);
} catch (Exception e) {
LOGGER.error("Could not get git diff for: {}", tracerEnvironment, e);
}
}

return LineDiff.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
mockBackend.givenChangedFile("src/test/java/datadog/smoke/TestSucceed.java")

def exitCode = whenRunningMavenBuild([
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_CLIENT_ENABLED)}=false" as String
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_CLIENT_ENABLED)}=false" as String,
"${Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_IMPACTED_TESTS_BACKEND_REQUEST_ENABLED)}=true" as String
], [])
assert exitCode == 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public final class CiVisibilityConfig {
public static final String CIVISIBILITY_FLAKY_RETRY_ENABLED = "civisibility.flaky.retry.enabled";
public static final String CIVISIBILITY_IMPACTED_TESTS_DETECTION_ENABLED =
"civisibility.impacted.tests.detection.enabled";
public static final String CIVISIBILITY_IMPACTED_TESTS_BACKEND_REQUEST_ENABLED =
"civisibility.impacted.tests.backend.request.enabled";
public static final String CIVISIBILITY_KNOWN_TESTS_REQUEST_ENABLED =
"civisibility.known.tests.request.enabled";
public static final String CIVISIBILITY_FLAKY_RETRY_ONLY_KNOWN_FLAKES =
Expand Down
7 changes: 7 additions & 0 deletions internal-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ public static String getHostName() {
private final List<String> ciVisibilityResourceFolderNames;
private final boolean ciVisibilityFlakyRetryEnabled;
private final boolean ciVisibilityImpactedTestsDetectionEnabled;
private final boolean ciVisibilityImpactedTestsBackendRequestEnabled;
private final boolean ciVisibilityKnownTestsRequestEnabled;
private final boolean ciVisibilityFlakyRetryOnlyKnownFlakes;
private final int ciVisibilityFlakyRetryCount;
Expand Down Expand Up @@ -1501,6 +1502,8 @@ PROFILING_DATADOG_PROFILER_ENABLED, isDatadogProfilerSafeInCurrentEnvironment())
configProvider.getBoolean(CIVISIBILITY_FLAKY_RETRY_ENABLED, true);
ciVisibilityImpactedTestsDetectionEnabled =
configProvider.getBoolean(CIVISIBILITY_IMPACTED_TESTS_DETECTION_ENABLED, true);
ciVisibilityImpactedTestsBackendRequestEnabled =
configProvider.getBoolean(CIVISIBILITY_IMPACTED_TESTS_BACKEND_REQUEST_ENABLED, false);
ciVisibilityKnownTestsRequestEnabled =
configProvider.getBoolean(CIVISIBILITY_KNOWN_TESTS_REQUEST_ENABLED, true);
ciVisibilityFlakyRetryOnlyKnownFlakes =
Expand Down Expand Up @@ -2945,6 +2948,10 @@ public boolean isCiVisibilityImpactedTestsDetectionEnabled() {
return ciVisibilityImpactedTestsDetectionEnabled;
}

public boolean isCiVisibilityImpactedTestsBackendRequestEnabled() {
return ciVisibilityImpactedTestsBackendRequestEnabled;
}

public boolean isCiVisibilityKnownTestsRequestEnabled() {
return ciVisibilityKnownTestsRequestEnabled;
}
Expand Down

0 comments on commit acf173a

Please sign in to comment.