Skip to content

Commit

Permalink
[issues-317] - Adding tests to verify simultaneous configuration of b…
Browse files Browse the repository at this point in the history
…oth Micrometer and MP Telemetry corner cases for MP Fault Tolerance

Fixing MicroProfileTelemetryServerSetup.java and renaming it to MicroProfileTelemetryServerConfiguration.java and moving it into tooling-obserso that it can be used by FT, too.

Fix OpenTelemetryCollectorContainer and improve it, so that it can now provide new instance, and does not handle the Jaeger container lifecycle anymore
  • Loading branch information
fabiobrz committed Dec 2, 2024
1 parent 4eefe59 commit 472ffa6
Show file tree
Hide file tree
Showing 10 changed files with 565 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jboss.eap.qe.microprofile.tooling.server.configuration.deployment.ConfigurationUtil;
import org.jboss.eap.qe.observability.containers.OpenTelemetryCollectorContainer;
import org.jboss.eap.qe.observability.prometheus.model.PrometheusMetric;
import org.jboss.eap.qe.observability.server.configuration.micrometer.MicrometerServerConfiguration;
import org.jboss.eap.qe.ts.common.docker.Docker;
import org.jboss.eap.qe.ts.common.docker.junit.DockerRequiredTests;
import org.jboss.shrinkwrap.api.Archive;
Expand All @@ -40,7 +41,7 @@
* Tests that metrics can be pushed to the OpenTelemetry collector by Micrometer, and then exported to Jaeger.
* This class is based on the similar one in WildFly, although it uses a different {@code @ServerSetup} task class,
* i.e. {@link MicrometerServerSetup}, which provides the logic for executing the required configuration
* (see {@link org.jboss.eap.qe.micrometer.util.MicrometerServerConfiguration}) within the Arquillian container.
* (see {@link MicrometerServerConfiguration}) within the Arquillian container.
*/
@RunWith(Arquillian.class)
@ServerSetup(MicrometerServerSetup.class) // Enables/Disables Micrometer extension/subsystem for Arquillian in-container tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.jboss.eap.qe.microprofile.tooling.server.configuration.arquillian.MicroProfileServerSetupTask;
import org.jboss.eap.qe.observability.containers.OpenTelemetryCollectorContainer;
import org.jboss.eap.qe.observability.server.configuration.micrometer.MicrometerServerConfiguration;
import org.jboss.eap.qe.ts.common.docker.Docker;

/**
Expand All @@ -20,6 +21,7 @@ public void setup() throws Exception {
}
// start the OTel collector container
otelCollector = OpenTelemetryCollectorContainer.getInstance();
otelCollector.start();
// and pass Micrometer the OTel collector endopint URL
MicrometerServerConfiguration.enableMicrometer(otelCollector.getOtlpHttpEndpoint());
}
Expand All @@ -29,5 +31,6 @@ public void tearDown() throws Exception {
MicrometerServerConfiguration.disableMicrometer();
// stop the OTel collector container
otelCollector.stop();
OpenTelemetryCollectorContainer.dispose();
}
}
5 changes: 5 additions & 0 deletions microprofile-fault-tolerance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.eap.qe.microprofile.fault.tolerance.deployments.v10.HelloService;
import org.jboss.eap.qe.microprofile.fault.tolerance.util.MicroProfileFaultToleranceServerConfiguration;
import org.jboss.eap.qe.microprofile.fault.tolerance.util.MicroProfileTelemetryServerSetup;
import org.jboss.eap.qe.observability.server.configuration.microprofile.telemetry.MicroProfileTelemetryServerConfiguration;
import org.jboss.eap.qe.microprofile.tooling.server.configuration.creaper.ManagementClientProvider;
import org.jboss.eap.qe.microprofile.tooling.server.configuration.deployment.ConfigurationUtil;
import org.jboss.eap.qe.microprofile.tooling.server.log.LogChecker;
import org.jboss.eap.qe.microprofile.tooling.server.log.ModelNodeLogChecker;
import org.jboss.eap.qe.observability.containers.OpenTelemetryCollectorContainer;
import org.jboss.eap.qe.observability.prometheus.model.PrometheusMetric;
import org.jboss.eap.qe.observability.server.configuration.micrometer.MicrometerServerConfiguration;
import org.jboss.eap.qe.ts.common.docker.Docker;
import org.jboss.eap.qe.ts.common.docker.junit.DockerRequiredTests;
import org.jboss.shrinkwrap.api.Archive;
Expand Down Expand Up @@ -88,6 +89,9 @@ public static Archive<?> createNonMPFTDeployment() {
public static void setup() throws Exception {
// Enable FT
MicroProfileFaultToleranceServerConfiguration.enableFaultTolerance();
// And disable Micrometer for good measure since were going to test MicroProfile Fault Tolerance integration
// with MP Telemetry 2.0 metrics too.
MicrometerServerConfiguration.disableMicrometer();
}

/**
Expand Down Expand Up @@ -134,73 +138,90 @@ public void testFaultToleranceMetricsAreTracedWithSameDeployments(
}
// start the OTel collector container
otelCollector = OpenTelemetryCollectorContainer.getInstance();
// Enable MP Telemetry based metrics, which rely on OpenTelemetry subsystem
MicroProfileTelemetryServerSetup.enableOpenTelemetry();
MicroProfileTelemetryServerSetup.addOpenTelemetryCollectorConfiguration(otelCollector.getOtlpGrpcEndpoint());
MicroProfileTelemetryServerSetup.enableMicroProfileTelemetry();
// manually deploy our deployments
deployer.deploy(FIRST_DEPLOYMENT);
deployer.deploy(SECOND_DEPLOYMENT);
get(firstDeploymentUlr + "?operation=timeout&context=foobar&fail=true").then()
.assertThat()
.body(containsString("Fallback Hello, context = foobar"));
// timeout is not working because 2nd deployment has disabled it
get(secondDeploymentUlr + "?operation=timeout&context=foobar&fail=true").then()
.assertThat()
.body(containsString("Hello from @Timeout method, context = foobar"));
// fetch the collected metrics in prometheus format
List<String> metricsToTest = Arrays.asList(
"ft_timeout_calls_total",
"ft_invocations_total");
// give it some time to actually be able and report some metrics via the Pmetheus URL
Thread.sleep(5_000);
List<PrometheusMetric> metrics = OpenTelemetryCollectorContainer.getInstance().fetchMetrics("");
// assert
metricsToTest.forEach(n -> Assert.assertTrue("Missing metric: " + n,
metrics.stream().anyMatch(m -> m.getKey().startsWith(n))));
try {
otelCollector.start();
try {
// Enable MP Telemetry based metrics, which rely on OpenTelemetry subsystem
MicroProfileTelemetryServerConfiguration.enableOpenTelemetry();
MicroProfileTelemetryServerConfiguration
.addOpenTelemetryCollectorConfiguration(otelCollector.getOtlpGrpcEndpoint());
MicroProfileTelemetryServerConfiguration.enableMicroProfileTelemetry();
try {
// manually deploy our deployments
deployer.deploy(FIRST_DEPLOYMENT);
deployer.deploy(SECOND_DEPLOYMENT);
try {
get(firstDeploymentUlr + "?operation=timeout&context=foobar&fail=true").then()
.assertThat()
.body(containsString("Fallback Hello, context = foobar"));
// timeout is not working because 2nd deployment has disabled it
get(secondDeploymentUlr + "?operation=timeout&context=foobar&fail=true").then()
.assertThat()
.body(containsString("Hello from @Timeout method, context = foobar"));
// fetch the collected metrics in prometheus format
List<String> metricsToTest = Arrays.asList(
"ft_timeout_calls_total",
"ft_invocations_total");
// give it some time to actually be able and report some metrics via the Pmetheus URL
Thread.sleep(5_000);
List<PrometheusMetric> metrics = OpenTelemetryCollectorContainer.getInstance().fetchMetrics("");
// assert
metricsToTest.forEach(n -> Assert.assertTrue("Missing metric: " + n,
metrics.stream().anyMatch(m -> m.getKey().startsWith(n))));

Assert.assertTrue("\"ft_timeout_calls_total\" not found or not expected",
metrics.stream()
.filter(m -> "ft_timeout_calls_total".equals(m.getKey()))
.filter(m -> m.getTags().entrySet().stream().anyMatch(
t -> "method".equals(t.getKey())
&& "org.jboss.eap.qe.microprofile.fault.tolerance.deployments.v10.HelloService.timeout"
.equals(t.getValue()))
&& m.getTags().entrySet().stream().anyMatch(
t -> "timedOut".equals(t.getKey()) && "true".equals(t.getValue())))
.anyMatch(m -> "1".equals(m.getValue())));
Assert.assertTrue("\"ft_invocations_total\" (fallback applied) not found or not expected",
metrics.stream()
.filter(m -> "ft_invocations_total".equals(m.getKey()))
.filter(m -> m.getTags().entrySet().stream().anyMatch(
t -> "fallback".equals(t.getKey()) && "applied".equals(t.getValue()))
&& m.getTags().entrySet().stream().anyMatch(
t -> "method".equals(t.getKey())
&& "org.jboss.eap.qe.microprofile.fault.tolerance.deployments.v10.HelloService.timeout"
.equals(t.getValue()))
&& m.getTags().entrySet().stream().anyMatch(
t -> "result".equals(t.getKey()) && "valueReturned".equals(t.getValue())))
.anyMatch(m -> "1".equals(m.getValue())));
Assert.assertTrue("\"ft_invocations_total\" (fallback not applied) not found or not expected",
metrics.stream()
.filter(m -> "ft_invocations_total".equals(m.getKey()))
.filter(m -> m.getTags().entrySet().stream().anyMatch(
t -> "fallback".equals(t.getKey()) && "notApplied".equals(t.getValue()))
&& m.getTags().entrySet().stream().anyMatch(
t -> "method".equals(t.getKey())
&& "org.jboss.eap.qe.microprofile.fault.tolerance.deployments.v10.HelloService.timeout"
.equals(t.getValue()))
&& m.getTags().entrySet().stream().anyMatch(
t -> "result".equals(t.getKey()) && "valueReturned".equals(t.getValue())))
.anyMatch(m -> "1".equals(m.getValue())));
// disable MP Telemetry based metrics
MicroProfileTelemetryServerSetup.disableMicroProfileTelemetry();
MicroProfileTelemetryServerSetup.disableOpenTelemetry();
// stop the OTel collector container
otelCollector.stop();
// undeploy
deployer.undeploy(FIRST_DEPLOYMENT);
deployer.undeploy(SECOND_DEPLOYMENT);
Assert.assertTrue("\"ft_timeout_calls_total\" not found or not expected",
metrics.stream()
.filter(m -> "ft_timeout_calls_total".equals(m.getKey()))
.filter(m -> m.getTags().entrySet().stream().anyMatch(
t -> "method".equals(t.getKey())
&& "org.jboss.eap.qe.microprofile.fault.tolerance.deployments.v10.HelloService.timeout"
.equals(t.getValue()))
&& m.getTags().entrySet().stream().anyMatch(
t -> "timedOut".equals(t.getKey()) && "true".equals(t.getValue())))
.anyMatch(m -> "1".equals(m.getValue())));
Assert.assertTrue("\"ft_invocations_total\" (fallback applied) not found or not expected",
metrics.stream()
.filter(m -> "ft_invocations_total".equals(m.getKey()))
.filter(m -> m.getTags().entrySet().stream().anyMatch(
t -> "fallback".equals(t.getKey()) && "applied".equals(t.getValue()))
&& m.getTags().entrySet().stream().anyMatch(
t -> "method".equals(t.getKey())
&& "org.jboss.eap.qe.microprofile.fault.tolerance.deployments.v10.HelloService.timeout"
.equals(t.getValue()))
&& m.getTags().entrySet().stream().anyMatch(
t -> "result".equals(t.getKey())
&& "valueReturned".equals(t.getValue())))
.anyMatch(m -> "1".equals(m.getValue())));
Assert.assertTrue("\"ft_invocations_total\" (fallback not applied) not found or not expected",
metrics.stream()
.filter(m -> "ft_invocations_total".equals(m.getKey()))
.filter(m -> m.getTags().entrySet().stream().anyMatch(
t -> "fallback".equals(t.getKey()) && "notApplied".equals(t.getValue()))
&& m.getTags().entrySet().stream().anyMatch(
t -> "method".equals(t.getKey())
&& "org.jboss.eap.qe.microprofile.fault.tolerance.deployments.v10.HelloService.timeout"
.equals(t.getValue()))
&& m.getTags().entrySet().stream().anyMatch(
t -> "result".equals(t.getKey())
&& "valueReturned".equals(t.getValue())))
.anyMatch(m -> "1".equals(m.getValue())));
} finally {
// undeploy
deployer.undeploy(FIRST_DEPLOYMENT);
deployer.undeploy(SECOND_DEPLOYMENT);
}
} finally {
// disable MP Telemetry based metrics
MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry();
MicroProfileTelemetryServerConfiguration.disableOpenTelemetry();
}
} finally {
// stop the OTel collector container
otelCollector.stop();
}
} finally {
OpenTelemetryCollectorContainer.dispose();
}
}

/**
Expand Down
Loading

0 comments on commit 472ffa6

Please sign in to comment.