Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ public enum Intake {
"http-intake.logs",
"v2",
Config::isAgentlessLogSubmissionEnabled,
Config::getAgentlessLogSubmissionUrl);
Config::getAgentlessLogSubmissionUrl),
CI_INTAKE(
"ci-intake",
"v2",
Config::isCiVisibilityAgentlessEnabled,
Config::getCiVisibilityIntakeAgentlessUrl);

public final String urlPrefix;
public final String version;
Expand Down
1 change: 1 addition & 0 deletions dd-java-agent/agent-ci-visibility/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies {
testFixturesApi group: 'com.jayway.jsonpath', name: 'json-path', version: '2.8.0'
testFixturesApi group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.16.0'
testFixturesApi group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.9.6'
testFixturesApi group: 'org.xmlunit', name: 'xmlunit-core', version: '2.10.3'

testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.9.2") // Required to update dependency lock files
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,45 @@
import datadog.trace.api.civisibility.coverage.CoverageStore;
import datadog.trace.api.civisibility.coverage.NoOpCoverageStore;
import datadog.trace.civisibility.config.ExecutionSettings;
import datadog.trace.civisibility.config.JvmInfo;
import datadog.trace.civisibility.coverage.SkippableAwareCoverageStoreFactory;
import datadog.trace.civisibility.coverage.file.FileCoverageStore;
import datadog.trace.civisibility.coverage.line.LineCoverageStore;
import datadog.trace.civisibility.coverage.percentage.CoverageCalculator;
import datadog.trace.civisibility.coverage.percentage.JacocoCoverageCalculator;
import datadog.trace.civisibility.coverage.percentage.child.ChildProcessCoverageReporter;
import datadog.trace.civisibility.coverage.percentage.child.JacocoChildProcessCoverageReporter;
import datadog.trace.civisibility.coverage.report.CoverageProcessor;
import datadog.trace.civisibility.coverage.report.CoverageReportUploader;
import datadog.trace.civisibility.coverage.report.JacocoCoverageProcessor;
import datadog.trace.civisibility.coverage.report.child.ChildProcessCoverageReporter;
import datadog.trace.civisibility.coverage.report.child.JacocoChildProcessCoverageReporter;
import datadog.trace.civisibility.domain.buildsystem.ModuleSignalRouter;
import java.util.Map;

/**
* Services that are related to coverage calculation (both per-test coverage and total coverage
* percentage). The scope is session/module.
* Services that are related to per-test code coverage and coverage report uploads. The scope is
* session/module.
*/
public class CiVisibilityCoverageServices {

/** Services used in the parent process (build system). */
static class Parent {
final ModuleSignalRouter moduleSignalRouter;
final CoverageCalculator.Factory<?> coverageCalculatorFactory;
final CoverageProcessor.Factory<?> coverageProcessorFactory;

Parent(CiVisibilityServices services, CiVisibilityRepoServices repoServices) {
moduleSignalRouter = new ModuleSignalRouter();
coverageCalculatorFactory =
new JacocoCoverageCalculator.Factory(

ExecutionSettings executionSettings =
repoServices.executionSettingsFactory.create(JvmInfo.CURRENT_JVM, null);
CoverageReportUploader coverageReportUploader =
executionSettings.isCodeCoverageReportUploadEnabled()
? new CoverageReportUploader(
services.ciIntake, repoServices.ciTags, services.metricCollector)
: null;

coverageProcessorFactory =
new JacocoCoverageProcessor.Factory(
services.config,
repoServices.repoIndexProvider,
coverageReportUploader,
repoServices.repoRoot,
moduleSignalRouter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class CiVisibilityServices {
final Config config;
final CiVisibilityMetricCollector metricCollector;
final BackendApi backendApi;
final BackendApi ciIntake;
final JvmInfoFactory jvmInfoFactory;
final CiEnvironment environment;
final CIProviderInfoFactory ciProviderInfoFactory;
Expand All @@ -85,6 +86,8 @@ public class CiVisibilityServices {
this.metricCollector = metricCollector;
this.backendApi =
new BackendApiFactory(config, sco).createBackendApi(BackendApiFactory.Intake.API);
this.ciIntake =
new BackendApiFactory(config, sco).createBackendApi(BackendApiFactory.Intake.CI_INTAKE);
this.jvmInfoFactory = new CachingJvmInfoFactory(config, new JvmInfoFactoryImpl());
this.gitClientFactory = buildGitClientFactory(config, metricCollector);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.lang.instrument.Instrumentation;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Predicate;
Expand Down Expand Up @@ -241,7 +242,7 @@ private static BuildSystemSession.Factory buildSystemSessionFactory(
repoServices.executionSettingsFactory,
signalServer,
repoServices.repoIndexProvider,
coverageServices.coverageCalculatorFactory);
coverageServices.coverageProcessorFactory);
};
}

Expand All @@ -266,6 +267,11 @@ private static TestFrameworkSession.Factory childTestFrameworkSessionFactory(
repoServices.sourcePathResolver,
services.linesResolver);

// only add report upload capability for children sessions,
// because report upload is only supported when the build system is instrumented
capabilities = new ArrayList<>(capabilities);
capabilities.add(LibraryCapability.COV_REPORT_UPLOAD);

return new ProxyTestSession(
services.processHierarchy.parentProcessModuleContext,
services.config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class CiVisibilitySettings {
false,
false,
false,
false,
EarlyFlakeDetectionSettings.DEFAULT,
TestManagementSettings.DEFAULT,
null);
Expand All @@ -28,6 +29,7 @@ public class CiVisibilitySettings {
private final boolean flakyTestRetriesEnabled;
private final boolean impactedTestsDetectionEnabled;
private final boolean knownTestsEnabled;
private final boolean coverageReportUploadEnabled;
private final EarlyFlakeDetectionSettings earlyFlakeDetectionSettings;
private final TestManagementSettings testManagementSettings;
@Nullable private final String defaultBranch;
Expand All @@ -40,6 +42,7 @@ public class CiVisibilitySettings {
boolean flakyTestRetriesEnabled,
boolean impactedTestsDetectionEnabled,
boolean knownTestsEnabled,
boolean coverageReportUploadEnabled,
EarlyFlakeDetectionSettings earlyFlakeDetectionSettings,
TestManagementSettings testManagementSettings,
@Nullable String defaultBranch) {
Expand All @@ -50,6 +53,7 @@ public class CiVisibilitySettings {
this.flakyTestRetriesEnabled = flakyTestRetriesEnabled;
this.impactedTestsDetectionEnabled = impactedTestsDetectionEnabled;
this.knownTestsEnabled = knownTestsEnabled;
this.coverageReportUploadEnabled = coverageReportUploadEnabled;
this.earlyFlakeDetectionSettings = earlyFlakeDetectionSettings;
this.testManagementSettings = testManagementSettings;
this.defaultBranch = defaultBranch;
Expand Down Expand Up @@ -83,6 +87,10 @@ public boolean isKnownTestsEnabled() {
return knownTestsEnabled;
}

public boolean isCoverageReportUploadEnabled() {
return coverageReportUploadEnabled;
}

public EarlyFlakeDetectionSettings getEarlyFlakeDetectionSettings() {
return earlyFlakeDetectionSettings;
}
Expand Down Expand Up @@ -112,6 +120,7 @@ public boolean equals(Object o) {
&& flakyTestRetriesEnabled == that.flakyTestRetriesEnabled
&& impactedTestsDetectionEnabled == that.impactedTestsDetectionEnabled
&& knownTestsEnabled == that.knownTestsEnabled
&& coverageReportUploadEnabled == that.coverageReportUploadEnabled
&& Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings)
&& Objects.equals(testManagementSettings, that.testManagementSettings)
&& Objects.equals(defaultBranch, that.defaultBranch);
Expand All @@ -127,6 +136,7 @@ public int hashCode() {
flakyTestRetriesEnabled,
impactedTestsDetectionEnabled,
knownTestsEnabled,
coverageReportUploadEnabled,
earlyFlakeDetectionSettings,
testManagementSettings,
defaultBranch);
Expand Down Expand Up @@ -154,6 +164,7 @@ public CiVisibilitySettings fromJson(Map<String, Object> json) {
getBoolean(json, "flaky_test_retries_enabled", false),
getBoolean(json, "impacted_tests_enabled", false),
getBoolean(json, "known_tests_enabled", false),
getBoolean(json, "coverage_report_upload_enabled", false),
EarlyFlakeDetectionSettings.JsonAdapter.INSTANCE.fromJson(
(Map<String, Object>) json.get("early_flake_detection")),
TestManagementSettings.JsonAdapter.INSTANCE.fromJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ExecutionSettings {
false,
false,
false,
false,
EarlyFlakeDetectionSettings.DEFAULT,
TestManagementSettings.DEFAULT,
null,
Expand All @@ -43,6 +44,7 @@ public class ExecutionSettings {
private final boolean testSkippingEnabled;
private final boolean flakyTestRetriesEnabled;
private final boolean impactedTestsDetectionEnabled;
private final boolean codeCoverageReportUploadEnabled;
@Nonnull private final EarlyFlakeDetectionSettings earlyFlakeDetectionSettings;
@Nonnull private final TestManagementSettings testManagementSettings;
@Nullable private final String itrCorrelationId;
Expand All @@ -58,6 +60,7 @@ public ExecutionSettings(
boolean testSkippingEnabled,
boolean flakyTestRetriesEnabled,
boolean impactedTestsDetectionEnabled,
boolean codeCoverageReportUploadEnabled,
@Nonnull EarlyFlakeDetectionSettings earlyFlakeDetectionSettings,
@Nonnull TestManagementSettings testManagementSettings,
@Nullable String itrCorrelationId,
Expand All @@ -74,6 +77,7 @@ public ExecutionSettings(
this.testSkippingEnabled = testSkippingEnabled;
this.flakyTestRetriesEnabled = flakyTestRetriesEnabled;
this.impactedTestsDetectionEnabled = impactedTestsDetectionEnabled;
this.codeCoverageReportUploadEnabled = codeCoverageReportUploadEnabled;
this.earlyFlakeDetectionSettings = earlyFlakeDetectionSettings;
this.testManagementSettings = testManagementSettings;
this.itrCorrelationId = itrCorrelationId;
Expand Down Expand Up @@ -110,6 +114,7 @@ private ExecutionSettings(
boolean testSkippingEnabled,
boolean flakyTestRetriesEnabled,
boolean impactedTestsDetectionEnabled,
boolean codeCoverageReportUploadEnabled,
@Nonnull EarlyFlakeDetectionSettings earlyFlakeDetectionSettings,
@Nonnull TestManagementSettings testManagementSettings,
@Nullable String itrCorrelationId,
Expand All @@ -123,6 +128,7 @@ private ExecutionSettings(
this.testSkippingEnabled = testSkippingEnabled;
this.flakyTestRetriesEnabled = flakyTestRetriesEnabled;
this.impactedTestsDetectionEnabled = impactedTestsDetectionEnabled;
this.codeCoverageReportUploadEnabled = codeCoverageReportUploadEnabled;
this.earlyFlakeDetectionSettings = earlyFlakeDetectionSettings;
this.testManagementSettings = testManagementSettings;
this.itrCorrelationId = itrCorrelationId;
Expand Down Expand Up @@ -157,6 +163,10 @@ public boolean isImpactedTestsDetectionEnabled() {
return impactedTestsDetectionEnabled;
}

public boolean isCodeCoverageReportUploadEnabled() {
return codeCoverageReportUploadEnabled;
}

@Nonnull
public EarlyFlakeDetectionSettings getEarlyFlakeDetectionSettings() {
return earlyFlakeDetectionSettings;
Expand Down Expand Up @@ -243,6 +253,7 @@ public boolean equals(Object o) {
&& testSkippingEnabled == that.testSkippingEnabled
&& flakyTestRetriesEnabled == that.flakyTestRetriesEnabled
&& impactedTestsDetectionEnabled == that.impactedTestsDetectionEnabled
&& codeCoverageReportUploadEnabled == that.codeCoverageReportUploadEnabled
&& Objects.equals(earlyFlakeDetectionSettings, that.earlyFlakeDetectionSettings)
&& Objects.equals(testManagementSettings, that.testManagementSettings)
&& Objects.equals(itrCorrelationId, that.itrCorrelationId)
Expand All @@ -261,6 +272,7 @@ public int hashCode() {
testSkippingEnabled,
flakyTestRetriesEnabled,
impactedTestsDetectionEnabled,
codeCoverageReportUploadEnabled,
earlyFlakeDetectionSettings,
testManagementSettings,
itrCorrelationId,
Expand All @@ -278,6 +290,7 @@ public static class Serializer {
private static final int TEST_SKIPPING_ENABLED_FLAG = 4;
private static final int FLAKY_TEST_RETRIES_ENABLED_FLAG = 8;
private static final int IMPACTED_TESTS_DETECTION_ENABLED_FLAG = 16;
private static final int CODE_COVERAGE_REPORT_UPLOAD_ENABLED_FLAG = 32;

public static ByteBuffer serialize(ExecutionSettings settings) {
datadog.trace.civisibility.ipc.serialization.Serializer s =
Expand All @@ -291,6 +304,9 @@ public static ByteBuffer serialize(ExecutionSettings settings) {
| (settings.flakyTestRetriesEnabled ? FLAKY_TEST_RETRIES_ENABLED_FLAG : 0)
| (settings.impactedTestsDetectionEnabled
? IMPACTED_TESTS_DETECTION_ENABLED_FLAG
: 0)
| (settings.codeCoverageReportUploadEnabled
? CODE_COVERAGE_REPORT_UPLOAD_ENABLED_FLAG
: 0));
s.write(flags);

Expand Down Expand Up @@ -330,6 +346,8 @@ public static ExecutionSettings deserialize(ByteBuffer buffer) {
boolean testSkippingEnabled = (flags & TEST_SKIPPING_ENABLED_FLAG) != 0;
boolean flakyTestRetriesEnabled = (flags & FLAKY_TEST_RETRIES_ENABLED_FLAG) != 0;
boolean impactedTestsDetectionEnabled = (flags & IMPACTED_TESTS_DETECTION_ENABLED_FLAG) != 0;
boolean codeCoverageReportUploadEnabled =
(flags & CODE_COVERAGE_REPORT_UPLOAD_ENABLED_FLAG) != 0;

EarlyFlakeDetectionSettings earlyFlakeDetectionSettings =
EarlyFlakeDetectionSettings.Serializer.deserialize(buffer);
Expand Down Expand Up @@ -372,6 +390,7 @@ public static ExecutionSettings deserialize(ByteBuffer buffer) {
testSkippingEnabled,
flakyTestRetriesEnabled,
impactedTestsDetectionEnabled,
codeCoverageReportUploadEnabled,
earlyFlakeDetectionSettings,
testManagementSettings,
itrCorrelationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ private Map<String, ExecutionSettings> doCreate(
settings,
CiVisibilitySettings::isKnownTestsEnabled,
Config::isCiVisibilityKnownTestsRequestEnabled);
boolean codeCoverageReportUpload =
isFeatureEnabled(
settings,
CiVisibilitySettings::isCoverageReportUploadEnabled,
Config::isCiVisibilityCodeCoverageReportUploadEnabled);

TestManagementSettings testManagementSettings = getTestManagementSettings(settings);

Expand All @@ -189,7 +194,8 @@ private Map<String, ExecutionSettings> doCreate(
+ "Impacted tests detection - {},\n"
+ "Known tests marking - {},\n"
+ "Auto test retries - {},\n"
+ "Test Management - {}",
+ "Test Management - {},\n"
+ "Code coverage report upload - {}",
repositoryRoot,
tracerEnvironment.getConfigurations().getRuntimeName(),
tracerEnvironment.getConfigurations().getRuntimeVersion(),
Expand All @@ -201,7 +207,8 @@ private Map<String, ExecutionSettings> doCreate(
impactedTestsEnabled,
knownTestsRequest,
flakyTestRetriesEnabled,
testManagementSettings.isEnabled());
testManagementSettings.isEnabled(),
codeCoverageReportUpload);

Future<SkippableTests> skippableTestsFuture =
executor.submit(() -> getSkippableTests(tracerEnvironment, itrEnabled));
Expand Down Expand Up @@ -253,6 +260,7 @@ private Map<String, ExecutionSettings> doCreate(
testSkippingEnabled,
flakyTestRetriesEnabled,
impactedTestsEnabled,
codeCoverageReportUpload,
earlyFlakeDetectionEnabled
? settings.getEarlyFlakeDetectionSettings()
: EarlyFlakeDetectionSettings.DEFAULT,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package datadog.trace.civisibility.coverage.percentage;
package datadog.trace.civisibility.coverage.report;

import datadog.trace.api.civisibility.domain.BuildModuleLayout;
import datadog.trace.civisibility.config.ExecutionSettings;
import javax.annotation.Nullable;

/** Calculates percentage of executable lines that are covered with tests. */
public interface CoverageCalculator {
/** Processes coverage reports. */
public interface CoverageProcessor {
/** Processes previously collected coverage data and returns the percentage of lines covered. */
@Nullable
Long calculateCoveragePercentage();
Long processCoverageData();

interface Factory<T extends CoverageCalculator> {
interface Factory<T extends CoverageProcessor> {
T sessionCoverage(long sessionId);

T moduleCoverage(
Expand Down
Loading
Loading