Skip to content

Commit

Permalink
[WFLY-19846] Update multideployment MP Metrics tests for MP Telemetry…
Browse files Browse the repository at this point in the history
… metrics
  • Loading branch information
marekkopecky committed Dec 2, 2024
1 parent 8eba4a9 commit 479dde1
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.eap.qe.microprofile.fault.tolerance.deployments.v10.HelloService;
import org.jboss.eap.qe.microprofile.fault.tolerance.util.MicroProfileFaultToleranceServerConfiguration;
import org.jboss.eap.qe.microprofile.fault.tolerance.util.MicroProfileTelemetryServerSetup;
import org.jboss.eap.qe.microprofile.tooling.server.MicroProfileTelemetryServerSetup;
import org.jboss.eap.qe.microprofile.tooling.server.configuration.creaper.ManagementClientProvider;
import org.jboss.eap.qe.microprofile.tooling.server.configuration.deployment.ConfigurationUtil;
import org.jboss.eap.qe.microprofile.tooling.server.log.LogChecker;
Expand Down
48 changes: 47 additions & 1 deletion microprofile-telemetry-metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<version>1.0.0.Final-SNAPSHOT</version>
</parent>

<artifactId>microprofile-metrics</artifactId>
<artifactId>microprofile-telemetry-metrics</artifactId>

<dependencies>
<dependency>
Expand All @@ -33,11 +33,57 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
package org.jboss.eap.qe.microprofile.metrics.namefellow;

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

import org.eclipse.microprofile.metrics.annotation.Counted;
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";

@Counted(name = "ping-count", absolute = true, displayName = "Pong Count", description = "Number of ping invocations", tags = "_app="
+ 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
@@ -1,17 +1,34 @@
package org.jboss.eap.qe.microprofile.metrics.namefellow;

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

import org.eclipse.microprofile.metrics.annotation.Counted;
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";

@Counted(name = "ping-count", absolute = true, displayName = "Pong Count", description = "Number of ping invocations", tags = "_app="
+ 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,46 @@
package org.jboss.eap.qe.microprofile.metrics;

import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.eap.qe.microprofile.tooling.server.MicroProfileTelemetryServerSetup;
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());
}
// 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();
}

/**
* 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
MicroProfileTelemetryServerSetup.disableMicroProfileTelemetry();
MicroProfileTelemetryServerSetup.disableOpenTelemetry();
// stop the OTel collector container
otelCollector.stop();
}
}
Loading

0 comments on commit 479dde1

Please sign in to comment.