From 923577a4697f50675dc13d77f92e29e21d9c4ba7 Mon Sep 17 00:00:00 2001 From: yasmin-aumeeruddy Date: Sun, 16 Jun 2024 08:47:15 +0100 Subject: [PATCH] Add jvm metrics to TCK --- tck/logs/src/main/resources/logback.xml | 11 -- tck/metrics/pom.xml | 22 ---- .../tck/cdi/AsyncDoubleCounterTest.java | 9 +- .../metrics/tck/cdi/AsyncLongCounterTest.java | 8 +- .../metrics/tck/cdi/DoubleCounterTest.java | 8 +- .../metrics/tck/cdi/DoubleGaugeTest.java | 6 +- .../metrics/tck/cdi/DoubleHistogramTest.java | 6 +- .../tck/cdi/DoubleUpDownCounterTest.java | 6 +- .../metrics/tck/cdi/LongCounterTest.java | 8 +- .../metrics/tck/cdi/LongGaugeTest.java | 6 +- .../metrics/tck/cdi/LongHistogramTest.java | 7 +- .../tck/cdi/LongUpDownCounterTest.java | 6 +- .../tck/exporter/InMemoryMetricExporter.java | 21 ++-- .../metrics/tck/jvm/JvmClassesTest.java | 99 ++++++++++++++++ .../telemetry/metrics/tck/jvm/JvmCpuTest.java | 99 ++++++++++++++++ .../tck/jvm/JvmGarbageCollectionTest.java | 83 ++++++++++++++ .../metrics/tck/jvm/JvmMemoryTest.java | 107 ++++++++++++++++++ .../metrics/tck/jvm/JvmThreadTest.java | 83 ++++++++++++++ 18 files changed, 515 insertions(+), 80 deletions(-) delete mode 100644 tck/logs/src/main/resources/logback.xml create mode 100644 tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmClassesTest.java create mode 100644 tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmCpuTest.java create mode 100644 tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmGarbageCollectionTest.java create mode 100644 tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmMemoryTest.java create mode 100644 tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmThreadTest.java diff --git a/tck/logs/src/main/resources/logback.xml b/tck/logs/src/main/resources/logback.xml deleted file mode 100644 index 8ac8ccfb..00000000 --- a/tck/logs/src/main/resources/logback.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - true - true - - - - - \ No newline at end of file diff --git a/tck/metrics/pom.xml b/tck/metrics/pom.xml index bc21c0f4..e1ecf89c 100644 --- a/tck/metrics/pom.xml +++ b/tck/metrics/pom.xml @@ -95,26 +95,4 @@ - - - - com.coderplus.maven.plugins - copy-rename-maven-plugin - ${version.plugin.copy.rename} - - - copy-readme - prepare-package - - copy - - - ../README.adoc - target/classes/README.adoc - - - - - - diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncDoubleCounterTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncDoubleCounterTest.java index 74330019..78b53d63 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncDoubleCounterTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncDoubleCounterTest.java @@ -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"; @@ -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"); } @@ -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); diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncLongCounterTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncLongCounterTest.java index 9d4d6945..7510c18e 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncLongCounterTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncLongCounterTest.java @@ -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"; @@ -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"); } @@ -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); diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleCounterTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleCounterTest.java index 2a8750ad..64d33349 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleCounterTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleCounterTest.java @@ -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"); } @@ -99,10 +99,10 @@ void testDoubleCounter() throws InterruptedException { expectedResults.keySet().stream().forEach(key -> doubleCounter.add(key, expectedResults.get(key))); - List metrics = metricExporter.getMetricData((MetricDataType.DOUBLE_SUM)); + List 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); }) @@ -119,4 +119,4 @@ void testDoubleCounter() throws InterruptedException { }); } -} \ No newline at end of file +} diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleGaugeTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleGaugeTest.java index 037b722d..89d3463e 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleGaugeTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleGaugeTest.java @@ -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"); } @@ -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); diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleHistogramTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleHistogramTest.java index 95ed8fab..2b5305d6 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleHistogramTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleHistogramTest.java @@ -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"); } @@ -98,10 +98,10 @@ void testDoubleHistogram() throws InterruptedException { expectedResults.keySet().stream().forEach(key -> doubleHistogram.record(key, expectedResults.get(key))); - List metrics = metricExporter.getMetricData((MetricDataType.HISTOGRAM)); + List 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); }) diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleUpDownCounterTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleUpDownCounterTest.java index 9a30ad24..67d40a58 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleUpDownCounterTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleUpDownCounterTest.java @@ -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"); } @@ -99,10 +99,10 @@ void testDoubleUpDownCounter() throws InterruptedException { expectedResults.keySet().stream().forEach(key -> doubleUpDownCounter.add(key, expectedResults.get(key))); - List metrics = metricExporter.getMetricData((MetricDataType.DOUBLE_SUM)); + List 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); }) diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongCounterTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongCounterTest.java index dbe01822..e40cf9b0 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongCounterTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongCounterTest.java @@ -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"); } @@ -100,10 +100,10 @@ void testLongCounter() throws InterruptedException { expectedResults.keySet().stream().forEach(key -> longCounter.add(key, expectedResults.get(key))); - List metrics = metricExporter.getMetricData((MetricDataType.LONG_SUM)); + List 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); }) @@ -119,4 +119,4 @@ void testLongCounter() throws InterruptedException { + TestUtils.mapToString(expectedResults.get(point.getValue()).asMap())); }); } -} \ No newline at end of file +} diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongGaugeTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongGaugeTest.java index f6f85380..d074b2cb 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongGaugeTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongGaugeTest.java @@ -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"); } @@ -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); diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongHistogramTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongHistogramTest.java index db00896b..8fc73d6a 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongHistogramTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongHistogramTest.java @@ -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"); } @@ -99,11 +99,10 @@ void testLongHistogram() throws InterruptedException { expectedResults.keySet().stream().forEach(key -> longHistogram.record(key, expectedResults.get(key))); - List metrics = metricExporter.getMetricData((MetricDataType.HISTOGRAM)); - System.out.println("Expected results :" + expectedResults); + List 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); }) diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongUpDownCounterTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongUpDownCounterTest.java index 85d1d23a..94bf5eab 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongUpDownCounterTest.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongUpDownCounterTest.java @@ -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"); } @@ -98,10 +98,10 @@ void testLongUpDownCounter() throws InterruptedException { expectedResults.keySet().stream().forEach(key -> longUpDownCounter.add(key, expectedResults.get(key))); - List metrics = metricExporter.getMetricData((MetricDataType.LONG_SUM)); + List 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); }) diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/exporter/InMemoryMetricExporter.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/exporter/InMemoryMetricExporter.java index 90b97982..bb4e0ecd 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/exporter/InMemoryMetricExporter.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/exporter/InMemoryMetricExporter.java @@ -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; @@ -55,22 +54,23 @@ public InMemoryMetricExporter() { * * @return a {@code List} of the finished {@code Metric}s. */ - public List getFinishedMetricItems(int itemCount) { - assertItemCount(itemCount); + public List 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 getMetricData(MetricDataType dataType) { - return getFinishedMetricItems(1).stream().filter(metric -> metric.getType() == dataType) + public List 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. @@ -98,7 +98,6 @@ public CompletableResultCode export(Collection metrics) { if (isStopped) { return CompletableResultCode.ofFailure(); } - System.out.println("Exporting metrics :" + metrics); finishedMetricItems.addAll(metrics); return CompletableResultCode.ofSuccess(); } diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmClassesTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmClassesTest.java new file mode 100644 index 00000000..c3105c27 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmClassesTest.java @@ -0,0 +1,99 @@ +/* + ********************************************************************** + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICES file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + **********************************************************************/ +package org.eclipse.microprofile.telemetry.metrics.tck.jvm; + +import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; +import org.eclipse.microprofile.telemetry.metrics.tck.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 io.opentelemetry.instrumentation.api.internal.SemconvStability; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import io.opentelemetry.api.OpenTelemetry; +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 JvmClassesTest extends Arquillian { + + @Inject + OpenTelemetry openTelemetry; + + @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(); + } + } + + @Test + void testClassLoadedMetrics() { + MetricData metric = metricExporter.getMetricData("jvm.class.loaded").get(0); + Assert.assertEquals(metric.getDescription(), "Number of classes loaded since JVM start."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM); + Assert.assertEquals(metric.getUnit(), "{class}"); + } + + @Test + void testClassUnloadedMetrics() { + MetricData metric = metricExporter.getMetricData("jvm.class.unloaded").get(0); + Assert.assertEquals(metric.getDescription(), "Number of classes unloaded since JVM start."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM); + Assert.assertEquals(metric.getUnit(), "{class}"); + } + + @Test + void testClassCountMetrics() { + MetricData metric = metricExporter.getMetricData("jvm.class.count").get(0); + Assert.assertEquals(metric.getDescription(), "Number of classes currently loaded."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM); + Assert.assertEquals(metric.getUnit(), "{class}"); + } + +} diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmCpuTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmCpuTest.java new file mode 100644 index 00000000..719fa848 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmCpuTest.java @@ -0,0 +1,99 @@ +/* + ********************************************************************** + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICES file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + **********************************************************************/ +package org.eclipse.microprofile.telemetry.metrics.tck.jvm; + +import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; +import org.eclipse.microprofile.telemetry.metrics.tck.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 io.opentelemetry.instrumentation.api.internal.SemconvStability; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import io.opentelemetry.api.OpenTelemetry; +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 JvmCpuTest extends Arquillian { + + @Inject + OpenTelemetry openTelemetry; + + @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(); + } + } + + @Test + void testCpuTimeMetric() { + MetricData metric = metricExporter.getMetricData("jvm.cpu.time").get(0); + Assert.assertEquals(metric.getDescription(), "CPU time used by the process as reported by the JVM."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM); + Assert.assertEquals(metric.getUnit(), "{s}"); + } + + @Test + void testCpuCountMetric() { + MetricData metric = metricExporter.getMetricData("jvm.cpu.count").get(0); + Assert.assertEquals(metric.getDescription(), "Number of processors available to the Java virtual machine.."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM); + Assert.assertEquals(metric.getUnit(), "{cpu}"); + } + + @Test + void testCpuRecentUtilizationMetric() { + MetricData metric = metricExporter.getMetricData("jvm.cpu.recent_utilization").get(0); + Assert.assertEquals(metric.getDescription(), "Recent CPU utilization for the process as reported by the JVM."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_GAUGE); + Assert.assertEquals(metric.getUnit(), "{1}"); + } + +} diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmGarbageCollectionTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmGarbageCollectionTest.java new file mode 100644 index 00000000..f4f63ad7 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmGarbageCollectionTest.java @@ -0,0 +1,83 @@ +/* + ********************************************************************** + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICES file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + **********************************************************************/ +package org.eclipse.microprofile.telemetry.metrics.tck.jvm; + +import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; +import org.eclipse.microprofile.telemetry.metrics.tck.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 io.opentelemetry.instrumentation.api.internal.SemconvStability; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import io.opentelemetry.api.OpenTelemetry; +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 JvmGarbageCollectionTest extends Arquillian { + + @Inject + OpenTelemetry openTelemetry; + + @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(); + } + } + + @Test + void testGarbageCollectionCountMetric() { + MetricData metric = metricExporter.getMetricData("jvm.gc.duration").get(0); + Assert.assertEquals(metric.getDescription(), "Duration of JVM garbage collection actions."); + Assert.assertEquals(metric.getType(), MetricDataType.HISTOGRAM); + Assert.assertEquals(metric.getUnit(), "{thread}"); + } + +} diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmMemoryTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmMemoryTest.java new file mode 100644 index 00000000..aa318b27 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmMemoryTest.java @@ -0,0 +1,107 @@ +/* + ********************************************************************** + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICES file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + **********************************************************************/ +package org.eclipse.microprofile.telemetry.metrics.tck.jvm; + +import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; +import org.eclipse.microprofile.telemetry.metrics.tck.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.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import io.opentelemetry.api.OpenTelemetry; +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 JvmMemoryTest extends Arquillian { + + @Inject + OpenTelemetry openTelemetry; + + @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(); + } + } + + @Test + void testJvmMemoryUsedMetric() { + MetricData metric = metricExporter.getMetricData("jvm.memory.used").get(0); + Assert.assertEquals(metric.getDescription(), "Measure of memory used."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM); + Assert.assertEquals(metric.getUnit(), "{By}"); + } + + @Test + void testJvmMemoryCommittedMetric() { + MetricData metric = metricExporter.getMetricData("jvm.memory.committed").get(0); + Assert.assertEquals(metric.getDescription(), "Measure of memory committed."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM); + Assert.assertEquals(metric.getUnit(), "{By}"); + } + + @Test + void testMemoryLimitMetric() { + MetricData metric = metricExporter.getMetricData("jvm.memory.limit").get(0); + Assert.assertEquals(metric.getDescription(), "Measure of max obtainable memory."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM); + Assert.assertEquals(metric.getUnit(), "{class}"); + } + + @Test + void testMemoryUsedAfterLastGcMetric() { + MetricData metric = metricExporter.getMetricData("jvm.memory.used_after_last_gc").get(0); + Assert.assertEquals(metric.getDescription(), + "Measure of memory used, as measured after the most recent garbage collection event on this pool."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM); + Assert.assertEquals(metric.getUnit(), "{By}"); + } + +} diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmThreadTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmThreadTest.java new file mode 100644 index 00000000..0b470d4a --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmThreadTest.java @@ -0,0 +1,83 @@ +/* + ********************************************************************** + * Copyright (c) 2024 Contributors to the Eclipse Foundation + * + * See the NOTICES file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + **********************************************************************/ +package org.eclipse.microprofile.telemetry.metrics.tck.jvm; + +import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; +import org.eclipse.microprofile.telemetry.metrics.tck.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 io.opentelemetry.instrumentation.api.internal.SemconvStability; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import io.opentelemetry.api.OpenTelemetry; +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 JvmThreadTest extends Arquillian { + + @Inject + OpenTelemetry openTelemetry; + + @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(); + } + } + + @Test + void testThreadCountMetric() { + MetricData metric = metricExporter.getMetricData("jvm.thread.count").get(0); + Assert.assertEquals(metric.getDescription(), "Number of executing platform threads."); + Assert.assertEquals(metric.getType(), MetricDataType.LONG_SUM); + Assert.assertEquals(metric.getUnit(), "{thread}"); + } + +}