Skip to content

Commit

Permalink
Fix trace diagnostics (#2778)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-action[bot]@users.noreply.github.com>
  • Loading branch information
trask and github-actions[bot] authored Dec 7, 2022
1 parent f9a22ad commit 53eb54b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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";
Expand Down Expand Up @@ -369,6 +372,7 @@ protected Set<Integer> getLivenessCheckPorts() {
+ FAKE_INGESTION_ENDPOINT
+ ";LiveEndpoint="
+ FAKE_INGESTION_ENDPOINT)
.withEnv("APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_LEVEL", selfDiagnosticsLevel)
.withNetwork(network)
.withExposedPorts(8080)
.withFileSystemBind(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -41,13 +42,19 @@ public SmokeTestExtensionBuilder useOld3xAgent() {
return this;
}

public SmokeTestExtensionBuilder setSelfDiagnosticsLevel(String selfDiagnosticsLevel) {
this.selfDiagnosticsLevel = selfDiagnosticsLevel;
return this;
}

public SmokeTestExtension build() {
return new SmokeTestExtension(
dependencyContainer,
dependencyContainerEnvVarName,
usesGlobalIngestionEndpoint,
skipHealthCheck,
readOnly,
useOld3xAgent);
useOld3xAgent,
selfDiagnosticsLevel);
}
}

0 comments on commit 53eb54b

Please sign in to comment.