Skip to content

Commit

Permalink
Add logs TCK
Browse files Browse the repository at this point in the history
Update logs TCK

Update logs tck to remove in-memory exporter

Add jvm metrics to TCK

TCK updates

Rename logs tck test
  • Loading branch information
yasmin-aumeeruddy committed Jun 17, 2024
1 parent fe9d7c5 commit 24ba3b1
Show file tree
Hide file tree
Showing 19 changed files with 565 additions and 65 deletions.
7 changes: 7 additions & 0 deletions tck/logs/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ If you want to run the logs tests, you can specify all tests in the `tck-suite.x
</suite>
----

== Logging File Configuration
OpenTelemetry logs are sent to stdout in the tests. 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`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.eclipse.microprofile.telemetry.logs.tck.TestLibraries;
Expand All @@ -29,12 +33,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)
Expand All @@ -50,13 +56,43 @@ 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 {
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;
}
}
}
11 changes: 0 additions & 11 deletions tck/logs/src/main/resources/logback.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import jakarta.inject.Inject;

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

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

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

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

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

public class AsyncLongCounterTest extends Arquillian {

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

Expand All @@ -58,7 +58,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.logs.exporter=none\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
Expand Down Expand Up @@ -87,9 +87,9 @@ void testAsyncLongCounter() throws InterruptedException {
measurement.record(1, Attributes.empty());
}));

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.logs.exporter=none\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
Expand Down Expand Up @@ -99,10 +99,10 @@ void testDoubleCounter() throws InterruptedException {

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

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

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.logs.exporter=none\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
Expand Down Expand Up @@ -83,8 +83,8 @@ void testDoubleGauge() throws InterruptedException {
measurement.record(1, Attributes.empty());
}));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.logs.exporter=none\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
Expand Down Expand Up @@ -98,10 +98,10 @@ void testDoubleHistogram() throws InterruptedException {

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

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

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static WebArchive createTestArchive() {
.addAsLibrary(TestLibraries.AWAITILITY_LIB)
.addAsServiceProvider(ConfigurableMetricExporterProvider.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"otel.sdk.disabled=false\notel.metrics.exporter=in-memory\notel.logs.exporter=none\notel.traces.exporter=none\notel.metric.export.interval=3000"),
"META-INF/microprofile-config.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
Expand Down Expand Up @@ -99,11 +99,10 @@ void testLongHistogram() throws InterruptedException {

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

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

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

List<MetricData> metrics = metricExporter.getMetricData((MetricDataType.LONG_SUM));
List<MetricData> metrics = metricExporter.getMetricData((counterName));
metrics.stream()
.peek(metricData -> {
Assert.assertEquals(metricData.getName(), counterName);
Assert.assertEquals(metricData.getType(), MetricDataType.LONG_SUM);
Assert.assertEquals(metricData.getDescription(), counterDescription);
Assert.assertEquals(metricData.getUnit(), counterUnit);
})
Expand Down
Loading

0 comments on commit 24ba3b1

Please sign in to comment.