From 3fb888b81b6546784736580fc772c598297869d7 Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko <121111529+nikita-tkachenko-datadog@users.noreply.github.com> Date: Mon, 13 Nov 2023 12:56:12 +0100 Subject: [PATCH] Fail fast when tracer versions do not match in parent and child processes (#6168) --- .../trace/civisibility/CiVisibilitySystem.java | 13 +++++++++++++ .../config/ModuleExecutionSettingsFactoryImpl.java | 6 ++++++ .../trace/api/config/CiVisibilityConfig.java | 2 ++ .../src/main/java/datadog/trace/api/Config.java | 8 ++++++++ 4 files changed, 29 insertions(+) diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilitySystem.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilitySystem.java index 1c3000726fa..4f4a29255b6 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilitySystem.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilitySystem.java @@ -1,6 +1,7 @@ package datadog.trace.civisibility; import datadog.communication.ddagent.SharedCommunicationObjects; +import datadog.communication.ddagent.TracerVersion; import datadog.trace.api.Config; import datadog.trace.api.civisibility.CIVisibility; import datadog.trace.api.civisibility.InstrumentationBridge; @@ -52,6 +53,7 @@ import datadog.trace.civisibility.source.index.RepoIndexProvider; import datadog.trace.civisibility.source.index.RepoIndexSourcePathResolver; import datadog.trace.util.Strings; +import datadog.trace.util.throwable.FatalAgentMisconfigurationError; import java.net.InetSocketAddress; import java.nio.file.FileSystems; import java.nio.file.Path; @@ -74,6 +76,17 @@ public static void start(SharedCommunicationObjects sco) { return; } + String injectedTracerVersion = config.getCiVisibilityInjectedTracerVersion(); + if (injectedTracerVersion != null + && !injectedTracerVersion.equals(TracerVersion.TRACER_VERSION)) { + throw new FatalAgentMisconfigurationError( + "Running JVM with tracer version " + + TracerVersion.TRACER_VERSION + + " however parent process attempted to inject " + + injectedTracerVersion + + ". Do not inject the tracer into the forked JVMs manually, or ensure the manually injected version is the same as the one injected automatically"); + } + sco.createRemaining(config); GitClient.Factory gitClientFactory = buildGitClientFactory(config); diff --git a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ModuleExecutionSettingsFactoryImpl.java b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ModuleExecutionSettingsFactoryImpl.java index 6122ac1aabe..6e4c4b29de4 100644 --- a/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ModuleExecutionSettingsFactoryImpl.java +++ b/dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/config/ModuleExecutionSettingsFactoryImpl.java @@ -1,5 +1,6 @@ package datadog.trace.civisibility.config; +import datadog.communication.ddagent.TracerVersion; import datadog.trace.api.Config; import datadog.trace.api.civisibility.config.Configurations; import datadog.trace.api.civisibility.config.ModuleExecutionSettings; @@ -156,6 +157,11 @@ private Map getPropertiesPropagatedToChildProcess( CiVisibilityConfig.CIVISIBILITY_BUILD_INSTRUMENTATION_ENABLED), Boolean.toString(false)); + propagatedSystemProperties.put( + Strings.propertyNameToSystemPropertyName( + CiVisibilityConfig.CIVISIBILITY_INJECTED_TRACER_VERSION), + TracerVersion.TRACER_VERSION); + return propagatedSystemProperties; } diff --git a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java index 1a3d861c3ac..b23ce0fd206 100644 --- a/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java +++ b/dd-trace-api/src/main/java/datadog/trace/api/config/CiVisibilityConfig.java @@ -60,6 +60,8 @@ public final class CiVisibilityConfig { "civisibility.module.execution.settings.cache.size"; public static final String CIVISIBILITY_COVERAGE_SEGMENTS_ENABLED = "civisibility.coverage.segments.enabled"; + public static final String CIVISIBILITY_INJECTED_TRACER_VERSION = + "civisibility.injected.tracer.version"; private CiVisibilityConfig() {} } diff --git a/internal-api/src/main/java/datadog/trace/api/Config.java b/internal-api/src/main/java/datadog/trace/api/Config.java index a322a4c8f1d..b5b898012fa 100644 --- a/internal-api/src/main/java/datadog/trace/api/Config.java +++ b/internal-api/src/main/java/datadog/trace/api/Config.java @@ -155,6 +155,7 @@ import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_GIT_UNSHALLOW_ENABLED; import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_GIT_UPLOAD_ENABLED; import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_GIT_UPLOAD_TIMEOUT_MILLIS; +import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_INJECTED_TRACER_VERSION; import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_ITR_ENABLED; import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_JACOCO_GRADLE_SOURCE_SETS; import static datadog.trace.api.config.CiVisibilityConfig.CIVISIBILITY_JACOCO_PLUGIN_EXCLUDES; @@ -716,6 +717,7 @@ static class HostNameHolder { private final boolean ciVisibilityRepoIndexSharingEnabled; private final int ciVisibilityModuleExecutionSettingsCacheSize; private final boolean ciVisibilityCoverageSegmentsEnabled; + private final String ciVisibilityInjectedTracerVersion; private final boolean remoteConfigEnabled; private final boolean remoteConfigIntegrityCheckEnabled; @@ -1651,6 +1653,8 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins configProvider.getInteger(CIVISIBILITY_MODULE_EXECUTION_SETTINGS_CACHE_SIZE, 16); ciVisibilityCoverageSegmentsEnabled = configProvider.getBoolean(CIVISIBILITY_COVERAGE_SEGMENTS_ENABLED, false); + ciVisibilityInjectedTracerVersion = + configProvider.getString(CIVISIBILITY_INJECTED_TRACER_VERSION); remoteConfigEnabled = configProvider.getBoolean(REMOTE_CONFIG_ENABLED, DEFAULT_REMOTE_CONFIG_ENABLED); @@ -2733,6 +2737,10 @@ public boolean isCiVisibilityCoverageSegmentsEnabled() { return ciVisibilityCoverageSegmentsEnabled; } + public String getCiVisibilityInjectedTracerVersion() { + return ciVisibilityInjectedTracerVersion; + } + public String getAppSecRulesFile() { return appSecRulesFile; }