Skip to content

Commit

Permalink
[WFLY-19846] Restore multideployment MP Metrics tests from #274 for M…
Browse files Browse the repository at this point in the history
…P Telemetry Metrics
  • Loading branch information
marekkopecky committed Dec 2, 2024
1 parent fe9265a commit 8eba4a9
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 0 deletions.
142 changes: 142 additions & 0 deletions microprofile-telemetry-metrics/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jboss.eap.qe</groupId>
<artifactId>microprofile-test-suite</artifactId>
<version>1.0.0.Final-SNAPSHOT</version>
</parent>

<artifactId>microprofile-metrics</artifactId>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.eap.qe</groupId>
<artifactId>tooling-server-configuration</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-controller</artifactId>
</dependency>
</dependencies>

<profiles>
<!-- Test against Bootable JAR -->
<profile>
<id>bootablejar.profile</id>
<activation>
<property>
<name>ts.bootable</name>
</property>
</activation>
<build>
<plugins>
<!-- Bootable JAR Maven plugin -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-jar-maven-plugin</artifactId>
<executions>
<!-- Provision a server with the core functionality we will provide in OpenShift images -->
<execution>
<id>bootable-jar-packaging</id>
<goals>
<goal>package</goal>
</goals>
<phase>process-test-resources</phase>
<configuration>
<output-file-name>test-microprofile-metrics-bootable.jar</output-file-name>
<hollowJar>true</hollowJar>
<record-state>false</record-state>
<log-time>${galleon.log.time}</log-time>
<plugin-options>
<jboss-fork-embedded>${galleon.fork.embedded}</jboss-fork-embedded>
</plugin-options>
<feature-packs>
<feature-pack>
<groupId>${testsuite.galleon.pack.groupId}</groupId>
<artifactId>${testsuite.galleon.pack.artifactId}</artifactId>
<version>${testsuite.galleon.pack.version}</version>
</feature-pack>
</feature-packs>
<layers>
<layer>cloud-server</layer>
<layer>undertow-https</layer>
</layers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<systemPropertyVariables combine.children="append">
<jboss.args/>
<install.dir>${project.build.directory}/jboss-as-bootable</install.dir>
<bootable.jar>${project.build.directory}/test-microprofile-metrics-bootable.jar</bootable.jar>
<arquillian.xml>arquillian-bootable.xml</arquillian.xml>
<module.path>${jboss.modules.path}</module.path>
</systemPropertyVariables>
<classpathDependencyExcludes>
<classpathDependencyExclude>
org.wildfly.arquillian:wildfly-arquillian-container-managed
</classpathDependencyExclude>
</classpathDependencyExcludes>
<excludes>
<!-- Need MP FaultTolerance -->
<exclude>org/jboss/eap/qe/microprofile/metrics/integration/ft/*Test.java</exclude>
<!-- The following test cases need for a module.path system property to be set
which doesn't make sense with Bootable JAR -->
<exclude>org/jboss/eap/qe/microprofile/metrics/integration/config/CustomMetricCustomConfigSourceProviderTest</exclude>
<exclude>org/jboss/eap/qe/microprofile/metrics/integration/config/CustomMetricCustomConfigSourceTest</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Loading

0 comments on commit 8eba4a9

Please sign in to comment.