From 8eba4a9174b45a2adb6512dd5fdf6933c40c6b32 Mon Sep 17 00:00:00 2001 From: Marek Kopecky Date: Wed, 27 Nov 2024 14:15:19 +0100 Subject: [PATCH] [WFLY-19846] Restore multideployment MP Metrics tests from #274 for MP Telemetry Metrics --- microprofile-telemetry-metrics/pom.xml | 142 ++++++++++++++++ .../metrics/namefellow/PingApplication.java | 8 + .../metrics/namefellow/PingOneResource.java | 21 +++ .../metrics/namefellow/PingOneService.java | 17 ++ .../metrics/namefellow/PingTwoResource.java | 21 +++ .../metrics/namefellow/PingTwoService.java | 17 ++ .../MultipleDeploymentsMetricsTest.java | 152 ++++++++++++++++++ .../test/resources/arquillian-bootable.xml | 20 +++ pom.xml | 1 + 9 files changed, 399 insertions(+) create mode 100644 microprofile-telemetry-metrics/pom.xml create mode 100644 microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingApplication.java create mode 100644 microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingOneResource.java create mode 100644 microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingOneService.java create mode 100644 microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingTwoResource.java create mode 100644 microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingTwoService.java create mode 100644 microprofile-telemetry-metrics/src/test/java/org/jboss/eap/qe/microprofile/metrics/namefellow/MultipleDeploymentsMetricsTest.java create mode 100644 microprofile-telemetry-metrics/src/test/resources/arquillian-bootable.xml diff --git a/microprofile-telemetry-metrics/pom.xml b/microprofile-telemetry-metrics/pom.xml new file mode 100644 index 00000000..7bcde4e0 --- /dev/null +++ b/microprofile-telemetry-metrics/pom.xml @@ -0,0 +1,142 @@ + + + 4.0.0 + + + org.jboss.eap.qe + microprofile-test-suite + 1.0.0.Final-SNAPSHOT + + + microprofile-metrics + + + + junit + junit + test + + + io.rest-assured + rest-assured + test + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.wildfly.arquillian + wildfly-arquillian-container-managed + test + + + jakarta.servlet + jakarta.servlet-api + provided + + + org.jboss.eap.qe + tooling-server-configuration + test + + + org.wildfly.arquillian + wildfly-arquillian-common + test + + + org.wildfly.core + wildfly-controller + + + + + + + bootablejar.profile + + + ts.bootable + + + + + + + org.wildfly.plugins + wildfly-jar-maven-plugin + + + + bootable-jar-packaging + + package + + process-test-resources + + test-microprofile-metrics-bootable.jar + true + false + ${galleon.log.time} + + ${galleon.fork.embedded} + + + + ${testsuite.galleon.pack.groupId} + ${testsuite.galleon.pack.artifactId} + ${testsuite.galleon.pack.version} + + + + cloud-server + undertow-https + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + default-test + + test + + test + + + + ${project.build.directory}/jboss-as-bootable + ${project.build.directory}/test-microprofile-metrics-bootable.jar + arquillian-bootable.xml + ${jboss.modules.path} + + + + org.wildfly.arquillian:wildfly-arquillian-container-managed + + + + + org/jboss/eap/qe/microprofile/metrics/integration/ft/*Test.java + + org/jboss/eap/qe/microprofile/metrics/integration/config/CustomMetricCustomConfigSourceProviderTest + org/jboss/eap/qe/microprofile/metrics/integration/config/CustomMetricCustomConfigSourceTest + + + + + + + + + + diff --git a/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingApplication.java b/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingApplication.java new file mode 100644 index 00000000..2ad2d84f --- /dev/null +++ b/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingApplication.java @@ -0,0 +1,8 @@ +package org.jboss.eap.qe.microprofile.metrics.namefellow; + +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.core.Application; + +@ApplicationPath("/") +public class PingApplication extends Application { +} diff --git a/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingOneResource.java b/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingOneResource.java new file mode 100644 index 00000000..185ab4db --- /dev/null +++ b/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingOneResource.java @@ -0,0 +1,21 @@ +package org.jboss.eap.qe.microprofile.metrics.namefellow; + +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/" + PingOneResource.RESOURCE) +public class PingOneResource { + public static final String RESOURCE = "ping-one"; + + @Inject + private PingOneService ping; + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String doGet() { + return ping.ping(); + } +} diff --git a/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingOneService.java b/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingOneService.java new file mode 100644 index 00000000..c79716cf --- /dev/null +++ b/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingOneService.java @@ -0,0 +1,17 @@ +package org.jboss.eap.qe.microprofile.metrics.namefellow; + +import jakarta.enterprise.context.ApplicationScoped; + +import org.eclipse.microprofile.metrics.annotation.Counted; + +@ApplicationScoped +public class PingOneService { + public static final String MESSAGE = "pong one"; + public static final String PING_ONE_SERVICE_TAG = "ping-one-service-tag"; + + @Counted(name = "ping-count", absolute = true, displayName = "Pong Count", description = "Number of ping invocations", tags = "_app=" + + PING_ONE_SERVICE_TAG) + public String ping() { + return MESSAGE; + } +} diff --git a/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingTwoResource.java b/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingTwoResource.java new file mode 100644 index 00000000..df0b2d29 --- /dev/null +++ b/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingTwoResource.java @@ -0,0 +1,21 @@ +package org.jboss.eap.qe.microprofile.metrics.namefellow; + +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/" + PingTwoResource.RESOURCE) +public class PingTwoResource { + public static final String RESOURCE = "ping-one"; + + @Inject + private PingTwoService ping; + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String doGet() { + return ping.ping(); + } +} diff --git a/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingTwoService.java b/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingTwoService.java new file mode 100644 index 00000000..5d0ad901 --- /dev/null +++ b/microprofile-telemetry-metrics/src/main/java/org/jboss/eap/qe/microprofile/metrics/namefellow/PingTwoService.java @@ -0,0 +1,17 @@ +package org.jboss.eap.qe.microprofile.metrics.namefellow; + +import jakarta.enterprise.context.ApplicationScoped; + +import org.eclipse.microprofile.metrics.annotation.Counted; + +@ApplicationScoped +public class PingTwoService { + public static final String MESSAGE = "pong two"; + public static final String PING_TWO_SERVICE_TAG = "ping-two-service-tag"; + + @Counted(name = "ping-count", absolute = true, displayName = "Pong Count", description = "Number of ping invocations", tags = "_app=" + + PING_TWO_SERVICE_TAG) + public String ping() { + return MESSAGE; + } +} diff --git a/microprofile-telemetry-metrics/src/test/java/org/jboss/eap/qe/microprofile/metrics/namefellow/MultipleDeploymentsMetricsTest.java b/microprofile-telemetry-metrics/src/test/java/org/jboss/eap/qe/microprofile/metrics/namefellow/MultipleDeploymentsMetricsTest.java new file mode 100644 index 00000000..82444104 --- /dev/null +++ b/microprofile-telemetry-metrics/src/test/java/org/jboss/eap/qe/microprofile/metrics/namefellow/MultipleDeploymentsMetricsTest.java @@ -0,0 +1,152 @@ +package org.jboss.eap.qe.microprofile.metrics.namefellow; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasKey; +import static org.hamcrest.Matchers.hasSize; + +import java.net.URL; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.OperateOnDeployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.eap.qe.microprofile.tooling.server.configuration.ConfigurationException; +import org.jboss.eap.qe.microprofile.tooling.server.configuration.arquillian.ArquillianContainerProperties; +import org.jboss.eap.qe.microprofile.tooling.server.configuration.arquillian.ArquillianDescriptorWrapper; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import io.restassured.http.ContentType; +import io.restassured.specification.RequestSpecification; + +/** + * Multiple deployment scenario. + */ +@RunWith(Arquillian.class) +public class MultipleDeploymentsMetricsTest { + + public static final String PING_ONE_SERVICE = "ping-one-service"; + public static final String PING_TWO_SERVICE = "ping-two-service"; + + @Deployment(name = PING_ONE_SERVICE, order = 1) + public static WebArchive createDeployment1() { + return ShrinkWrap.create(WebArchive.class, PING_ONE_SERVICE + ".war") + .addClasses(PingApplication.class, PingOneService.class, PingOneResource.class); + + } + + @Deployment(name = PING_TWO_SERVICE, order = 2) + public static WebArchive createDeployment2() { + return ShrinkWrap.create(WebArchive.class, PING_TWO_SERVICE + ".war") + .addClasses(PingApplication.class, PingTwoService.class, PingTwoResource.class); + } + + private static RequestSpecification jsonMetricsRequest; + private static RequestSpecification textMetricsRequest; + + @BeforeClass + public static void prepare() throws ConfigurationException { + ArquillianContainerProperties arqProps = new ArquillianContainerProperties( + ArquillianDescriptorWrapper.getArquillianDescriptor()); + String url = "http://" + arqProps.getDefaultManagementAddress() + ":" + arqProps.getDefaultManagementPort() + + "/metrics"; + jsonMetricsRequest = given() + .baseUri(url) + .accept(ContentType.JSON); + textMetricsRequest = given() + .baseUri(url) + .accept(ContentType.TEXT); + } + + /** + * @tpTestDetails High level scenario to verify two none-reusable counter metrics of the same name are registered + * and tagged properly. The information is available under {@code /metrics} endpoint via HTTP OPTIONS. + * Metrics are in separate archives - multiple-deployment. + * @tpPassCrit Metrics are tagged properly + * @tpSince EAP 7.4.0.CD19 + */ + @Test + @RunAsClient + public void applicationMetricsAreRegisteredAtDeploymentTime() { + jsonMetricsRequest.options().then() + .contentType(ContentType.JSON) + .header("Content-Type", containsString("application/json")) + .body("$", hasKey("application"), + "application", hasKey("ping-count"), + "application.ping-count", hasKey("tags"), // 11 at `/` + 1 at `/another-hello` + "application.ping-count.tags", hasSize(2), + "application.ping-count.tags[0]", hasSize(1), + "application.ping-count.tags[1]", hasSize(1), + "application.ping-count.tags.flatten()", + contains("_app=" + PingOneService.PING_ONE_SERVICE_TAG, "_app=" + PingTwoService.PING_TWO_SERVICE_TAG)); + } + + /** + * @tpTestDetails High level scenario to verify two none-reusable counter metrics of the same name are incremented + * properly according to the number of a CDI beans invocation. + * Metrics are in separate archives - multiple-deployment. + * @tpPassCrit Counters have correct values (according to number of the CDI bean invocations) in JSON and prometheus format. + * @tpSince EAP 7.4.0.CD19 + */ + @Test + @RunAsClient + public void dataTest(@ArquillianResource @OperateOnDeployment(PING_ONE_SERVICE) URL pingOneUrl, + @ArquillianResource @OperateOnDeployment(PING_TWO_SERVICE) URL pingTwoUrl) { + + get(pingOneUrl.toString() + PingOneResource.RESOURCE) + .then() + .statusCode(200) + .body(equalTo(PingOneService.MESSAGE)); + + get(pingTwoUrl.toString() + PingTwoResource.RESOURCE) + .then() + .statusCode(200) + .body(equalTo(PingTwoService.MESSAGE)); + + get(pingTwoUrl.toString() + PingTwoResource.RESOURCE).then().statusCode(200); + get(pingTwoUrl.toString() + PingTwoResource.RESOURCE).then().statusCode(200); + get(pingTwoUrl.toString() + PingTwoResource.RESOURCE).then().statusCode(200); + + get(pingOneUrl.toString() + PingOneResource.RESOURCE).then().statusCode(200); + + jsonDataTest(); + prometheusDataTest(); + } + + /** + * Verify correct data of counters in JSON format. ping one: 2, ping-two: 4 + */ + private void jsonDataTest() { + jsonMetricsRequest.get().then() + .contentType(ContentType.JSON) + .header("Content-Type", containsString("application/json")) + .body("$", hasKey("application"), + "application", hasKey("ping-count;_app=" + PingOneService.PING_ONE_SERVICE_TAG), + "application.ping-count;_app=" + PingOneService.PING_ONE_SERVICE_TAG, equalTo(2), + + "application", hasKey("ping-count;_app=" + PingTwoService.PING_TWO_SERVICE_TAG), + "application.ping-count;_app=" + PingTwoService.PING_TWO_SERVICE_TAG, equalTo(4)); + } + + /** + * Verify correct data of counters in prometheus format. ping one: 2, ping-two: 4 + */ + private void prometheusDataTest() { + textMetricsRequest.get().then() + .contentType(ContentType.TEXT) + .header("Content-Type", containsString("text/plain")) + .body( + containsString( + "application_ping_count_total{_app=\"" + PingTwoService.PING_TWO_SERVICE_TAG + "\"} 4.0"), + containsString( + "application_ping_count_total{_app=\"" + PingOneService.PING_ONE_SERVICE_TAG + "\"} 2.0")); + } +} diff --git a/microprofile-telemetry-metrics/src/test/resources/arquillian-bootable.xml b/microprofile-telemetry-metrics/src/test/resources/arquillian-bootable.xml new file mode 100644 index 00000000..c7de7366 --- /dev/null +++ b/microprofile-telemetry-metrics/src/test/resources/arquillian-bootable.xml @@ -0,0 +1,20 @@ + + + + + + + + + ${install.dir} + ${bootable.jar} + ${server.jvm.args} + ${jboss.args} + true + 127.0.0.1 + 9990 + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 172981bf..50dc25f6 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ microprofile-fault-tolerance microprofile-jwt microprofile-lra + microprofile-telemetry-metrics microprofile-open-api micrometer tooling-observability