From 53eb54ba7da1296efac7e3df0e5c217d10633829 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 7 Dec 2022 11:45:34 -0800 Subject: [PATCH] Fix trace diagnostics (#2778) Co-authored-by: github-actions[bot] --- .../agent/internal/init/AppInsightsCertificate.java | 6 ++++++ .../agent/internal/init/CommandExecutor.java | 4 ++++ .../smoketest/CustomDimensionsTest.java | 6 +++++- .../smoketest/SmokeTestExtension.java | 6 +++++- .../smoketest/SmokeTestExtensionBuilder.java | 9 ++++++++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AppInsightsCertificate.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AppInsightsCertificate.java index fdb744b88fc..80424758798 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AppInsightsCertificate.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/AppInsightsCertificate.java @@ -87,6 +87,12 @@ private String loadCertificates() { private String executeWithoutException(ProcessBuilder processBuilder) { try { + // to make sure the javaagent is not re-applied to the keytool process, which then creates + // a recursive hanging + // also helps to ensure other JVM args are not passed along + processBuilder.environment().put("JAVA_TOOL_OPTIONS", ""); + processBuilder.environment().put("_JAVA_OPTIONS", ""); + Process process = processBuilder.start(); OutputStream outputStream = process.getOutputStream(); PrintWriter writer = diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/CommandExecutor.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/CommandExecutor.java index d620bf95901..8ddbb125f6f 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/CommandExecutor.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/CommandExecutor.java @@ -22,6 +22,10 @@ static String execute(ProcessBuilder processBuilder) { IllegalStateException exitException = null; String result = null; try { + // to make sure the javaagent (and other JVM args) are not applied to the process + processBuilder.environment().put("JAVA_TOOL_OPTIONS", ""); + processBuilder.environment().put("_JAVA_OPTIONS", ""); + Process process = processBuilder.start(); int exitValue = process.waitFor(); exitException = diff --git a/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java b/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java index 787c9d3ed75..7e4533c8604 100644 --- a/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java +++ b/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java @@ -20,7 +20,11 @@ @UseAgent abstract class CustomDimensionsTest { - @RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create(); + // TODO (trask) find a better(?) place to test self-diagnostics trace level + // instead of this seemingly ad-hoc location + @RegisterExtension + static final SmokeTestExtension testing = + SmokeTestExtension.builder().setSelfDiagnosticsLevel("trace").build(); @Test @TargetUri("/test") diff --git a/smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtension.java b/smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtension.java index 492172cc5af..33ec1f637d8 100644 --- a/smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtension.java +++ b/smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtension.java @@ -91,6 +91,7 @@ public class SmokeTestExtension private final boolean readOnly; private final boolean usesGlobalIngestionEndpoint; private final boolean useOld3xAgent; + private final String selfDiagnosticsLevel; private final File javaagentFile; public static SmokeTestExtension create() { @@ -107,13 +108,15 @@ public static SmokeTestExtensionBuilder builder() { boolean usesGlobalIngestionEndpoint, boolean skipHealthCheck, boolean readOnly, - boolean useOld3xAgent) { + boolean useOld3xAgent, + String selfDiagnosticsLevel) { this.skipHealthCheck = skipHealthCheck; this.readOnly = readOnly; this.dependencyContainer = dependencyContainer; this.dependencyContainerEnvVarName = dependencyContainerEnvVarName; this.usesGlobalIngestionEndpoint = usesGlobalIngestionEndpoint; this.useOld3xAgent = useOld3xAgent; + this.selfDiagnosticsLevel = selfDiagnosticsLevel; String javaagentPathSystemProperty = useOld3xAgent ? "ai.smoke-test.old-3x-javaagent-file" : "ai.smoke-test.javaagent-file"; @@ -369,6 +372,7 @@ protected Set getLivenessCheckPorts() { + FAKE_INGESTION_ENDPOINT + ";LiveEndpoint=" + FAKE_INGESTION_ENDPOINT) + .withEnv("APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_LEVEL", selfDiagnosticsLevel) .withNetwork(network) .withExposedPorts(8080) .withFileSystemBind( diff --git a/smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtensionBuilder.java b/smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtensionBuilder.java index e4d20af2cdc..18814fbbfbc 100644 --- a/smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtensionBuilder.java +++ b/smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/SmokeTestExtensionBuilder.java @@ -13,6 +13,7 @@ public class SmokeTestExtensionBuilder { private boolean skipHealthCheck; private boolean readOnly; private boolean useOld3xAgent; + private String selfDiagnosticsLevel = "info"; public SmokeTestExtensionBuilder setDependencyContainer( String envVarName, GenericContainer container) { @@ -41,6 +42,11 @@ public SmokeTestExtensionBuilder useOld3xAgent() { return this; } + public SmokeTestExtensionBuilder setSelfDiagnosticsLevel(String selfDiagnosticsLevel) { + this.selfDiagnosticsLevel = selfDiagnosticsLevel; + return this; + } + public SmokeTestExtension build() { return new SmokeTestExtension( dependencyContainer, @@ -48,6 +54,7 @@ public SmokeTestExtension build() { usesGlobalIngestionEndpoint, skipHealthCheck, readOnly, - useOld3xAgent); + useOld3xAgent, + selfDiagnosticsLevel); } }