Skip to content

Commit

Permalink
Add jvm metrics to TCK
Browse files Browse the repository at this point in the history
  • Loading branch information
yasmin-aumeeruddy committed Jun 17, 2024
1 parent e7c2f9a commit 923577a
Show file tree
Hide file tree
Showing 18 changed files with 515 additions and 80 deletions.
11 changes: 0 additions & 11 deletions tck/logs/src/main/resources/logback.xml

This file was deleted.

22 changes: 0 additions & 22 deletions tck/metrics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,4 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>${version.plugin.copy.rename}</version>
<executions>
<execution>
<id>copy-readme</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>../README.adoc</sourceFile>
<destinationFile>target/classes/README.adoc</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import jakarta.inject.Inject;

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

Expand All @@ -57,7 +57,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"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");
}
Expand Down Expand Up @@ -86,10 +86,9 @@ void testAsyncDoubleCounter() throws InterruptedException {
.buildWithCallback(measurement -> {
measurement.record(1, Attributes.empty());
}));
MetricData metric = metricExporter.getMetricData(counterName).get(0);

MetricData metric = metricExporter.getMetricData((MetricDataType.DOUBLE_SUM)).get(0);

Assert.assertEquals(metric.getName(), counterName);
Assert.assertEquals(metric.getType(), MetricDataType.DOUBLE_SUM);
Assert.assertEquals(metric.getDescription(), counterDescription);
Assert.assertEquals(metric.getUnit(), counterUnit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

public class AsyncLongCounterTest extends Arquillian {

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

Expand All @@ -58,7 +58,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"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");
}
Expand Down Expand Up @@ -87,9 +87,9 @@ void testAsyncLongCounter() throws InterruptedException {
measurement.record(1, Attributes.empty());
}));

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

Assert.assertEquals(metric.getName(), counterName);
Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM);
Assert.assertEquals(metric.getDescription(), counterDescription);
Assert.assertEquals(metric.getUnit(), counterUnit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"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");
}
Expand Down Expand Up @@ -99,10 +99,10 @@ void testDoubleCounter() throws InterruptedException {

expectedResults.keySet().stream().forEach(key -> doubleCounter.add(key, expectedResults.get(key)));

List<MetricData> metrics = metricExporter.getMetricData((MetricDataType.DOUBLE_SUM));
List<MetricData> metrics = metricExporter.getMetricData((counterName));
metrics.stream()
.peek(metricData -> {
Assert.assertEquals(metricData.getName(), counterName);
Assert.assertEquals(metricData.getType(), MetricDataType.DOUBLE_SUM);
Assert.assertEquals(metricData.getDescription(), counterDescription);
Assert.assertEquals(metricData.getUnit(), counterUnit);
})
Expand All @@ -119,4 +119,4 @@ void testDoubleCounter() throws InterruptedException {
});
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"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");
}
Expand Down Expand Up @@ -83,8 +83,8 @@ void testDoubleGauge() throws InterruptedException {
measurement.record(1, Attributes.empty());
}));

MetricData metric = metricExporter.getMetricData(MetricDataType.DOUBLE_GAUGE).get(0);
Assert.assertEquals(metric.getName(), gaugeName);
MetricData metric = metricExporter.getMetricData(gaugeName).get(0);
Assert.assertEquals(metric.getType(), MetricDataType.DOUBLE_GAUGE);
Assert.assertEquals(metric.getDescription(), gaugeDescription);
Assert.assertEquals(metric.getUnit(), gaugeUnit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"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");
}
Expand Down Expand Up @@ -98,10 +98,10 @@ void testDoubleHistogram() throws InterruptedException {

expectedResults.keySet().stream().forEach(key -> doubleHistogram.record(key, expectedResults.get(key)));

List<MetricData> metrics = metricExporter.getMetricData((MetricDataType.HISTOGRAM));
List<MetricData> metrics = metricExporter.getMetricData((histogramName));
metrics.stream()
.peek(metricData -> {
Assert.assertEquals(metricData.getName(), histogramName);
Assert.assertEquals(metricData.getType(), MetricDataType.HISTOGRAM);
Assert.assertEquals(metricData.getDescription(), histogramDescription);
Assert.assertEquals(metricData.getUnit(), histogramUnit);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"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");
}
Expand Down Expand Up @@ -99,10 +99,10 @@ void testDoubleUpDownCounter() throws InterruptedException {

expectedResults.keySet().stream().forEach(key -> doubleUpDownCounter.add(key, expectedResults.get(key)));

List<MetricData> metrics = metricExporter.getMetricData((MetricDataType.DOUBLE_SUM));
List<MetricData> metrics = metricExporter.getMetricData((counterName));
metrics.stream()
.peek(metricData -> {
Assert.assertEquals(metricData.getName(), counterName);
Assert.assertEquals(metricData.getType(), MetricDataType.DOUBLE_SUM);
Assert.assertEquals(metricData.getDescription(), counterDescription);
Assert.assertEquals(metricData.getUnit(), counterUnit);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"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");
}
Expand Down Expand Up @@ -100,10 +100,10 @@ void testLongCounter() throws InterruptedException {

expectedResults.keySet().stream().forEach(key -> longCounter.add(key, expectedResults.get(key)));

List<MetricData> metrics = metricExporter.getMetricData((MetricDataType.LONG_SUM));
List<MetricData> metrics = metricExporter.getMetricData((counterName));
metrics.stream()
.peek(metricData -> {
Assert.assertEquals(metricData.getName(), counterName);
Assert.assertEquals(metricData.getType(), MetricDataType.LONG_SUM);
Assert.assertEquals(metricData.getDescription(), counterDescription);
Assert.assertEquals(metricData.getUnit(), counterUnit);
})
Expand All @@ -119,4 +119,4 @@ void testLongCounter() throws InterruptedException {
+ TestUtils.mapToString(expectedResults.get(point.getValue()).asMap()));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"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");
}
Expand Down Expand Up @@ -84,8 +84,8 @@ void testLongGauge() throws InterruptedException {
measurement.record(1, Attributes.empty());
}));

MetricData metric = metricExporter.getMetricData((MetricDataType.LONG_GAUGE)).get(0);
Assert.assertEquals(metric.getName(), gaugeName);
MetricData metric = metricExporter.getMetricData((gaugeName)).get(0);
Assert.assertEquals(metric.getType(), MetricDataType.LONG_GAUGE);
Assert.assertEquals(metric.getDescription(), gaugeDescription);
Assert.assertEquals(metric.getUnit(), gaugeUnit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"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");
}
Expand Down Expand Up @@ -99,11 +99,10 @@ void testLongHistogram() throws InterruptedException {

expectedResults.keySet().stream().forEach(key -> longHistogram.record(key, expectedResults.get(key)));

List<MetricData> metrics = metricExporter.getMetricData((MetricDataType.HISTOGRAM));
System.out.println("Expected results :" + expectedResults);
List<MetricData> metrics = metricExporter.getMetricData((histogramName));
metrics.stream()
.peek(metricData -> {
Assert.assertEquals(metricData.getName(), histogramName);
Assert.assertEquals(metricData.getType(), MetricDataType.HISTOGRAM);
Assert.assertEquals(metricData.getDescription(), histogramDescription);
Assert.assertEquals(metricData.getUnit(), histogramUnit);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"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");
}
Expand Down Expand Up @@ -98,10 +98,10 @@ void testLongUpDownCounter() throws InterruptedException {

expectedResults.keySet().stream().forEach(key -> longUpDownCounter.add(key, expectedResults.get(key)));

List<MetricData> metrics = metricExporter.getMetricData((MetricDataType.LONG_SUM));
List<MetricData> metrics = metricExporter.getMetricData((counterName));
metrics.stream()
.peek(metricData -> {
Assert.assertEquals(metricData.getName(), counterName);
Assert.assertEquals(metricData.getType(), MetricDataType.LONG_SUM);
Assert.assertEquals(metricData.getDescription(), counterDescription);
Assert.assertEquals(metricData.getUnit(), counterUnit);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricDataType;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import jakarta.enterprise.context.ApplicationScoped;

Expand All @@ -55,22 +54,23 @@ public InMemoryMetricExporter() {
*
* @return a {@code List} of the finished {@code Metric}s.
*/
public List<MetricData> getFinishedMetricItems(int itemCount) {
assertItemCount(itemCount);
public List<MetricData> getFinishedMetricItems() {
return finishedMetricItems.stream()
.collect(Collectors.toList());
}

public void assertItemCount(int itemCount) {
Awaitility.await().pollDelay(3, SECONDS).atMost(10, SECONDS)
.untilAsserted(() -> Assert.assertEquals(finishedMetricItems.size(), itemCount));
}

public List<MetricData> getMetricData(MetricDataType dataType) {
return getFinishedMetricItems(1).stream().filter(metric -> metric.getType() == dataType)
public List<MetricData> getMetricData(String metricName) {
assertMetricNameFound(metricName);
return getFinishedMetricItems().stream().filter(metric -> metric.getName() == metricName)
.collect(Collectors.toList());
// .orElseThrow(() -> new IllegalStateException("No metric found with type " + dataType));
}
public void assertMetricNameFound(String metricName) {
Awaitility.await().pollDelay(5, SECONDS).atMost(10, SECONDS)
.untilAsserted(() -> Assert.assertTrue(
getFinishedMetricItems().stream().filter(metric -> metric.getName() == metricName)
.collect(Collectors.toList()).size() > 0));
}

/**
* Clears the internal {@code List} of finished {@code Metric}s.
Expand Down Expand Up @@ -98,7 +98,6 @@ public CompletableResultCode export(Collection<MetricData> metrics) {
if (isStopped) {
return CompletableResultCode.ofFailure();
}
System.out.println("Exporting metrics :" + metrics);
finishedMetricItems.addAll(metrics);
return CompletableResultCode.ofSuccess();
}
Expand Down
Loading

0 comments on commit 923577a

Please sign in to comment.