From c73d6f9086859a1e0b6c19f5c9405dbc1148faf2 Mon Sep 17 00:00:00 2001 From: Fabio Burzigotti Date: Thu, 5 Dec 2024 17:30:51 +0100 Subject: [PATCH] Fix Fault Tolerance multiple metrics provider test Split OTel related configuration APIs to OpenTelemetryServerCOnfiguration --- microprofile-fault-tolerance/pom.xml | 1 + .../fault/tolerance/UndeployDeployTest.java | 7 +- ...java => MultipleMetricsProvidersTest.java} | 220 ++++++++++-------- .../metrics/MPTelemetryServerSetupTask.java | 7 +- .../OpenTelemetryCollectorContainer.java | 4 +- ...roProfileTelemetryServerConfiguration.java | 112 +-------- .../OpenTelemetryServerConfiguration.java | 121 ++++++++++ 7 files changed, 259 insertions(+), 213 deletions(-) rename microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/integration/metrics/{MultipleMetricsExtensionTest.java => MultipleMetricsProvidersTest.java} (67%) create mode 100644 tooling-server-configuration/src/main/java/org/jboss/eap/qe/microprofile/common/setuptasks/OpenTelemetryServerConfiguration.java diff --git a/microprofile-fault-tolerance/pom.xml b/microprofile-fault-tolerance/pom.xml index 21877661..108d6950 100644 --- a/microprofile-fault-tolerance/pom.xml +++ b/microprofile-fault-tolerance/pom.xml @@ -146,6 +146,7 @@ cloud-server microprofile-fault-tolerance + micrometer diff --git a/microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/UndeployDeployTest.java b/microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/UndeployDeployTest.java index 0a73ffbb..de2c74f2 100644 --- a/microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/UndeployDeployTest.java +++ b/microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/UndeployDeployTest.java @@ -17,6 +17,7 @@ import org.jboss.eap.qe.microprofile.common.setuptasks.MicroProfileFaultToleranceServerConfiguration; import org.jboss.eap.qe.microprofile.common.setuptasks.MicroProfileTelemetryServerConfiguration; import org.jboss.eap.qe.microprofile.common.setuptasks.MicrometerServerConfiguration; +import org.jboss.eap.qe.microprofile.common.setuptasks.OpenTelemetryServerConfiguration; 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; @@ -142,8 +143,8 @@ public void testFaultToleranceMetricsAreTracedWithSameDeployments( otelCollector.start(); try { // Enable MP Telemetry based metrics, which rely on OpenTelemetry subsystem - MicroProfileTelemetryServerConfiguration.enableOpenTelemetry(); - MicroProfileTelemetryServerConfiguration + OpenTelemetryServerConfiguration.enableOpenTelemetry(); + OpenTelemetryServerConfiguration .addOpenTelemetryCollectorConfiguration(otelCollector.getOtlpGrpcEndpoint()); MicroProfileTelemetryServerConfiguration.enableMicroProfileTelemetry(); try { @@ -213,7 +214,7 @@ public void testFaultToleranceMetricsAreTracedWithSameDeployments( } finally { // disable MP Telemetry based metrics MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); - MicroProfileTelemetryServerConfiguration.disableOpenTelemetry(); + OpenTelemetryServerConfiguration.disableOpenTelemetry(); } } finally { // stop the OTel collector container diff --git a/microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/integration/metrics/MultipleMetricsExtensionTest.java b/microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/integration/metrics/MultipleMetricsProvidersTest.java similarity index 67% rename from microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/integration/metrics/MultipleMetricsExtensionTest.java rename to microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/integration/metrics/MultipleMetricsProvidersTest.java index 86113d53..4056835e 100644 --- a/microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/integration/metrics/MultipleMetricsExtensionTest.java +++ b/microprofile-fault-tolerance/src/test/java/org/jboss/eap/qe/microprofile/fault/tolerance/integration/metrics/MultipleMetricsProvidersTest.java @@ -17,6 +17,7 @@ import org.jboss.eap.qe.microprofile.common.setuptasks.MicroProfileFaultToleranceServerConfiguration; import org.jboss.eap.qe.microprofile.common.setuptasks.MicroProfileTelemetryServerConfiguration; import org.jboss.eap.qe.microprofile.common.setuptasks.MicrometerServerConfiguration; +import org.jboss.eap.qe.microprofile.common.setuptasks.OpenTelemetryServerConfiguration; import org.jboss.eap.qe.microprofile.fault.tolerance.deployments.v10.HelloService; import org.jboss.eap.qe.microprofile.tooling.server.configuration.deployment.ConfigurationUtil; import org.jboss.eap.qe.observability.containers.OpenTelemetryCollectorContainer; @@ -46,7 +47,7 @@ @RunAsClient @RunWith(Arquillian.class) @Category(DockerRequiredTests.class) -public class MultipleMetricsExtensionTest { +public class MultipleMetricsProvidersTest { private static final String FAULT_TOLERANCE_DEPLOYMENT = "FTDeployment"; private static final String FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY = "FTDeploymentWithMPTelemetryEnabled"; @@ -108,7 +109,8 @@ public static Archive deploymentWithMPTelemetryEnabled() { */ @Deployment(name = FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY_DISABLING_MICROMETER, managed = false) public static Archive deploymentWithMPTelemetryEnabledDisablingMicrometer() { - String mpConfig = "otel.metric.export.interval=100\notel.service.name=" + FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY_DISABLING_MICROMETER + String mpConfig = "otel.metric.export.interval=100\notel.service.name=" + + FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY_DISABLING_MICROMETER + "\notel.sdk.disabled=false\nTimeout/enabled=true\nsmallrye.faulttolerance.micrometer.disabled=true"; return ShrinkWrap.create(WebArchive.class, FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY_DISABLING_MICROMETER + ".war") .addPackages(true, HelloService.class.getPackage()) @@ -124,7 +126,12 @@ public static Archive deploymentWithMPTelemetryEnabledDisablingMicrometer() { */ @Test @InSequence(0) - public void deployAll() { + public void deployAll() throws Exception { + // we enable Micrometer and/or MP Telemetry/OpenTelemetry selectively + MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); + OpenTelemetryServerConfiguration.disableOpenTelemetry(); + MicrometerServerConfiguration.disableMicrometer(); + // Deploy/undeploy everything to let Arquillian inject URLs... (workaround for multiple manual deployment tests) deployer.deploy(FAULT_TOLERANCE_DEPLOYMENT); deployer.deploy(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY); deployer.deploy(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY_DISABLING_MICROMETER); @@ -145,8 +152,9 @@ public void deployAll() { @InSequence(10) public void noMetricsAreCollectedWhenMetricsExtensionsAreNotAvailable( @ArquillianResource @OperateOnDeployment(FAULT_TOLERANCE_DEPLOYMENT) URL deploymentUrl) throws Exception { - // Remove the MP Telemetry extension + // Remove the microprofile-telemetry and opentelemetry extensions MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); + OpenTelemetryServerConfiguration.disableOpenTelemetry(); // And be sure Micrometer is not available as well MicrometerServerConfiguration.disableMicrometer(); // start the OTel collector container @@ -187,13 +195,14 @@ public void noMetricsAreCollectedWhenMetricsExtensionsAreNotAvailable( * @throws Exception When something fails during server configuration */ @Test - @InSequence(10) + @InSequence(20) public void metricsAreCollectedWhenOnlyMicrometerExtensionIsAvailable( @ArquillianResource @OperateOnDeployment(FAULT_TOLERANCE_DEPLOYMENT) URL deploymentUrl) throws Exception { - // Remove the MP Telemetry extension + // Remove the microprofile-telemetry and opentelemetry extensions MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); + OpenTelemetryServerConfiguration.disableOpenTelemetry(); // start the OTel collector container - OpenTelemetryCollectorContainer otelCollector = OpenTelemetryCollectorContainer.getNewInstance(); + final OpenTelemetryCollectorContainer otelCollector = OpenTelemetryCollectorContainer.getNewInstance(); otelCollector.start(); try { // And be sure Micrometer is available instead @@ -238,45 +247,52 @@ public void metricsAreCollectedWhenOnlyMicrometerExtensionIsAvailable( * @throws Exception When something fails during server configuration */ @Test - @InSequence(10) + @InSequence(30) public void noMetricsAreCollectedWhenOnlyMPTelemetryIsAvailableButNotEnabled( @ArquillianResource @OperateOnDeployment(FAULT_TOLERANCE_DEPLOYMENT) URL deploymentUrl) throws Exception { // Remove the Micrometer extension... MicrometerServerConfiguration.disableMicrometer(); - // ... but make the MicroProfile Telemetry extension available - MicroProfileTelemetryServerConfiguration.enableMicroProfileTelemetry(); + // ... start the OTel collector container... + final OpenTelemetryCollectorContainer otelCollector = OpenTelemetryCollectorContainer.getNewInstance(); + otelCollector.start(); try { - // start the OTel collector container - OpenTelemetryCollectorContainer otelCollector = OpenTelemetryCollectorContainer.getNewInstance(); - otelCollector.start(); + // ... and make the opentelemetry extension available... + OpenTelemetryServerConfiguration.enableOpenTelemetry(); try { - // deploy an app that DOES NOT enable MP Telemetry - deployer.deploy(FAULT_TOLERANCE_DEPLOYMENT); + OpenTelemetryServerConfiguration.addOpenTelemetryCollectorConfiguration(otelCollector.getOtlpGrpcEndpoint()); + // ... and finally the microProfile-telemetry extension available + MicroProfileTelemetryServerConfiguration.enableMicroProfileTelemetry(); try { - // call the app operation for some times - for (int i = 0; i < REQUEST_COUNT; i++) { - get(deploymentUrl + "?operation=timeout&context=foobar&fail=true").then() - .assertThat() - .statusCode(HttpStatus.SC_OK) - .body(containsString("Fallback Hello, context = foobar")); + // deploy an app that DOES NOT enable MP Telemetry + deployer.deploy(FAULT_TOLERANCE_DEPLOYMENT); + try { + // call the app operation for some times + for (int i = 0; i < REQUEST_COUNT; i++) { + get(deploymentUrl + "?operation=timeout&context=foobar&fail=true").then() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body(containsString("Fallback Hello, context = foobar")); + } + // give it some time to actually be able and report some metrics via the Pmetheus URL + Thread.sleep(1_000); + // fetch the collected metrics in prometheus format + List metrics = otelCollector.fetchMetrics(TESTED_FT_METRIC); + Assert.assertTrue( + TESTED_FT_METRIC + " metrics found, which is not expected when only the MP Telemetry extension " + + + "is available but NOT enabled at application level.", + metrics.stream().noneMatch(m -> m.getKey().startsWith(TESTED_FT_METRIC))); + } finally { + deployer.undeploy(FAULT_TOLERANCE_DEPLOYMENT); } - // give it some time to actually be able and report some metrics via the Pmetheus URL - Thread.sleep(1_000); - // fetch the collected metrics in prometheus format - List metrics = otelCollector.fetchMetrics(TESTED_FT_METRIC); - Assert.assertTrue( - TESTED_FT_METRIC + " metrics found, which is not expected when only the MP Telemetry extension " - + - "is available but NOT enabled at application level.", - metrics.stream().noneMatch(m -> m.getKey().startsWith(TESTED_FT_METRIC))); } finally { - deployer.undeploy(FAULT_TOLERANCE_DEPLOYMENT); + MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); } } finally { - otelCollector.stop(); + OpenTelemetryServerConfiguration.disableOpenTelemetry(); } } finally { - MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); + otelCollector.stop(); } } @@ -288,47 +304,55 @@ public void noMetricsAreCollectedWhenOnlyMPTelemetryIsAvailableButNotEnabled( * @throws Exception When something fails during server configuration */ @Test - @InSequence(10) + @InSequence(40) public void metricsAreCollectedWhenOnlyMPTelemetryExtensionIsAvailableAndEnabled( @ArquillianResource @OperateOnDeployment(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY) URL deploymentUrl) throws Exception { // Remove the Micrometer extension MicrometerServerConfiguration.disableMicrometer(); - // Make the MP Telemetry extension available - MicroProfileTelemetryServerConfiguration.enableMicroProfileTelemetry(); + // start the OTel collector container + OpenTelemetryCollectorContainer otelCollector = OpenTelemetryCollectorContainer.getNewInstance(); + otelCollector.start(); try { - // start the OTel collector container - OpenTelemetryCollectorContainer otelCollector = OpenTelemetryCollectorContainer.getNewInstance(); - otelCollector.start(); + // ... and make the opentelemetry extension available... + OpenTelemetryServerConfiguration.enableOpenTelemetry(); try { - // deploy an app that enables MP Telemetry - deployer.deploy(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY); + OpenTelemetryServerConfiguration + .addOpenTelemetryCollectorConfiguration(otelCollector.getOtlpGrpcEndpoint()); + // ... and finally make the microprofile-telemetry extension available + MicroProfileTelemetryServerConfiguration.enableMicroProfileTelemetry(); try { - // call the app operation for some times - for (int i = 0; i < REQUEST_COUNT; i++) { - get(deploymentUrl + "?operation=timeout&context=foobar&fail=true").then() - .assertThat() - .statusCode(HttpStatus.SC_OK) - .body(containsString("Fallback Hello, context = foobar")); + // deploy an app that enables MP Telemetry + deployer.deploy(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY); + try { + // call the app operation for some times + for (int i = 0; i < REQUEST_COUNT; i++) { + get(deploymentUrl + "?operation=timeout&context=foobar&fail=true").then() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body(containsString("Fallback Hello, context = foobar")); + } + // give it some time to actually be able and report some metrics via the Pmetheus URL + Thread.sleep(1_000); + // fetch the collected metrics in prometheus format + List metrics = otelCollector.fetchMetrics(TESTED_FT_METRIC); + Assert.assertFalse( + TESTED_FT_METRIC + + " metrics not found, which is not expected when the MP Telemetry extension is available " + + + "and enabled at the application level, i.e. FT metrics should be collected.", + metrics.isEmpty()); + } finally { + deployer.undeploy(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY); } - // give it some time to actually be able and report some metrics via the Pmetheus URL - Thread.sleep(1_000); - // fetch the collected metrics in prometheus format - List metrics = otelCollector.fetchMetrics(TESTED_FT_METRIC); - Assert.assertFalse( - TESTED_FT_METRIC - + " metrics not found, which is not expected when the MP Telemetry extension is available " - + - "and enabled at the application level, i.e. FT metrics should be collected.", - metrics.isEmpty()); } finally { - deployer.undeploy(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY); + MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); } } finally { - otelCollector.stop(); + OpenTelemetryServerConfiguration.disableOpenTelemetry(); } } finally { - MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); + otelCollector.stop(); } } @@ -342,55 +366,63 @@ public void metricsAreCollectedWhenOnlyMPTelemetryExtensionIsAvailableAndEnabled * @throws Exception When something fails during server configuration */ @Test - @InSequence(10) + @InSequence(50) public void metricsAreCollectedWhenBothExtensionsAreAvailableAndOnlyMPTelIsEnabled( @ArquillianResource @OperateOnDeployment(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY_DISABLING_MICROMETER) URL deploymentUrl) throws Exception { - // Make the MP Telemetry extension available - MicroProfileTelemetryServerConfiguration.enableMicroProfileTelemetry(); + // start the OTel collector container + OpenTelemetryCollectorContainer otelCollector = OpenTelemetryCollectorContainer.getNewInstance(); + otelCollector.start(); try { - // start the OTel collector container - OpenTelemetryCollectorContainer otelCollector = OpenTelemetryCollectorContainer.getNewInstance(); - otelCollector.start(); + // ... and make the opentelemetry extension available... + OpenTelemetryServerConfiguration.enableOpenTelemetry(); try { - // And be sure Micrometer is available too - MicrometerServerConfiguration.enableMicrometer(otelCollector.getOtlpHttpEndpoint()); + OpenTelemetryServerConfiguration + .addOpenTelemetryCollectorConfiguration(otelCollector.getOtlpGrpcEndpoint()); + // ... then make the microprofile-telemetry extension available + MicroProfileTelemetryServerConfiguration.enableMicroProfileTelemetry(); try { - // deploy an app that enables MP Telemetry, and disables the Micrometer Fault Tolerance metrics collection - // instead, see - deployer.deploy(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY_DISABLING_MICROMETER); + // And be sure Micrometer is available too + MicrometerServerConfiguration.enableMicrometer(otelCollector.getOtlpHttpEndpoint()); try { - // call the app operation for some times - for (int i = 0; i < REQUEST_COUNT; i++) { - get(deploymentUrl + "?operation=timeout&context=foobar&fail=true").then() - .assertThat() - .statusCode(HttpStatus.SC_OK) - .body(containsString("Fallback Hello, context = foobar")); + // deploy an app that enables MP Telemetry, and disables the Micrometer Fault Tolerance metrics collection + // instead, see + deployer.deploy(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY_DISABLING_MICROMETER); + try { + // call the app operation for some times + for (int i = 0; i < REQUEST_COUNT; i++) { + get(deploymentUrl + "?operation=timeout&context=foobar&fail=true").then() + .assertThat() + .statusCode(HttpStatus.SC_OK) + .body(containsString("Fallback Hello, context = foobar")); + } + // give it some time to actually be able and report some metrics via the Pmetheus URL + Thread.sleep(1_000); + // fetch the collected metrics in prometheus format + List metrics = otelCollector.fetchMetrics(TESTED_FT_METRIC); + Assert.assertFalse( + TESTED_FT_METRIC + + " metrics not found, which is not expected when the Micrometer extension is available, i.e. FT metrics should be collected.", + metrics.isEmpty()); + Assert.assertEquals( + "Duplicate metrics were found, which is not expected when both the Micrometer and MP Telemetry extension " + + + "are available but the deployment is explicitly enabling MP Telemetry while disabling Micrometer metrics collection instead.", + metrics.size(), metrics.stream().distinct().count()); + } finally { + deployer.undeploy(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY_DISABLING_MICROMETER); } - // give it some time to actually be able and report some metrics via the Pmetheus URL - Thread.sleep(1_000); - // fetch the collected metrics in prometheus format - List metrics = otelCollector.fetchMetrics(TESTED_FT_METRIC); - Assert.assertFalse( - TESTED_FT_METRIC - + " metrics not found, which is not expected when the Micrometer extension is available, i.e. FT metrics should be collected.", - metrics.isEmpty()); - Assert.assertEquals( - "Duplicate metrics were found, which is not expected when both the Micrometer and MP Telemetry extension " - + - "are available but the deployment is explicitly enabling MP Telemetry while disabling Micrometer metrics collection instead.", - metrics.size(), metrics.stream().distinct().count()); } finally { - deployer.undeploy(FAULT_TOLERANCE_DEPOYMENT_WITH_MP_TELEMETRY_DISABLING_MICROMETER); + MicrometerServerConfiguration.disableMicrometer(); } } finally { - MicrometerServerConfiguration.disableMicrometer(); + MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); } } finally { - otelCollector.stop(); + OpenTelemetryServerConfiguration.disableOpenTelemetry(); } } finally { - MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); + otelCollector.stop(); } } diff --git a/microprofile-telemetry/src/test/java/org/jboss/eap/qe/microprofile/telemetry/metrics/MPTelemetryServerSetupTask.java b/microprofile-telemetry/src/test/java/org/jboss/eap/qe/microprofile/telemetry/metrics/MPTelemetryServerSetupTask.java index f3cdb427..d54de186 100644 --- a/microprofile-telemetry/src/test/java/org/jboss/eap/qe/microprofile/telemetry/metrics/MPTelemetryServerSetupTask.java +++ b/microprofile-telemetry/src/test/java/org/jboss/eap/qe/microprofile/telemetry/metrics/MPTelemetryServerSetupTask.java @@ -4,6 +4,7 @@ import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.eap.qe.microprofile.common.setuptasks.MicroProfileTelemetryServerConfiguration; import org.jboss.eap.qe.microprofile.common.setuptasks.MicrometerServerConfiguration; +import org.jboss.eap.qe.microprofile.common.setuptasks.OpenTelemetryServerConfiguration; import org.jboss.eap.qe.observability.containers.OpenTelemetryCollectorContainer; import org.jboss.eap.qe.ts.common.docker.Docker; @@ -31,8 +32,8 @@ public void setup(ManagementClient managementClient, String containerId) throws otelCollector = OpenTelemetryCollectorContainer.getInstance(); otelCollector.start(); // Enable MP Telemetry based metrics, which rely on OpenTelemetry subsystem - MicroProfileTelemetryServerConfiguration.enableOpenTelemetry(); - MicroProfileTelemetryServerConfiguration.addOpenTelemetryCollectorConfiguration(otelCollector.getOtlpGrpcEndpoint()); + OpenTelemetryServerConfiguration.enableOpenTelemetry(); + OpenTelemetryServerConfiguration.addOpenTelemetryCollectorConfiguration(otelCollector.getOtlpGrpcEndpoint()); MicroProfileTelemetryServerConfiguration.enableMicroProfileTelemetry(); } @@ -43,7 +44,7 @@ public void setup(ManagementClient managementClient, String containerId) throws public void tearDown(ManagementClient managementClient, String containerId) throws Exception { // disable MP Telemetry based metrics MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry(); - MicroProfileTelemetryServerConfiguration.disableOpenTelemetry(); + OpenTelemetryServerConfiguration.disableOpenTelemetry(); // stop the OTel collector container otelCollector.stop(); } diff --git a/tooling-observability/src/main/java/org/jboss/eap/qe/observability/containers/OpenTelemetryCollectorContainer.java b/tooling-observability/src/main/java/org/jboss/eap/qe/observability/containers/OpenTelemetryCollectorContainer.java index 12248fb5..ee103a12 100644 --- a/tooling-observability/src/main/java/org/jboss/eap/qe/observability/containers/OpenTelemetryCollectorContainer.java +++ b/tooling-observability/src/main/java/org/jboss/eap/qe/observability/containers/OpenTelemetryCollectorContainer.java @@ -124,7 +124,7 @@ public static synchronized OpenTelemetryCollectorContainer getInstance() { * Static method to get a unique instance of {@link OpenTelemetryCollectorContainer}. * * @param jaegerBackendContainer A {@link JaegerContainer} instance that will be used as the Jaeger backend, e.g.: - * for storing and retrieving traces. + * for storing and retrieving traces. * @return A unique instance of {@link OpenTelemetryCollectorContainer} */ public static synchronized OpenTelemetryCollectorContainer getInstance(JaegerContainer jaegerBackendContainer) { @@ -150,7 +150,7 @@ public static synchronized OpenTelemetryCollectorContainer getNewInstance() { * external code. * * @param jaegerBackendContainer A {@link JaegerContainer} instance that will be used as the Jaeger backend, e.g.: - * for storing and retrieving traces. + * for storing and retrieving traces. * @return An instance of {@link OpenTelemetryCollectorContainer} */ public static synchronized OpenTelemetryCollectorContainer getNewInstance(JaegerContainer jaegerBackendContainer) { diff --git a/tooling-server-configuration/src/main/java/org/jboss/eap/qe/microprofile/common/setuptasks/MicroProfileTelemetryServerConfiguration.java b/tooling-server-configuration/src/main/java/org/jboss/eap/qe/microprofile/common/setuptasks/MicroProfileTelemetryServerConfiguration.java index 2da296d6..f7deca93 100644 --- a/tooling-server-configuration/src/main/java/org/jboss/eap/qe/microprofile/common/setuptasks/MicroProfileTelemetryServerConfiguration.java +++ b/tooling-server-configuration/src/main/java/org/jboss/eap/qe/microprofile/common/setuptasks/MicroProfileTelemetryServerConfiguration.java @@ -7,39 +7,14 @@ import org.wildfly.extras.creaper.core.online.operations.admin.Administration; /** - * Operations required to set up the server for MicroProfile Telemetry + * Operations required to set up and configure the {@code microprofile-telemetry} extension */ public class MicroProfileTelemetryServerConfiguration { - private static final Address OPENTELEMETRY_EXTENSION_ADDRESS = Address - .extension("org.wildfly.extension.opentelemetry"); - private static final Address OPENTELEMETRY_SUBSYSTEM_ADDRESS = Address - .subsystem("opentelemetry"); - private static final Address MICROPROFILE_TELEMETRY_EXTENSION_ADDRESS = Address .extension("org.wildfly.extension.microprofile.telemetry"); private static final Address MICROPROFILE_TELEMETRY_SUBSYSTEM_ADDRESS = Address .subsystem("microprofile-telemetry"); - /** - * Checks whether "org.wildfly.extension.opentelemetry" extension is present - * - * @return True if extension is already present,false otherwise - * @throws Exception exception thrown by the internal operation executed by {@link Operations} API - */ - public static Boolean openTelemetryExtensionExists(Operations operations) throws Exception { - return operations.exists(OPENTELEMETRY_EXTENSION_ADDRESS); - } - - /** - * Checks whether "opentelemetry" subsystem is present - * - * @return True if extension is already present,false otherwise - * @throws Exception exception thrown by the internal operation executed by {@link Operations} API - */ - public static Boolean openTelemetrySubsystemExists(Operations operations) throws Exception { - return operations.exists(OPENTELEMETRY_SUBSYSTEM_ADDRESS); - } - /** * Checks whether "org.wildfly.extension.microprofile.telemetry" extension is present * @@ -60,91 +35,6 @@ public static Boolean microProfileTelemetrySubsystemExists(Operations operations return operations.exists(MICROPROFILE_TELEMETRY_SUBSYSTEM_ADDRESS); } - /** - * Enable OpenTelemetry extension and subsystem. - * - * @throws Exception exception thrown by the internal operation executed by {@link OnlineManagementClient} API - */ - public static void enableOpenTelemetry() throws Exception { - try (OnlineManagementClient client = ManagementClientProvider.onlineStandalone()) { - enableOpenTelemetry(client); - } - } - - /** - * Set a default, working OpenTelemetry subsystem configuration, e.g.: to set the OTLP receiver URL. - */ - public static void addOpenTelemetryCollectorConfiguration(final String otlpCollectorEndpointUrl) throws Exception { - try (OnlineManagementClient client = ManagementClientProvider.onlineStandalone()) { - addOpenTelemetryCollectorConfiguration(otlpCollectorEndpointUrl, client); - } - } - - /** - * Set a default, working OpenTelemetry subsystem configuration, e.g.: to set the OTLP receiver URL. - * - * @param client {@link OnlineManagementClient} instance used to execute the command - */ - public static void addOpenTelemetryCollectorConfiguration(final String otlpCollectorEndpointUrl, - OnlineManagementClient client) throws Exception { - Operations operations = new Operations(client); - if (!openTelemetrySubsystemExists(operations)) { - throw new IllegalStateException("OpenTelemetry subsystem not found"); - } - operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "exporter-type", "otlp"); - operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "sampler-type", "on"); - operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "max-export-batch-size", "512"); - operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "batch-delay", "1"); - operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "max-queue-size", "1"); - operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "endpoint", otlpCollectorEndpointUrl); - new Administration(client).reloadIfRequired(); - } - - /** - * Enable OpenTelemetry extension and subsystem. - * - * @param client {@link OnlineManagementClient} instance used to execute the command - * @throws Exception exception thrown by the internal operation executed by {@link OnlineManagementClient} API - */ - public static void enableOpenTelemetry(OnlineManagementClient client) throws Exception { - Operations operations = new Operations(client); - if (!openTelemetryExtensionExists(operations)) { - operations.add(OPENTELEMETRY_EXTENSION_ADDRESS); - } - if (!openTelemetrySubsystemExists(operations)) { - operations.add(OPENTELEMETRY_SUBSYSTEM_ADDRESS); - } - new Administration(client).reloadIfRequired(); - } - - /** - * Disable OpenTelemetry subsystem and extension - * - * @throws Exception exception thrown by the internal operation executed by {@link OnlineManagementClient} API - */ - public static void disableOpenTelemetry() throws Exception { - try (OnlineManagementClient client = ManagementClientProvider.onlineStandalone()) { - disableOpenTelemetry(client); - } - } - - /** - * Disable OpenTelemetry subsystem and extension - * - * @param client {@link OnlineManagementClient} instance used to execute the command - * @throws Exception exception thrown by the internal operation executed by {@link OnlineManagementClient} API - */ - public static void disableOpenTelemetry(OnlineManagementClient client) throws Exception { - Operations operations = new Operations(client); - if (openTelemetrySubsystemExists(operations)) { - operations.remove(OPENTELEMETRY_SUBSYSTEM_ADDRESS); - } - if (openTelemetryExtensionExists(operations)) { - operations.remove(OPENTELEMETRY_EXTENSION_ADDRESS); - } - new Administration(client).reloadIfRequired(); - } - /** * Enable MicroProfile Telemetry extension and subsystem. * diff --git a/tooling-server-configuration/src/main/java/org/jboss/eap/qe/microprofile/common/setuptasks/OpenTelemetryServerConfiguration.java b/tooling-server-configuration/src/main/java/org/jboss/eap/qe/microprofile/common/setuptasks/OpenTelemetryServerConfiguration.java new file mode 100644 index 00000000..96b0c62a --- /dev/null +++ b/tooling-server-configuration/src/main/java/org/jboss/eap/qe/microprofile/common/setuptasks/OpenTelemetryServerConfiguration.java @@ -0,0 +1,121 @@ +package org.jboss.eap.qe.microprofile.common.setuptasks; + +import org.jboss.eap.qe.microprofile.tooling.server.configuration.creaper.ManagementClientProvider; +import org.wildfly.extras.creaper.core.online.OnlineManagementClient; +import org.wildfly.extras.creaper.core.online.operations.Address; +import org.wildfly.extras.creaper.core.online.operations.Operations; +import org.wildfly.extras.creaper.core.online.operations.admin.Administration; + +/** + * Operations required to set up and configure the {@code opentelemetry} subsystem + */ +public class OpenTelemetryServerConfiguration { + private static final Address OPENTELEMETRY_EXTENSION_ADDRESS = Address + .extension("org.wildfly.extension.opentelemetry"); + private static final Address OPENTELEMETRY_SUBSYSTEM_ADDRESS = Address + .subsystem("opentelemetry"); + + /** + * Checks whether "org.wildfly.extension.opentelemetry" extension is present + * + * @return True if extension is already present,false otherwise + * @throws Exception exception thrown by the internal operation executed by {@link Operations} API + */ + public static Boolean openTelemetryExtensionExists(Operations operations) throws Exception { + return operations.exists(OPENTELEMETRY_EXTENSION_ADDRESS); + } + + /** + * Checks whether "opentelemetry" subsystem is present + * + * @return True if extension is already present,false otherwise + * @throws Exception exception thrown by the internal operation executed by {@link Operations} API + */ + public static Boolean openTelemetrySubsystemExists(Operations operations) throws Exception { + return operations.exists(OPENTELEMETRY_SUBSYSTEM_ADDRESS); + } + + /** + * Enable OpenTelemetry extension and subsystem. + * + * @throws Exception exception thrown by the internal operation executed by {@link OnlineManagementClient} API + */ + public static void enableOpenTelemetry() throws Exception { + try (OnlineManagementClient client = ManagementClientProvider.onlineStandalone()) { + enableOpenTelemetry(client); + } + } + + /** + * Set a default, working OpenTelemetry subsystem configuration, e.g.: to set the OTLP receiver URL. + */ + public static void addOpenTelemetryCollectorConfiguration(final String otlpCollectorEndpointUrl) throws Exception { + try (OnlineManagementClient client = ManagementClientProvider.onlineStandalone()) { + addOpenTelemetryCollectorConfiguration(otlpCollectorEndpointUrl, client); + } + } + + /** + * Set a default, working OpenTelemetry subsystem configuration, e.g.: to set the OTLP receiver URL. + * + * @param client {@link OnlineManagementClient} instance used to execute the command + */ + public static void addOpenTelemetryCollectorConfiguration(final String otlpCollectorEndpointUrl, + OnlineManagementClient client) throws Exception { + Operations operations = new Operations(client); + if (!openTelemetrySubsystemExists(operations)) { + throw new IllegalStateException("OpenTelemetry subsystem not found"); + } + operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "exporter-type", "otlp"); + operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "sampler-type", "on"); + operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "max-export-batch-size", "512"); + operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "max-queue-size", "1"); + operations.writeAttribute(OPENTELEMETRY_SUBSYSTEM_ADDRESS, "endpoint", otlpCollectorEndpointUrl); + new Administration(client).reloadIfRequired(); + } + + /** + * Enable OpenTelemetry extension and subsystem. + * + * @param client {@link OnlineManagementClient} instance used to execute the command + * @throws Exception exception thrown by the internal operation executed by {@link OnlineManagementClient} API + */ + public static void enableOpenTelemetry(OnlineManagementClient client) throws Exception { + Operations operations = new Operations(client); + if (!openTelemetryExtensionExists(operations)) { + operations.add(OPENTELEMETRY_EXTENSION_ADDRESS); + } + if (!openTelemetrySubsystemExists(operations)) { + operations.add(OPENTELEMETRY_SUBSYSTEM_ADDRESS); + } + new Administration(client).reloadIfRequired(); + } + + /** + * Disable OpenTelemetry subsystem and extension + * + * @throws Exception exception thrown by the internal operation executed by {@link OnlineManagementClient} API + */ + public static void disableOpenTelemetry() throws Exception { + try (OnlineManagementClient client = ManagementClientProvider.onlineStandalone()) { + disableOpenTelemetry(client); + } + } + + /** + * Disable OpenTelemetry subsystem and extension + * + * @param client {@link OnlineManagementClient} instance used to execute the command + * @throws Exception exception thrown by the internal operation executed by {@link OnlineManagementClient} API + */ + public static void disableOpenTelemetry(OnlineManagementClient client) throws Exception { + Operations operations = new Operations(client); + if (openTelemetrySubsystemExists(operations)) { + operations.remove(OPENTELEMETRY_SUBSYSTEM_ADDRESS); + } + if (openTelemetryExtensionExists(operations)) { + operations.remove(OPENTELEMETRY_EXTENSION_ADDRESS); + } + new Administration(client).reloadIfRequired(); + } +}