From 4a7ded71f7f0fbf71748e66cb6e3c6e1f7a57654 Mon Sep 17 00:00:00 2001 From: yasmin-aumeeruddy Date: Fri, 12 Apr 2024 15:43:50 +0100 Subject: [PATCH 1/5] Update logs tck to remove in-memory exporter Add jvm metrics to TCK Remove log appender dependencies create test for http metrics (#197) Change exporter for jvm metrics separate metric tests for runtime tests Update logs tck --- tck/logs/README.adoc | 8 + tck/logs/pom.xml | 30 --- .../{LogAppenderTest.java => JulTest.java} | 54 +++++- .../logs/tck/config/ServerInstanceTest.java | 1 - .../logs/tck/config/TestLibraries.java | 32 --- tck/logs/src/main/resources/logback.xml | 11 -- tck/metrics/README.adoc | 31 ++- .../telemetry/metrics/tck/TestLibraries.java | 32 --- .../tck/application/BasicHttpClient.java | 111 +++++++++++ .../tck/{ => application}/ConfigAsset.java | 2 +- .../tck/application/TestLibraries.java | 2 +- .../tck/{ => application}/TestUtils.java | 2 +- .../cdi/AsyncDoubleCounterTest.java | 17 +- .../cdi/AsyncLongCounterTest.java | 16 +- .../cdi/DoubleCounterTest.java | 18 +- .../cdi/DoubleGaugeTest.java | 14 +- .../cdi/DoubleHistogramTest.java | 16 +- .../cdi/DoubleUpDownCounterTest.java | 16 +- .../cdi/LongCounterTest.java | 18 +- .../{ => application}/cdi/LongGaugeTest.java | 14 +- .../cdi/LongHistogramTest.java | 17 +- .../cdi/LongUpDownCounterTest.java | 16 +- .../exporter/InMemoryMetricExporter.java | 23 ++- .../InMemoryMetricExporterProvider.java | 2 +- .../application/http/HttpHistogramTest.java | 183 ++++++++++++++++++ .../metrics/tck/jvm/JvmClassesTest.java | 70 +++++++ .../telemetry/metrics/tck/jvm/JvmCpuTest.java | 71 +++++++ .../tck/jvm/JvmGarbageCollectionTest.java | 57 ++++++ .../metrics/tck/jvm/JvmMemoryTest.java | 80 ++++++++ .../metrics/tck/jvm/JvmThreadTest.java | 57 ++++++ .../metrics/tck/jvm/MetricsReader.java | 57 ++++++ 31 files changed, 864 insertions(+), 214 deletions(-) rename tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/application/{LogAppenderTest.java => JulTest.java} (53%) delete mode 100644 tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/config/TestLibraries.java delete mode 100644 tck/logs/src/main/resources/logback.xml delete mode 100644 tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/TestLibraries.java create mode 100644 tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/BasicHttpClient.java rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/ConfigAsset.java (96%) rename tck/{logs/src/main/java/org/eclipse/microprofile/telemetry/logs => metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics}/tck/application/TestLibraries.java (94%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/TestUtils.java (94%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/cdi/AsyncDoubleCounterTest.java (84%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/cdi/AsyncLongCounterTest.java (84%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/cdi/DoubleCounterTest.java (88%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/cdi/DoubleGaugeTest.java (85%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/cdi/DoubleHistogramTest.java (88%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/cdi/DoubleUpDownCounterTest.java (88%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/cdi/LongCounterTest.java (88%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/cdi/LongGaugeTest.java (85%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/cdi/LongHistogramTest.java (88%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/cdi/LongUpDownCounterTest.java (88%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/exporter/InMemoryMetricExporter.java (84%) rename tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/{ => application}/exporter/InMemoryMetricExporterProvider.java (94%) create mode 100644 tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/http/HttpHistogramTest.java 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 create mode 100644 tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/MetricsReader.java diff --git a/tck/logs/README.adoc b/tck/logs/README.adoc index 3a0c5450..39d733a6 100644 --- a/tck/logs/README.adoc +++ b/tck/logs/README.adoc @@ -81,6 +81,14 @@ To test that the OpenTelemetry instance is set properly at runtime initializatio ---- +== Logging File Configuration +OpenTelemetry logs are sent to stdout in the tests. Ensure logs written to stdout are captured in a file and set the system property `log.file.path` to the file containing the log output when running the logs TCK. For example: + +[source, xml] +---- +log.file.path=console.log +---- + == Configuration in Apache Maven pom.xml If you use Apache Maven then the tests are run via the `maven-surefire-plugin` diff --git a/tck/logs/pom.xml b/tck/logs/pom.xml index 46d45860..6326b533 100644 --- a/tck/logs/pom.xml +++ b/tck/logs/pom.xml @@ -46,36 +46,6 @@ io.opentelemetry opentelemetry-sdk - - io.opentelemetry - opentelemetry-sdk-extension-autoconfigure - - - io.opentelemetry.instrumentation - opentelemetry-instrumentation-annotations - - - io.opentelemetry.semconv - opentelemetry-semconv - - - - io.opentelemetry.instrumentation - opentelemetry-logback-appender-1.0 - 2.2.0-alpha - - - - ch.qos.logback - logback-classic - 1.5.6 - - - - org.slf4j - jul-to-slf4j - 2.0.13 - org.testng testng diff --git a/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/application/LogAppenderTest.java b/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/application/JulTest.java similarity index 53% rename from tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/application/LogAppenderTest.java rename to tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/application/JulTest.java index 0fe5b5d1..c1c06764 100644 --- a/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/application/LogAppenderTest.java +++ b/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/application/JulTest.java @@ -20,6 +20,10 @@ package org.eclipse.microprofile.telemetry.logs.tck.application; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.logging.Level; import java.util.logging.Logger; import org.jboss.arquillian.container.test.api.Deployment; @@ -28,16 +32,17 @@ 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.Test; import io.opentelemetry.api.OpenTelemetry; import jakarta.inject.Inject; -public class LogAppenderTest extends Arquillian { +public class JulTest extends Arquillian { + @Deployment public static WebArchive createDeployment() { return ShrinkWrap.create(WebArchive.class) - .addAsLibrary(TestLibraries.AWAITILITY_LIB) .addAsResource(new StringAsset( "otel.sdk.disabled=false\notel.metrics.exporter=none\notel.traces.exporter=none\notel.logs.exporter=logging\notel.service.name=openliberty"), "META-INF/microprofile-config.properties") @@ -49,13 +54,46 @@ public static WebArchive createDeployment() { private static final Logger julLogger = Logger.getLogger("jul-logger"); + private static final String logFilePath = System.getProperty("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 julTest() throws InterruptedException { + void julInfoTest() throws IOException { + julLogger.log(Level.INFO, JUL_INFO_MESSAGE); + try { + Assert.assertTrue(checkMessage(".*INFO.*" + JUL_INFO_MESSAGE + ".*scopeInfo:.*")); + } catch (IOException e) { + } + } + + @Test + void julWarnTest() throws IOException { + julLogger.log(Level.WARNING, JUL_WARN_MESSAGE); + try { + Assert.assertTrue(checkMessage(".*WARN.*" + JUL_WARN_MESSAGE + ".*scopeInfo:.*")); + } catch (IOException e) { + } + } - julLogger.info("A JUL log message"); - julLogger.info("A JUL log message"); - julLogger.info("A JUL log message"); - julLogger.info("A JUL log message"); - Thread.sleep(10000); + public boolean checkMessage(String logMessage) throws IOException { + try { + try { + Thread.sleep(5000); + BufferedReader reader = new BufferedReader(new FileReader(logFilePath)); + String line; + while ((line = reader.readLine()) != null) { + if (line.matches(logMessage)) { + return true; + } + } + return false; + } catch (IOException e) { + return false; + } + } catch (InterruptedException e) { + return false; + } } } diff --git a/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/config/ServerInstanceTest.java b/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/config/ServerInstanceTest.java index b754284e..c47ce80e 100644 --- a/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/config/ServerInstanceTest.java +++ b/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/config/ServerInstanceTest.java @@ -40,7 +40,6 @@ public class ServerInstanceTest extends Arquillian { @Deployment public static WebArchive createDeployment() { return ShrinkWrap.create(WebArchive.class) - .addAsLibrary(TestLibraries.AWAITILITY_LIB) .addAsResource(new StringAsset( "otel.service.name=" + serviceNameUnused), "META-INF/microprofile-config.properties") diff --git a/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/config/TestLibraries.java b/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/config/TestLibraries.java deleted file mode 100644 index 7fc1e3ad..00000000 --- a/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/config/TestLibraries.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE 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. - * - */ -package org.eclipse.microprofile.telemetry.logs.tck.config; - -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; - -public class TestLibraries { - - public static final JavaArchive AWAITILITY_LIB = ShrinkWrap.create(JavaArchive.class, "awaitility.jar") - .addPackages(true, "org.awaitility", "org.hamcrest"); - - private TestLibraries() { - } -} 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/README.adoc b/tck/metrics/README.adoc index 8528cb19..ea2a4e6e 100644 --- a/tck/metrics/README.adoc +++ b/tck/metrics/README.adoc @@ -49,7 +49,34 @@ To enable the tests in your project you need to add the following dependency to ---- -If you want to run the metrics tests, you can specify all tests in the `tck-suite.xml`. E.g. +== Running the tests + +The JVM metrics tests require runtime configuration to enable metric reading at a runtime level. The metrics must be sent to stdout in the tests. Ensure logs written to stdout are captured in a file and set the system property `log.file.path` to the file containing the log output when running the logs TCK. Configure the runtime with `otel.metrics.exporter=console`/`OTEL_METRICS_EXPORTER=CONSOLE` and `otel.sdk.disabled=false`/`OTEL_SDK_DISABLED=FALSE` as a system property or environment variable. For example: + + +[source, xml] +---- +otel.sdk.disabled=false +otel.metrics.exporter=console +log.file.path=console.log +---- + +To run the JVM metrics tests, include the following content in the `tck-suite.xml` in your project: + +[source, xml] +---- + + + + + + + + + +---- + +The remaining metrics tests must use an OpenTelemetry SDK instance that is configured by the configuration properties set in the application. Ensure that `otel.sdk.disabled` and `otel.metrics.exporter` are NOT set by the runtime. To run the application metrics tests, include the following content in the `tck-suite.xml` in your project: [source, xml] ---- @@ -58,7 +85,7 @@ If you want to run the metrics tests, you can specify all tests in the `tck-suit - + diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/TestLibraries.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/TestLibraries.java deleted file mode 100644 index 86bf368d..00000000 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/TestLibraries.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE 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. - * - */ -package org.eclipse.microprofile.telemetry.metrics.tck; - -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; - -public class TestLibraries { - - public static final JavaArchive AWAITILITY_LIB = ShrinkWrap.create(JavaArchive.class, "awaitility.jar") - .addPackages(true, "org.awaitility", "org.hamcrest"); - - private TestLibraries() { - } -} diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/BasicHttpClient.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/BasicHttpClient.java new file mode 100644 index 00000000..87db538d --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/BasicHttpClient.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2022-2023 Contributors to the Eclipse Foundation + * + * See the NOTICE 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. + * + */ +package org.eclipse.microprofile.telemetry.metrics.tck.application; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import org.jboss.arquillian.test.api.ArquillianResource; + +/** + * A really basic client for doing Http requests + *

+ * For use when we don't want to use JAX-RS client or something else which has integration with telemetry + */ +public class BasicHttpClient { + + private URI baseUri; + + /** + * @param baseUrl + * The base URL. Any path requested through this client will be appended to this URL. This should usually + * be a URL injected using {@link ArquillianResource} + */ + public BasicHttpClient(URL baseUrl) { + try { + baseUri = baseUrl.toURI(); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + + /** + * Makes a GET request to a path and returns the response code + * + * @param path + * the path to request, relative to the baseUrl + * @return the response code + */ + public int get(String path) { + if (path.startsWith("/")) { + path = path.substring(1); + } + try { + URL spanUrl = baseUri.resolve(path).toURL(); + HttpURLConnection connection = (HttpURLConnection) spanUrl.openConnection(); + try { + return connection.getResponseCode(); + } catch (Exception e) { + throw new RuntimeException("Exception retrieving " + spanUrl, e); + } finally { + connection.disconnect(); + } + } catch (Exception e) { + throw new RuntimeException("Exception retrieving path " + path, e); + } + } + + /** + * Makes a GET request to a path and returns the response code + * + * @param path + * the path to request, relative to the baseUrl + * @return the response message + */ + public String getResponseMessage(String path) { + if (path.startsWith("/")) { + path = path.substring(1); + } + try { + URL spanUrl = baseUri.resolve(path).toURL(); + HttpURLConnection connection = (HttpURLConnection) spanUrl.openConnection(); + try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + String inputLine; + StringBuilder response = new StringBuilder(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + return response.toString(); + } catch (Exception e) { + throw new RuntimeException("Exception retrieving " + spanUrl, e); + } finally { + connection.disconnect(); + } + } catch (Exception e) { + throw new RuntimeException("Exception retrieving path " + path, e); + } + } + +} \ No newline at end of file diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/ConfigAsset.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/ConfigAsset.java similarity index 96% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/ConfigAsset.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/ConfigAsset.java index 7555689f..be0dda19 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/ConfigAsset.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/ConfigAsset.java @@ -17,7 +17,7 @@ * limitations under the License. * */ -package org.eclipse.microprofile.telemetry.metrics.tck; +package org.eclipse.microprofile.telemetry.metrics.tck.application; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/application/TestLibraries.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/TestLibraries.java similarity index 94% rename from tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/application/TestLibraries.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/TestLibraries.java index b29c1ebd..6c031499 100644 --- a/tck/logs/src/main/java/org/eclipse/microprofile/telemetry/logs/tck/application/TestLibraries.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/TestLibraries.java @@ -17,7 +17,7 @@ * limitations under the License. * */ -package org.eclipse.microprofile.telemetry.logs.tck.application; +package org.eclipse.microprofile.telemetry.metrics.tck.application; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/TestUtils.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/TestUtils.java similarity index 94% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/TestUtils.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/TestUtils.java index 181a585e..a9ad10fb 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/TestUtils.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/TestUtils.java @@ -17,7 +17,7 @@ * limitations under the License. * */ -package org.eclipse.microprofile.telemetry.metrics.tck; +package org.eclipse.microprofile.telemetry.metrics.tck.application; import java.util.Map; import java.util.stream.Collectors; 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/application/cdi/AsyncDoubleCounterTest.java similarity index 84% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncDoubleCounterTest.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/cdi/AsyncDoubleCounterTest.java index 74330019..7eee25ff 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/application/cdi/AsyncDoubleCounterTest.java @@ -19,11 +19,11 @@ * * SPDX-License-Identifier: Apache-2.0 **********************************************************************/ -package org.eclipse.microprofile.telemetry.metrics.tck.cdi; +package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi; -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.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; @@ -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/application/cdi/AsyncLongCounterTest.java similarity index 84% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/AsyncLongCounterTest.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/cdi/AsyncLongCounterTest.java index 9d4d6945..a7fef630 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/application/cdi/AsyncLongCounterTest.java @@ -19,11 +19,11 @@ * * SPDX-License-Identifier: Apache-2.0 **********************************************************************/ -package org.eclipse.microprofile.telemetry.metrics.tck.cdi; +package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi; -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.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; @@ -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/application/cdi/DoubleCounterTest.java similarity index 88% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleCounterTest.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/cdi/DoubleCounterTest.java index 2a8750ad..800f83c3 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/application/cdi/DoubleCounterTest.java @@ -19,16 +19,16 @@ * * SPDX-License-Identifier: Apache-2.0 **********************************************************************/ -package org.eclipse.microprofile.telemetry.metrics.tck.cdi; +package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; -import org.eclipse.microprofile.telemetry.metrics.tck.TestUtils; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporterProvider; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestUtils; +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; @@ -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/application/cdi/DoubleGaugeTest.java similarity index 85% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleGaugeTest.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/cdi/DoubleGaugeTest.java index 037b722d..321de4b7 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/application/cdi/DoubleGaugeTest.java @@ -19,11 +19,11 @@ * * SPDX-License-Identifier: Apache-2.0 **********************************************************************/ -package org.eclipse.microprofile.telemetry.metrics.tck.cdi; +package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi; -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.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; @@ -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/application/cdi/DoubleHistogramTest.java similarity index 88% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleHistogramTest.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/cdi/DoubleHistogramTest.java index 95ed8fab..739cd0d4 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/application/cdi/DoubleHistogramTest.java @@ -19,16 +19,16 @@ * * SPDX-License-Identifier: Apache-2.0 **********************************************************************/ -package org.eclipse.microprofile.telemetry.metrics.tck.cdi; +package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; -import org.eclipse.microprofile.telemetry.metrics.tck.TestUtils; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporterProvider; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestUtils; +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; @@ -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/application/cdi/DoubleUpDownCounterTest.java similarity index 88% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/DoubleUpDownCounterTest.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/cdi/DoubleUpDownCounterTest.java index 9a30ad24..15279f78 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/application/cdi/DoubleUpDownCounterTest.java @@ -19,16 +19,16 @@ * * SPDX-License-Identifier: Apache-2.0 **********************************************************************/ -package org.eclipse.microprofile.telemetry.metrics.tck.cdi; +package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; -import org.eclipse.microprofile.telemetry.metrics.tck.TestUtils; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporterProvider; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestUtils; +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; @@ -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/application/cdi/LongCounterTest.java similarity index 88% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongCounterTest.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/cdi/LongCounterTest.java index dbe01822..f77794c9 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/application/cdi/LongCounterTest.java @@ -19,16 +19,16 @@ * * SPDX-License-Identifier: Apache-2.0 **********************************************************************/ -package org.eclipse.microprofile.telemetry.metrics.tck.cdi; +package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; -import org.eclipse.microprofile.telemetry.metrics.tck.TestUtils; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporterProvider; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestUtils; +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; @@ -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/application/cdi/LongGaugeTest.java similarity index 85% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongGaugeTest.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/cdi/LongGaugeTest.java index f6f85380..e9275344 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/application/cdi/LongGaugeTest.java @@ -19,11 +19,11 @@ * * SPDX-License-Identifier: Apache-2.0 **********************************************************************/ -package org.eclipse.microprofile.telemetry.metrics.tck.cdi; +package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi; -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.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; @@ -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/application/cdi/LongHistogramTest.java similarity index 88% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongHistogramTest.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/cdi/LongHistogramTest.java index db00896b..efeb830c 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/application/cdi/LongHistogramTest.java @@ -19,16 +19,16 @@ * * SPDX-License-Identifier: Apache-2.0 **********************************************************************/ -package org.eclipse.microprofile.telemetry.metrics.tck.cdi; +package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; -import org.eclipse.microprofile.telemetry.metrics.tck.TestUtils; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporterProvider; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestUtils; +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; @@ -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/application/cdi/LongUpDownCounterTest.java similarity index 88% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/cdi/LongUpDownCounterTest.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/cdi/LongUpDownCounterTest.java index 85d1d23a..60c038e3 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/application/cdi/LongUpDownCounterTest.java @@ -19,16 +19,16 @@ * * SPDX-License-Identifier: Apache-2.0 **********************************************************************/ -package org.eclipse.microprofile.telemetry.metrics.tck.cdi; +package org.eclipse.microprofile.telemetry.metrics.tck.application.cdi; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.microprofile.telemetry.metrics.tck.TestLibraries; -import org.eclipse.microprofile.telemetry.metrics.tck.TestUtils; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporter; -import org.eclipse.microprofile.telemetry.metrics.tck.exporter.InMemoryMetricExporterProvider; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestLibraries; +import org.eclipse.microprofile.telemetry.metrics.tck.application.TestUtils; +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; @@ -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/application/exporter/InMemoryMetricExporter.java similarity index 84% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/exporter/InMemoryMetricExporter.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/exporter/InMemoryMetricExporter.java index 90b97982..b320f0bb 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/application/exporter/InMemoryMetricExporter.java @@ -18,7 +18,7 @@ * */ -package org.eclipse.microprofile.telemetry.metrics.tck.exporter; +package org.eclipse.microprofile.telemetry.metrics.tck.application.exporter; import static java.util.concurrent.TimeUnit.SECONDS; @@ -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/exporter/InMemoryMetricExporterProvider.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/exporter/InMemoryMetricExporterProvider.java similarity index 94% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/exporter/InMemoryMetricExporterProvider.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/exporter/InMemoryMetricExporterProvider.java index 95e1cf95..bd798d4d 100644 --- a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/exporter/InMemoryMetricExporterProvider.java +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/exporter/InMemoryMetricExporterProvider.java @@ -17,7 +17,7 @@ * limitations under the License. * */ -package org.eclipse.microprofile.telemetry.metrics.tck.exporter; +package org.eclipse.microprofile.telemetry.metrics.tck.application.exporter; import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider; diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/http/HttpHistogramTest.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/http/HttpHistogramTest.java new file mode 100644 index 00000000..cd4b30cc --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/http/HttpHistogramTest.java @@ -0,0 +1,183 @@ +/* + ********************************************************************** + * 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.application.http; + +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.eclipse.microprofile.telemetry.metrics.tck.application.BasicHttpClient; +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.test.api.ArquillianResource; +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.common.AttributeKey; +import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider; +import io.opentelemetry.sdk.metrics.data.MetricData; +import jakarta.inject.Inject; +import jakarta.ws.rs.ApplicationPath; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.core.Application; +import jakarta.ws.rs.core.Response; + +public class HttpHistogramTest extends Arquillian { + + private static final AttributeKey HTTP_REQUEST_METHOD = AttributeKey.stringKey("http.request.method"); + private static final AttributeKey URL_SCHEME = AttributeKey.stringKey("url.scheme"); + private static final AttributeKey HTTP_RESPONSE_STATUS_CODE = + AttributeKey.stringKey("http.response.status_code"); + private static final AttributeKey NETWORK_PROTOCOL_NAME = + AttributeKey.stringKey("network.protocol.name"); + private static final AttributeKey HTTP_ROUTE = AttributeKey.stringKey("http.route"); + private static final AttributeKey ERROR_TYPE = AttributeKey.stringKey("error.type"); + + @Inject + OpenTelemetry openTelemetry; + + @Deployment + public static WebArchive createTestArchive() { + return ShrinkWrap.create(WebArchive.class) + .addClasses(InMemoryMetricExporter.class, InMemoryMetricExporterProvider.class, + BasicHttpClient.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"); + } + + @ArquillianResource + private URL url; + @Inject + private InMemoryMetricExporter metricExporter; + + private BasicHttpClient basicClient; + + @BeforeMethod + void setUp() { + if (metricExporter != null) { + metricExporter.reset(); + basicClient = new BasicHttpClient(url); + } + } + + @Test + void collectsHttpRouteFromEndAttributes() { + + basicClient.get("/fail"); // Ensure we have metrics from both a successful (entering this method) and failing + // HTTP call. + + try { + Thread.sleep(4000); + } catch (InterruptedException e) { + e.printStackTrace(); + Assert.fail("The test thread was interrupted"); + } + + List items = metricExporter.getFinishedMetricItems(); + + Map, String> successfulHTTPMethod = new HashMap, String>(); + successfulHTTPMethod.put(HTTP_REQUEST_METHOD, "GET"); + successfulHTTPMethod.put(URL_SCHEME, "http"); + successfulHTTPMethod.put(HTTP_RESPONSE_STATUS_CODE, "200"); + successfulHTTPMethod.put(NETWORK_PROTOCOL_NAME, "HTTP"); + successfulHTTPMethod.put(HTTP_ROUTE, url.getPath().replaceAll("ArquillianServletRunner.*", "")); + + Map, String> failingHTTPMethod = new HashMap, String>(); + failingHTTPMethod.put(HTTP_REQUEST_METHOD, "GET"); + failingHTTPMethod.put(URL_SCHEME, "http"); + failingHTTPMethod.put(HTTP_RESPONSE_STATUS_CODE, "500"); + failingHTTPMethod.put(NETWORK_PROTOCOL_NAME, "HTTP"); + failingHTTPMethod.put(HTTP_ROUTE, url.getPath() + "fail"); + failingHTTPMethod.put(ERROR_TYPE, "500"); + + testMetricItem(successfulHTTPMethod, items); + testMetricItem(failingHTTPMethod, items); + + } + + private void testMetricItem(Map, String> keyAndExpectedValue, List items) { + + Assert.assertTrue( + items.stream() + .flatMap(md -> md.getHistogramData().getPoints().stream()) + .anyMatch(point -> { + return keyAndExpectedValue.entrySet().stream() + .allMatch(entry -> { + String attribute = point.getAttributes().get(entry.getKey()); + return attribute != null && + (attribute.equals(entry.getValue()) + || entry.getKey().equals(HTTP_ROUTE) && entry.getValue() + .contains(keyAndExpectedValue.get(HTTP_ROUTE)) + // special case for Path to exclude "/ArquillianServletRunnerEE9" + ); + }); + }), + "failed to find a metric with all items in this attribute map: " + dumpTestedMap(keyAndExpectedValue) + + "\n Dumping all attributes: " + + dumpMetricItems(items)); + } + + private String dumpTestedMap(Map, String> keyAndExpectedValue) { + return keyAndExpectedValue.entrySet().stream() + .map(entry -> entry.getKey().toString() + "=" + entry.getValue()) + .collect(Collectors.joining(", ")); + } + + private String dumpMetricItems(List items) { + + return items.stream() + .flatMap(md -> md.getHistogramData().getPoints().stream()) + .map(point -> point.getAttributes().toString()) + .collect(Collectors.joining(", ")); + } + + @Path("/") + public static class SpanResource { + @GET + @Path("/fail") + public Response span() { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + } + + @ApplicationPath("/") + public static class RestApplication extends Application { + + } + +} 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..83120c72 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmClassesTest.java @@ -0,0 +1,70 @@ +/* + ********************************************************************** + * 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 java.io.IOException; + +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.spec.WebArchive; +import org.testng.Assert; +import org.testng.annotations.Test; + +import io.opentelemetry.api.OpenTelemetry; +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(MetricsReader.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + void testClassLoadedMetrics() throws IOException { + Assert.assertTrue( + MetricsReader.checkMessage("jvm.class.loaded", "Number of classes loaded since JVM start.", "{class}", + MetricDataType.LONG_SUM.toString())); + } + + @Test + void testClassUnloadedMetrics() throws IOException { + Assert.assertTrue( + MetricsReader.checkMessage("jvm.class.unloaded", "Number of classes unloaded since JVM start.", + "{class}", MetricDataType.LONG_SUM.toString())); + } + + @Test + void testClassCountMetrics() throws IOException { + Assert.assertTrue(MetricsReader.checkMessage("jvm.class.count", "Number of classes currently loaded.", + "{class}", MetricDataType.LONG_SUM.toString())); + } + +} 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..899372a1 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmCpuTest.java @@ -0,0 +1,71 @@ +/* + ********************************************************************** + * 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 java.io.IOException; + +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.spec.WebArchive; +import org.testng.Assert; +import org.testng.annotations.Test; + +import io.opentelemetry.api.OpenTelemetry; +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(MetricsReader.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + void testCpuTimeMetric() throws IOException { + Assert.assertTrue( + MetricsReader.checkMessage("jvm.cpu.time", "CPU time used by the process as reported by the JVM.", "s", + MetricDataType.LONG_SUM.toString())); + } + + @Test + void testCpuCountMetric() throws IOException { + Assert.assertTrue(MetricsReader.checkMessage("jvm.cpu.count", + "Number of processors available to the Java virtual machine.", "{cpu}", + MetricDataType.LONG_SUM.toString())); + } + + @Test + void testCpuRecentUtilizationMetric() throws IOException { + Assert.assertTrue(MetricsReader.checkMessage("jvm.cpu.recent_utilization", + "Recent CPU utilization for the process as reported by the JVM.", "1", + MetricDataType.LONG_GAUGE.toString())); + } + +} 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..34f54ab3 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmGarbageCollectionTest.java @@ -0,0 +1,57 @@ +/* + ********************************************************************** + * 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 java.io.IOException; + +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.spec.WebArchive; +import org.testng.Assert; +import org.testng.annotations.Test; + +import io.opentelemetry.api.OpenTelemetry; +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(MetricsReader.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + void testGarbageCollectionCountMetric() throws IOException { + Assert.assertTrue( + MetricsReader.checkMessage("jvm.gc.duration", "Duration of JVM garbage collection actions.", "s", + MetricDataType.HISTOGRAM.toString())); + } + +} 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..366c84db --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmMemoryTest.java @@ -0,0 +1,80 @@ +/* + ********************************************************************** + * 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 java.io.IOException; + +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.spec.WebArchive; +import org.testng.Assert; +import org.testng.annotations.Test; + +import io.opentelemetry.api.OpenTelemetry; +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(MetricsReader.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + void testJvmMemoryUsedMetric() throws IOException { + Assert.assertTrue( + MetricsReader.checkMessage("jvm.memory.used", "Measure of memory used.", "By", + MetricDataType.LONG_SUM.toString())); + } + + @Test + void testJvmMemoryCommittedMetric() throws IOException { + Assert.assertTrue( + MetricsReader.checkMessage("jvm.memory.committed", "Measure of memory committed.", "By", + MetricDataType.LONG_SUM.toString())); + } + + @Test + void testMemoryLimitMetric() throws IOException { + Assert.assertTrue( + MetricsReader.checkMessage("jvm.memory.limit", "Measure of max obtainable memory.", "{class}", + MetricDataType.LONG_SUM.toString())); + } + + @Test + void testMemoryUsedAfterLastGcMetric() throws IOException { + Assert.assertTrue( + MetricsReader.checkMessage("jvm.memory.used_after_last_gc", + "Measure of memory used, as measured after the most recent garbage collection event on this pool.", + "By", + MetricDataType.LONG_SUM.toString())); + } + +} 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..63d9ad5a --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmThreadTest.java @@ -0,0 +1,57 @@ +/* + ********************************************************************** + * 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 java.io.IOException; + +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.spec.WebArchive; +import org.testng.Assert; +import org.testng.annotations.Test; + +import io.opentelemetry.api.OpenTelemetry; +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(MetricsReader.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + void testThreadCountMetric() throws IOException { + Assert.assertTrue( + MetricsReader.checkMessage("jvm.thread.count", "Number of executing platform threads.", "{thread}", + MetricDataType.LONG_SUM.toString())); + } + +} diff --git a/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/MetricsReader.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/MetricsReader.java new file mode 100644 index 00000000..253f4ae8 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/MetricsReader.java @@ -0,0 +1,57 @@ +/* + ********************************************************************** + * 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 java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +public class MetricsReader { + + private static final String logFilePath = System.getProperty("log.file.path"); + + public static boolean checkMessage(String metricName, String metricDescription, String metricUnit, + String metricType) + throws IOException { + try { + Thread.sleep(5000); + try { + BufferedReader reader = new BufferedReader(new FileReader(logFilePath)); + String line; + while ((line = reader.readLine()) != null) { + if (line.contains( + "name=" + metricName + ", description=" + metricDescription + ", unit=" + metricUnit + + ", type=" + metricType)) { + + return true; + } + } + return false; + } catch (IOException e) { + return false; + } + } catch (InterruptedException e) { + return false; + } + } + +} From 9bcb08d430adf59c78b7bde812985f6875dac876 Mon Sep 17 00:00:00 2001 From: David Chan Date: Wed, 26 Jun 2024 14:47:49 -0400 Subject: [PATCH 2/5] Update metric type and metric unit for JVM related metrics; Update README to include configuration of export interval --- tck/metrics/README.adoc | 9 +++++++-- .../telemetry/metrics/tck/jvm/JvmCpuTest.java | 4 ++-- .../telemetry/metrics/tck/jvm/JvmMemoryTest.java | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tck/metrics/README.adoc b/tck/metrics/README.adoc index ea2a4e6e..4f22f233 100644 --- a/tck/metrics/README.adoc +++ b/tck/metrics/README.adoc @@ -51,13 +51,18 @@ To enable the tests in your project you need to add the following dependency to == Running the tests -The JVM metrics tests require runtime configuration to enable metric reading at a runtime level. The metrics must be sent to stdout in the tests. Ensure logs written to stdout are captured in a file and set the system property `log.file.path` to the file containing the log output when running the logs TCK. Configure the runtime with `otel.metrics.exporter=console`/`OTEL_METRICS_EXPORTER=CONSOLE` and `otel.sdk.disabled=false`/`OTEL_SDK_DISABLED=FALSE` as a system property or environment variable. For example: +The JVM metrics tests require runtime configuration to enable metric reading at a runtime level. The metrics must be sent to stdout in the tests. Ensure logs written to stdout are captured in a file and set the system property `log.file.path` to the file containing the log output when running the logs TCK. Configure the runtime with `otel.metrics.exporter=logging`/`OTEL_METRICS_EXPORTER=LOGGING` and `otel.sdk.disabled=false`/`OTEL_SDK_DISABLED=FALSE` as a system property or environment variable. +The metric export interval `otel.metric.export.interval`/`OTEL_METRIC_EXPORT_INTERVAL` should be configured as well and it is recommended to be set to a value of `3000` (i.e., 3 seconds). +Note: it is recommended to set `otel.traces.exporter` / `OTEL_TRACES_EXPORTER` and `otel.logs.exporter` / `OTEL_LOGS_EXPORTER` to `none` for the execution of the metric tests. For example: [source, xml] ---- otel.sdk.disabled=false -otel.metrics.exporter=console +otel.metrics.exporter=logging +otel.traces.exporter=none +otel.logs.exporter=none +otel.metric.export.interval=3000 log.file.path=console.log ---- 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 index 899372a1..21378572 100644 --- 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 @@ -51,7 +51,7 @@ public static WebArchive createTestArchive() { void testCpuTimeMetric() throws IOException { Assert.assertTrue( MetricsReader.checkMessage("jvm.cpu.time", "CPU time used by the process as reported by the JVM.", "s", - MetricDataType.LONG_SUM.toString())); + MetricDataType.DOUBLE_SUM.toString())); } @Test @@ -65,7 +65,7 @@ void testCpuCountMetric() throws IOException { void testCpuRecentUtilizationMetric() throws IOException { Assert.assertTrue(MetricsReader.checkMessage("jvm.cpu.recent_utilization", "Recent CPU utilization for the process as reported by the JVM.", "1", - MetricDataType.LONG_GAUGE.toString())); + MetricDataType.DOUBLE_GAUGE.toString())); } } 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 index 366c84db..30e9a6d5 100644 --- 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 @@ -64,7 +64,7 @@ void testJvmMemoryCommittedMetric() throws IOException { @Test void testMemoryLimitMetric() throws IOException { Assert.assertTrue( - MetricsReader.checkMessage("jvm.memory.limit", "Measure of max obtainable memory.", "{class}", + MetricsReader.checkMessage("jvm.memory.limit", "Measure of max obtainable memory.", "By", MetricDataType.LONG_SUM.toString())); } From 8c08a117466e39ce38c5b4cc5e67e8130229be75 Mon Sep 17 00:00:00 2001 From: David Chan Date: Wed, 26 Jun 2024 14:49:52 -0400 Subject: [PATCH 3/5] formatting, wording --- tck/metrics/README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tck/metrics/README.adoc b/tck/metrics/README.adoc index 4f22f233..2917ff81 100644 --- a/tck/metrics/README.adoc +++ b/tck/metrics/README.adoc @@ -53,7 +53,7 @@ To enable the tests in your project you need to add the following dependency to The JVM metrics tests require runtime configuration to enable metric reading at a runtime level. The metrics must be sent to stdout in the tests. Ensure logs written to stdout are captured in a file and set the system property `log.file.path` to the file containing the log output when running the logs TCK. Configure the runtime with `otel.metrics.exporter=logging`/`OTEL_METRICS_EXPORTER=LOGGING` and `otel.sdk.disabled=false`/`OTEL_SDK_DISABLED=FALSE` as a system property or environment variable. The metric export interval `otel.metric.export.interval`/`OTEL_METRIC_EXPORT_INTERVAL` should be configured as well and it is recommended to be set to a value of `3000` (i.e., 3 seconds). -Note: it is recommended to set `otel.traces.exporter` / `OTEL_TRACES_EXPORTER` and `otel.logs.exporter` / `OTEL_LOGS_EXPORTER` to `none` for the execution of the metric tests. For example: + Note: it is recommended to set `otel.traces.exporter` / `OTEL_TRACES_EXPORTER` and `otel.logs.exporter` / `OTEL_LOGS_EXPORTER` to `none`. For example: [source, xml] From 5fca9c6ae1ea8770d1509cba61c39855a30dd21a Mon Sep 17 00:00:00 2001 From: David Chan Date: Wed, 26 Jun 2024 15:35:48 -0400 Subject: [PATCH 4/5] Use review suggestion --- tck/metrics/README.adoc | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/tck/metrics/README.adoc b/tck/metrics/README.adoc index 2917ff81..58ead279 100644 --- a/tck/metrics/README.adoc +++ b/tck/metrics/README.adoc @@ -51,20 +51,13 @@ To enable the tests in your project you need to add the following dependency to == Running the tests -The JVM metrics tests require runtime configuration to enable metric reading at a runtime level. The metrics must be sent to stdout in the tests. Ensure logs written to stdout are captured in a file and set the system property `log.file.path` to the file containing the log output when running the logs TCK. Configure the runtime with `otel.metrics.exporter=logging`/`OTEL_METRICS_EXPORTER=LOGGING` and `otel.sdk.disabled=false`/`OTEL_SDK_DISABLED=FALSE` as a system property or environment variable. -The metric export interval `otel.metric.export.interval`/`OTEL_METRIC_EXPORT_INTERVAL` should be configured as well and it is recommended to be set to a value of `3000` (i.e., 3 seconds). - Note: it is recommended to set `otel.traces.exporter` / `OTEL_TRACES_EXPORTER` and `otel.logs.exporter` / `OTEL_LOGS_EXPORTER` to `none`. For example: +The JVM metrics tests require runtime configuration to enable metric reading at a runtime level. The metrics must be sent to stdout in the tests. Ensure logs written to stdout are captured in a file and set the system property `log.file.path` to the file containing the log output when running the logs TCK. Configure the runtime with the following as system properties / environment variables: - -[source, xml] ----- -otel.sdk.disabled=false -otel.metrics.exporter=logging -otel.traces.exporter=none -otel.logs.exporter=none -otel.metric.export.interval=3000 -log.file.path=console.log ----- + * otel.sdk.disabled=false/OTEL_SDK_DISABLED=FALSE + * otel.metrics.exporter=logging/OTEL_METRICS_EXPORTER=LOGGING + * otel.traces.exporter=none/OTEL_TRACES_EXPORTER=none + * otel.logs.exporter=none/OTEL_LOGS_EXPORTER=none + * otel.metric.export.interval=3000/OTEL_METRIC_EXPORT_INTERVAL=3000 To run the JVM metrics tests, include the following content in the `tck-suite.xml` in your project: From 9358ac6db699442f51eb3be4a82e00c43da5f206 Mon Sep 17 00:00:00 2001 From: David Chan Date: Wed, 26 Jun 2024 15:38:54 -0400 Subject: [PATCH 5/5] code syntax --- tck/metrics/README.adoc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tck/metrics/README.adoc b/tck/metrics/README.adoc index 58ead279..3fdd0054 100644 --- a/tck/metrics/README.adoc +++ b/tck/metrics/README.adoc @@ -53,11 +53,11 @@ To enable the tests in your project you need to add the following dependency to The JVM metrics tests require runtime configuration to enable metric reading at a runtime level. The metrics must be sent to stdout in the tests. Ensure logs written to stdout are captured in a file and set the system property `log.file.path` to the file containing the log output when running the logs TCK. Configure the runtime with the following as system properties / environment variables: - * otel.sdk.disabled=false/OTEL_SDK_DISABLED=FALSE - * otel.metrics.exporter=logging/OTEL_METRICS_EXPORTER=LOGGING - * otel.traces.exporter=none/OTEL_TRACES_EXPORTER=none - * otel.logs.exporter=none/OTEL_LOGS_EXPORTER=none - * otel.metric.export.interval=3000/OTEL_METRIC_EXPORT_INTERVAL=3000 + * `otel.sdk.disabled=false`/`OTEL_SDK_DISABLED=FALSE` + * `otel.metrics.exporter=logging`/`OTEL_METRICS_EXPORTER=LOGGING` + * `otel.traces.exporter=none`/`OTEL_TRACES_EXPORTER=none` + * `otel.logs.exporter=none`/`OTEL_LOGS_EXPORTER=none` + * `otel.metric.export.interval=3000`/`OTEL_METRIC_EXPORT_INTERVAL=3000` To run the JVM metrics tests, include the following content in the `tck-suite.xml` in your project: