Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multideployment scenario for MP Telemetry metrics #315

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions microprofile-telemetry/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?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-telemetry-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.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.telemetry</groupId>
<artifactId>microprofile-telemetry-api</artifactId>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.eap.qe</groupId>
<artifactId>tooling-docker</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.eap.qe</groupId>
<artifactId>tooling-observability</artifactId>
<scope>test</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.telemetry.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.telemetry.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,34 @@
package org.jboss.eap.qe.microprofile.telemetry.metrics.namefellow;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.LongCounter;
import io.opentelemetry.api.metrics.Meter;

@ApplicationScoped
public class PingOneService {
public static final String MESSAGE = "pong one";
public static final String PING_ONE_SERVICE_TAG = "ping-one-service-tag";

@Inject
private Meter meter;
private LongCounter longCounter;

@PostConstruct
public void init() {
longCounter = meter
.counterBuilder("ping_count")
.setDescription("Number of ping invocations")
.build();
}

public String ping() {
longCounter.add(1, Attributes.of(
AttributeKey.stringKey("_app"), PING_ONE_SERVICE_TAG));
return MESSAGE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jboss.eap.qe.microprofile.telemetry.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,34 @@
package org.jboss.eap.qe.microprofile.telemetry.metrics.namefellow;

import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.LongCounter;
import io.opentelemetry.api.metrics.Meter;

@ApplicationScoped
public class PingTwoService {
public static final String MESSAGE = "pong two";
public static final String PING_TWO_SERVICE_TAG = "ping-two-service-tag";

@Inject
private Meter meter;
private LongCounter longCounter;

@PostConstruct
public void init() {
longCounter = meter
.counterBuilder("ping_count")
.setDescription("Number of ping invocations")
.build();
}

public String ping() {
longCounter.add(1, Attributes.of(
AttributeKey.stringKey("_app"), PING_TWO_SERVICE_TAG));
return MESSAGE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.jboss.eap.qe.microprofile.telemetry.metrics;

import org.jboss.as.arquillian.api.ServerSetupTask;
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.observability.containers.OpenTelemetryCollectorContainer;
import org.jboss.eap.qe.ts.common.docker.Docker;

/**
* Server setup task for configuration of MicroProfile Telemetry and otel collector
*/
public class MPTelemetryServerSetupTask implements ServerSetupTask {

private static OpenTelemetryCollectorContainer otelCollector;

/**
* Start otel collector in container and configure OpenTelemetry and MP Telemetry in application server
*/
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
// we need a Docker container for The OTel collector here, so throw an exception if a docker service is not available
try {
Docker.checkDockerPresent();
} catch (Exception e) {
throw new IllegalStateException("Cannot verify Docker availability: " + e.getMessage());
}
// disable micrometer
MicrometerServerConfiguration.disableMicrometer();
// start the OTel collector container
otelCollector = OpenTelemetryCollectorContainer.getInstance();
otelCollector.start();
// Enable MP Telemetry based metrics, which rely on OpenTelemetry subsystem
MicroProfileTelemetryServerConfiguration.enableOpenTelemetry();
MicroProfileTelemetryServerConfiguration.addOpenTelemetryCollectorConfiguration(otelCollector.getOtlpGrpcEndpoint());
MicroProfileTelemetryServerConfiguration.enableMicroProfileTelemetry();
}

/**
* Stop otel collector in container and disable OpenTelemetry and MP Telemetry in application server
*/
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
// disable MP Telemetry based metrics
MicroProfileTelemetryServerConfiguration.disableMicroProfileTelemetry();
MicroProfileTelemetryServerConfiguration.disableOpenTelemetry();
// stop the OTel collector container
otelCollector.stop();
}
}
Loading
Loading