Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OTel agent detector test that was polluting the JVM for later tests #8449

Merged
merged 3 commits into from
Mar 4, 2024
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
21 changes: 15 additions & 6 deletions microprofile/telemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
Support for MicroProfile Telemetry
</description>

<properties>
<!-- The default for the following is 5000 ms. Reducing it speeds up tests significantly. -->
<otel.bsp.schedule.delay>100</otel.bsp.schedule.delay>
</properties>

<dependencies>
<dependency>
<groupId>io.helidon.tracing.providers</groupId>
Expand Down Expand Up @@ -137,12 +142,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<!-- The default for the following is 5000 ms. Reducing it significantly speeds up tests. -->
<argLine>-Dotel.bsp.schedule.delay=100</argLine>
</configuration>
<executions>
<execution>
<id>default-test</id>
<configuration>
<systemPropertyVariables>
<otel.bsp.schedule.delay>${otel.bsp.schedule.delay}</otel.bsp.schedule.delay>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.helidon.tracing.providers.opentelemetry.HelidonOpenTelemetry;

import jakarta.enterprise.inject.spi.CDI;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -54,9 +55,18 @@ void shouldNotBeNoOpTelemetry(){

@Test
void checkEnvVariable(){
System.setProperty(HelidonOpenTelemetry.IO_OPENTELEMETRY_JAVAAGENT, "true");
Config config = CDI.current().select(Config.class).get();
boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config);
assertThat(present, is(true));
var originalAgentPropertyValue = System.setProperty(HelidonOpenTelemetry.IO_OPENTELEMETRY_JAVAAGENT, "true");
try {
Config config = CDI.current().select(Config.class).get();
boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config);
assertThat(present, is(true));
} finally {
// Restore or clear the agent setting to avoid polluting other tests which might follow.
if (originalAgentPropertyValue != null) {
System.setProperty(HelidonOpenTelemetry.IO_OPENTELEMETRY_JAVAAGENT, originalAgentPropertyValue);
} else {
System.clearProperty(HelidonOpenTelemetry.IO_OPENTELEMETRY_JAVAAGENT);
}
}
}
}