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

Unify Metrics TCK logic #259

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<parent>
<groupId>org.eclipse.microprofile.telemetry</groupId>
<artifactId>microprofile-telemetry-parent</artifactId>
<version>2.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>microprofile-telemetry-api</artifactId>
<packaging>pom</packaging>
<name>MicroProfile Telemetry API</name>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<groupId>org.eclipse.microprofile.telemetry</groupId>
<artifactId>microprofile-telemetry-parent</artifactId>
<version>2.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>MicroProfile Telemetry</name>
<url>https://microprofile.io/project/eclipse/microprofile-telemetry</url>
Expand Down
4 changes: 2 additions & 2 deletions spec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<parent>
<groupId>org.eclipse.microprofile.telemetry</groupId>
<artifactId>microprofile-telemetry-parent</artifactId>
<version>2.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>microprofile-telemetry-spec</artifactId>
<packaging>pom</packaging>
<name>MicroProfile Telemetry Specification</name>

</project>
</project>
6 changes: 3 additions & 3 deletions tck/logs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.eclipse.microprofile.telemetry</groupId>
<artifactId>microprofile-telemetry-tck-parent</artifactId>
<version>2.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>microprofile-telemetry-logs-tck</artifactId>
Expand All @@ -33,7 +33,7 @@
<dependency>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-api</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
Expand Down Expand Up @@ -71,6 +71,6 @@
<artifactId>awaitility</artifactId>
<version>${version.awaitility}</version>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,25 @@ public class JulTest extends Arquillian {
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=none\notel.traces.exporter=none\notel.logs.exporter=logging\notel.service.name=openliberty"),
"otel.sdk.disabled=false\notel.metrics.exporter=none\notel.traces.exporter=none\n" +
"otel.logs.exporter=logging\notel.service.name=openliberty"),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Inject
private OpenTelemetry openTelemetry;

private static final Logger julLogger = Logger.getLogger("jul-logger");
private static final Logger JUL_LOGGER = Logger.getLogger("jul-logger");

private static final String logFilePath = System.getProperty("mptelemetry.tck.log.file.path");
private static final String LOG_FILE_PATH = System.getProperty("mptelemetry.tck.log.file.path");

private static final String JUL_INFO_MESSAGE = "a very distinguishable info message";
private static final String JUL_WARN_MESSAGE = "a very distinguishable warning message";

@Test
void julInfoTest() throws IOException {
julLogger.log(Level.INFO, JUL_INFO_MESSAGE);
JUL_LOGGER.log(Level.INFO, JUL_INFO_MESSAGE);
try {
Assert.assertTrue(checkMessage(".*INFO.*" + JUL_INFO_MESSAGE + ".*scopeInfo:.*"));
} catch (IOException e) {
Expand All @@ -70,7 +71,7 @@ void julInfoTest() throws IOException {

@Test
void julWarnTest() throws IOException {
julLogger.log(Level.WARNING, JUL_WARN_MESSAGE);
JUL_LOGGER.log(Level.WARNING, JUL_WARN_MESSAGE);
try {
Assert.assertTrue(checkMessage(".*WARN.*" + JUL_WARN_MESSAGE + ".*scopeInfo:.*"));
} catch (IOException e) {
Expand All @@ -81,7 +82,7 @@ public boolean checkMessage(String logMessage) throws IOException {
try {
try {
Thread.sleep(5000);
BufferedReader reader = new BufferedReader(new FileReader(logFilePath));
BufferedReader reader = new BufferedReader(new FileReader(LOG_FILE_PATH));
String line;
while ((line = reader.readLine()) != null) {
if (line.matches(logMessage)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@

public class ServerInstanceTest extends Arquillian {

private static final String serviceNameUnused = "NOT_USED";
private static final String SERVICE_NAME_UNUSED = "NOT_USED";

// otel.sdk.disabled=false must be set at runtime level to make this test valid
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class)
.addAsResource(new StringAsset(
"otel.service.name=" + serviceNameUnused),
"otel.service.name=" + SERVICE_NAME_UNUSED),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
Expand Down
6 changes: 3 additions & 3 deletions tck/metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.eclipse.microprofile.telemetry</groupId>
<artifactId>microprofile-telemetry-tck-parent</artifactId>
<version>2.1-SNAPSHOT</version>
<version>2.0.2-SNAPSHOT</version>
</parent>

<artifactId>microprofile-telemetry-metrics-tck</artifactId>
Expand All @@ -33,7 +33,7 @@
<dependency>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-api</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
Expand All @@ -45,7 +45,7 @@
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,76 +21,31 @@
**********************************************************************/
package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi;

import org.eclipse.microprofile.telemetry.metrics.tck.application.TestLibraries;
import org.eclipse.microprofile.telemetry.metrics.tck.application.exporter.InMemoryMetricExporter;
import org.eclipse.microprofile.telemetry.metrics.tck.application.exporter.InMemoryMetricExporterProvider;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.eclipse.microprofile.telemetry.metrics.tck.shared.BaseMetricsTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricDataType;
import jakarta.inject.Inject;

public class AsyncDoubleCounterTest extends Arquillian {
private static final String counterName = "testDoubleAsyncCounter";
private static final String counterDescription = "Testing double counter";
private static final String counterUnit = "Metric Tonnes";

private static final double DOUBLE_WITH_ATTRIBUTES = 20.2;
private static final double DOUBLE_WITHOUT_ATTRIBUTES = 10.1;

@Deployment
public static WebArchive createTestArchive() {

return ShrinkWrap.create(WebArchive.class)
.addClasses(InMemoryMetricExporter.class, InMemoryMetricExporterProvider.class)
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.logs.exporter=none\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Inject
private Meter sdkMeter;

@Inject
private InMemoryMetricExporter metricExporter;

@BeforeMethod
void setUp() {
if (metricExporter != null) {
metricExporter.reset();
}
}
public class AsyncDoubleCounterTest extends BaseMetricsTest {
private static final String COUNTER_NAME = "testDoubleAsyncCounter";
private static final String COUNTER_DESCRIPTION = "Testing double counter";
private static final String COUNTER_UNIT = "Metric Tonnes";

@Test
void testAsyncDoubleCounter() throws InterruptedException {
void testAsyncDoubleCounter() {
Assert.assertNotNull(
sdkMeter
.counterBuilder(counterName)
.counterBuilder(COUNTER_NAME)
.ofDoubles()
.setDescription(counterDescription)
.setUnit(counterUnit)
.setDescription(COUNTER_DESCRIPTION)
.setUnit(COUNTER_UNIT)
.buildWithCallback(measurement -> {
measurement.record(1, Attributes.empty());
}));
MetricData metric = metricExporter.getMetricData(counterName).get(0);

Assert.assertEquals(metric.getType(), MetricDataType.DOUBLE_SUM);
Assert.assertEquals(metric.getDescription(), counterDescription);
Assert.assertEquals(metric.getUnit(), counterUnit);
MetricData metric = assertMetric(COUNTER_NAME, MetricDataType.DOUBLE_SUM, COUNTER_DESCRIPTION, COUNTER_UNIT);

Assert.assertEquals(metric.getDoubleSumData()
.getPoints()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,77 +21,32 @@
**********************************************************************/
package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi;

import org.eclipse.microprofile.telemetry.metrics.tck.application.TestLibraries;
import org.eclipse.microprofile.telemetry.metrics.tck.application.exporter.InMemoryMetricExporter;
import org.eclipse.microprofile.telemetry.metrics.tck.application.exporter.InMemoryMetricExporterProvider;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.eclipse.microprofile.telemetry.metrics.tck.shared.BaseMetricsTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricDataType;
import jakarta.inject.Inject;

public class AsyncLongCounterTest extends Arquillian {
public class AsyncLongCounterTest extends BaseMetricsTest {

private static final String counterName = "testAsyncLongCounter";
private static final String counterDescription = "Testing long counter";
private static final String counterUnit = "Metric Tonnes";

private static final long LONG_VALUE = 12;
private static final long LONG_WITH_ATTRIBUTES = 24;
private static final long LONG_WITHOUT_ATTRIBUTES = 12;

@Deployment
public static WebArchive createTestArchive() {
return ShrinkWrap.create(WebArchive.class)
.addClasses(InMemoryMetricExporter.class, InMemoryMetricExporterProvider.class)
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.logs.exporter=none\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Inject
private Meter sdkMeter;

@Inject
private InMemoryMetricExporter metricExporter;

@BeforeMethod
void setUp() {
if (metricExporter != null) {
metricExporter.reset();
}
}
private static final String COUNTER_NAME = "testAsyncLongCounter";
private static final String COUNTER_DESCRIPTION = "Testing long counter";
private static final String COUNTER_UNIT = "Metric Tonnes";

@Test
void testAsyncLongCounter() throws InterruptedException {
void testAsyncLongCounter() {
Assert.assertNotNull(
sdkMeter
.counterBuilder(counterName)
.setDescription(counterDescription)
.setUnit(counterUnit)
.counterBuilder(COUNTER_NAME)
.setDescription(COUNTER_DESCRIPTION)
.setUnit(COUNTER_UNIT)
.buildWithCallback(measurement -> {
measurement.record(1, Attributes.empty());
}));

MetricData metric = metricExporter.getMetricData((counterName)).get(0);

Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM);
Assert.assertEquals(metric.getDescription(), counterDescription);
Assert.assertEquals(metric.getUnit(), counterUnit);
MetricData metric = assertMetric(COUNTER_NAME, MetricDataType.LONG_SUM, COUNTER_DESCRIPTION, COUNTER_UNIT);

Assert.assertEquals(metric.getLongSumData()
.getPoints()
Expand Down
Loading
Loading