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..53575876 100644 --- a/tck/logs/pom.xml +++ b/tck/logs/pom.xml @@ -58,24 +58,6 @@ 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..8c447831 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,12 +32,14 @@ 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) @@ -49,13 +55,48 @@ 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"; + + private static final String SYS_OUT = "SystemOut"; + @Test - void julTest() throws InterruptedException { + void julInfoTest() throws IOException { + julLogger.log(Level.INFO, JUL_INFO_MESSAGE); + try { + Assert.assertTrue(checkMessage(SYS_OUT + ".*" + "INFO" + ".*" + JUL_INFO_MESSAGE)); + } catch (IOException e) { + } + } + + @Test + void julWarnTest() throws IOException { + julLogger.log(Level.WARNING, JUL_INFO_MESSAGE); + try { + Assert.assertTrue(checkMessage(SYS_OUT + ".*" + "WARN" + ".*" + JUL_INFO_MESSAGE)); + } 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.contains(logMessage)) { + return true; + } + } + return false; + } catch (IOException e) { + return false; + } + } catch (InterruptedException e) { + return false; + } } } 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..d680a747 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/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/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/TestLibraries.java b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/TestLibraries.java new file mode 100644 index 00000000..6c031499 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/application/TestLibraries.java @@ -0,0 +1,32 @@ +/* + * 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.application; + +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/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..0abb609a --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmClassesTest.java @@ -0,0 +1,75 @@ +/* + ********************************************************************** + * 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.asset.StringAsset; +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) + .addAsLibrary(TestLibraries.AWAITILITY_LIB) + .addAsResource(new StringAsset( + "otel.sdk.disabled=false\notel.logs.exporter=none\notel.traces.exporter=none"), + "META-INF/microprofile-config.properties") + .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..bf883a96 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmCpuTest.java @@ -0,0 +1,76 @@ +/* + ********************************************************************** + * 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.asset.StringAsset; +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) + .addAsLibrary(TestLibraries.AWAITILITY_LIB) + .addAsResource(new StringAsset( + "otel.sdk.disabled=false\notel.logs.exporter=none\notel.traces.exporter=none"), + "META-INF/microprofile-config.properties") + .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..9c6c5e24 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmGarbageCollectionTest.java @@ -0,0 +1,62 @@ +/* + ********************************************************************** + * 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.asset.StringAsset; +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) + .addAsLibrary(TestLibraries.AWAITILITY_LIB) + .addAsResource(new StringAsset( + "otel.sdk.disabled=false\notel.logs.exporter=none\notel.traces.exporter=none"), + "META-INF/microprofile-config.properties") + .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..9c0da4da --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmMemoryTest.java @@ -0,0 +1,85 @@ +/* + ********************************************************************** + * 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.asset.StringAsset; +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) + .addAsLibrary(TestLibraries.AWAITILITY_LIB) + .addAsResource(new StringAsset( + "otel.sdk.disabled=false\notel.logs.exporter=none\notel.traces.exporter=none"), + "META-INF/microprofile-config.properties") + .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..be9f7b51 --- /dev/null +++ b/tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/JvmThreadTest.java @@ -0,0 +1,62 @@ +/* + ********************************************************************** + * 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.asset.StringAsset; +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) + .addAsLibrary(TestLibraries.AWAITILITY_LIB) + .addAsResource(new StringAsset( + "otel.sdk.disabled=false\notel.logs.exporter=none\notel.traces.exporter=none"), + "META-INF/microprofile-config.properties") + .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; + } + } + +} 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/jvm/TestLibraries.java similarity index 94% rename from tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/TestLibraries.java rename to tck/metrics/src/main/java/org/eclipse/microprofile/telemetry/metrics/tck/jvm/TestLibraries.java index 86bf368d..53f0d50d 100644 --- 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/jvm/TestLibraries.java @@ -17,7 +17,7 @@ * limitations under the License. * */ -package org.eclipse.microprofile.telemetry.metrics.tck; +package org.eclipse.microprofile.telemetry.metrics.tck.jvm; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive;