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.

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 authored and marekkopecky committed Dec 4, 2024
1 parent d6decca commit 622d336
Show file tree
Hide file tree
Showing 12 changed files with 595 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.eap.qe.micrometer.base.MetricResource;
import org.jboss.eap.qe.micrometer.util.MicrometerServerSetup;
import org.jboss.eap.qe.microprofile.common.setuptasks.MicrometerServerConfiguration;
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;
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
@@ -1,5 +1,6 @@
package org.jboss.eap.qe.micrometer.util;

import org.jboss.eap.qe.microprofile.common.setuptasks.MicrometerServerConfiguration;
import org.jboss.eap.qe.microprofile.tooling.server.configuration.arquillian.MicroProfileServerSetupTask;
import org.jboss.eap.qe.observability.containers.OpenTelemetryCollectorContainer;
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();
}
}
2 changes: 1 addition & 1 deletion micrometer/src/test/resources/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ processors:

exporters:
logging:
verbosity: detailed
verbosity: normal
prometheus:
endpoint: "0.0.0.0:49152"
otlp:
Expand Down
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 @@ -15,7 +15,8 @@
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.eap.qe.microprofile.common.setuptasks.MicroProfileFaultToleranceServerConfiguration;
import org.jboss.eap.qe.microprofile.common.setuptasks.MicroProfileTelemetryServerSetup;
import org.jboss.eap.qe.microprofile.common.setuptasks.MicroProfileTelemetryServerConfiguration;
import org.jboss.eap.qe.microprofile.common.setuptasks.MicrometerServerConfiguration;
import org.jboss.eap.qe.microprofile.fault.tolerance.deployments.v10.HelloService;
import org.jboss.eap.qe.microprofile.tooling.server.configuration.creaper.ManagementClientProvider;
import org.jboss.eap.qe.microprofile.tooling.server.configuration.deployment.ConfigurationUtil;
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 622d336

Please sign in to comment.