Update to OTel 1.14 (#5999)

* Update to OTel 1.14

* Fix test

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
This commit is contained in:
Anuraag Agrawal 2022-05-11 06:23:56 +09:00 committed by GitHub
parent 25d929b5e7
commit d1ee692479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 1065 additions and 1037 deletions

View File

@ -11,7 +11,7 @@ data class DependencySet(val group: String, val version: String, val modules: Li
val dependencyVersions = hashMapOf<String, String>()
rootProject.extra["versions"] = dependencyVersions
val otelVersion = "1.13.0"
val otelVersion = "1.14.0"
rootProject.extra["otelVersion"] = otelVersion
// Need both BOM and groovy jars

View File

@ -5,8 +5,8 @@
package io.opentelemetry.instrumentation.api.instrumenter.http;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
@ -17,6 +17,7 @@ import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
@ -70,42 +71,40 @@ class HttpClientMetricsTest {
listener.onEnd(context1, responseAttributes, nanos(250));
assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.client.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
attributeEntry("net.peer.name", "localhost"),
attributeEntry("net.peer.port", 1234),
attributeEntry("http.method", "GET"),
attributeEntry("http.flavor", "2.0"),
attributeEntry("http.status_code", 200));
assertThat(point).exemplars().hasSize(1);
assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(SemanticAttributes.NET_PEER_PORT, 1234),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));
listener.onEnd(context2, responseAttributes, nanos(300));
assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.client.duration")
.hasDoubleHistogram()
.points()
.satisfiesExactly(point -> assertThat(point).hasSum(300 /* millis */)));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point -> point.hasSum(300 /* millis */))));
}
private static long nanos(int millis) {

View File

@ -5,8 +5,8 @@
package io.opentelemetry.instrumentation.api.instrumenter.http;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
@ -17,6 +17,7 @@ import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
@ -60,96 +61,86 @@ class HttpServerMetricsTest {
Context context1 = listener.onStart(parent, requestAttributes, nanos(100));
assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasDescription(
"The number of concurrent HTTP requests that are currently in-flight")
.hasUnit("requests")
.hasLongSum()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasValue(1)
.attributes()
.containsOnly(
attributeEntry("http.host", "host"),
attributeEntry("http.method", "GET"),
attributeEntry("http.scheme", "https"));
assertThat(point).exemplars().hasSize(1);
assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
.hasLongSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_HOST, "host"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_SCHEME, "https"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));
Context context2 = listener.onStart(Context.root(), requestAttributes, nanos(150));
assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSum()
.points()
.satisfiesExactly(point -> assertThat(point).hasValue(2)));
.hasLongSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(2))));
listener.onEnd(context1, responseAttributes, nanos(250));
assertThat(metricReader.collectAllMetrics())
.hasSize(2)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSum()
.points()
.satisfiesExactly(point -> assertThat(point).hasValue(1)))
.anySatisfy(
.hasLongSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(1))),
metric ->
assertThat(metric)
.hasName("http.server.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
attributeEntry("http.scheme", "https"),
attributeEntry("http.host", "host"),
attributeEntry("http.method", "GET"),
attributeEntry("http.status_code", 200),
attributeEntry("http.flavor", "2.0"));
assertThat(point).exemplars().hasSize(1);
assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
equalTo(SemanticAttributes.HTTP_HOST, "host"),
equalTo(SemanticAttributes.HTTP_METHOD, "GET"),
equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200),
equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));
listener.onEnd(context2, responseAttributes, nanos(300));
assertThat(metricReader.collectAllMetrics())
.hasSize(2)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.server.active_requests")
.hasLongSum()
.points()
.satisfiesExactly(point -> assertThat(point).hasValue(0)))
.anySatisfy(
.hasLongSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(0))),
metric ->
assertThat(metric)
.hasName("http.server.duration")
.hasDoubleHistogram()
.points()
.satisfiesExactly(point -> assertThat(point).hasSum(300 /* millis */)));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point -> point.hasSum(300 /* millis */))));
}
@Test
@ -179,17 +170,17 @@ class HttpServerMetricsTest {
assertThat(metric)
.hasName("http.server.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(100 /* millis */)
.attributes()
.containsOnly(
attributeEntry("http.scheme", "https"),
attributeEntry("http.host", "host"),
attributeEntry("http.route", "/test/{id}"))));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(100 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.HTTP_SCHEME, "https"),
equalTo(SemanticAttributes.HTTP_HOST, "host"),
equalTo(
SemanticAttributes.HTTP_ROUTE, "/test/{id}")))));
}
private static long nanos(int millis) {

View File

@ -5,8 +5,8 @@
package io.opentelemetry.instrumentation.api.instrumenter.rpc;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
@ -74,56 +74,56 @@ class RpcClientMetricsTest {
listener.onEnd(context1, responseAttributes1, nanos(250));
assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("rpc.client.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
attributeEntry("rpc.system", "grpc"),
attributeEntry("rpc.service", "myservice.EchoService"),
attributeEntry("rpc.method", "exampleMethod"),
attributeEntry("net.peer.name", "example.com"),
attributeEntry("net.peer.port", 8080),
attributeEntry("net.transport", "ip_tcp"));
assertThat(point).exemplars().hasSize(1);
assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"myservice.EchoService"),
equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"),
equalTo(
SemanticAttributes.NET_PEER_NAME, "example.com"),
equalTo(SemanticAttributes.NET_PEER_PORT, 8080),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));
listener.onEnd(context2, responseAttributes2, nanos(300));
assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("rpc.client.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
attributeEntry("rpc.system", "grpc"),
attributeEntry("rpc.service", "myservice.EchoService"),
attributeEntry("rpc.method", "exampleMethod"),
attributeEntry("net.peer.ip", "127.0.0.1"),
attributeEntry("net.peer.port", 8080),
attributeEntry("net.transport", "ip_tcp"));
}));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"myservice.EchoService"),
equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"),
equalTo(SemanticAttributes.NET_PEER_IP, "127.0.0.1"),
equalTo(SemanticAttributes.NET_PEER_PORT, 8080),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp")))));
}
private static long nanos(int millis) {

View File

@ -5,8 +5,8 @@
package io.opentelemetry.instrumentation.api.instrumenter.rpc;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
@ -74,54 +74,54 @@ class RpcServerMetricsTest {
listener.onEnd(context1, responseAttributes1, nanos(250));
assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("rpc.server.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
attributeEntry("rpc.system", "grpc"),
attributeEntry("rpc.service", "myservice.EchoService"),
attributeEntry("rpc.method", "exampleMethod"),
attributeEntry("net.host.name", "example.com"),
attributeEntry("net.transport", "ip_tcp"));
assertThat(point).exemplars().hasSize(1);
assertThat(point.getExemplars().get(0))
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00");
}));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"myservice.EchoService"),
equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"),
equalTo(
SemanticAttributes.NET_HOST_NAME, "example.com"),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"))
.hasExemplarsSatisfying(
exemplar ->
exemplar
.hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
.hasSpanId("090a0b0c0d0e0f00")))));
listener.onEnd(context2, responseAttributes2, nanos(300));
assertThat(metricReader.collectAllMetrics())
.hasSize(1)
.anySatisfy(
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("rpc.server.duration")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.hasSum(150 /* millis */)
.attributes()
.containsOnly(
attributeEntry("rpc.system", "grpc"),
attributeEntry("rpc.service", "myservice.EchoService"),
attributeEntry("rpc.method", "exampleMethod"),
attributeEntry("net.host.ip", "127.0.0.1"),
attributeEntry("net.transport", "ip_tcp"));
}));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(150 /* millis */)
.hasAttributesSatisfying(
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"myservice.EchoService"),
equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"),
equalTo(SemanticAttributes.NET_HOST_IP, "127.0.0.1"),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp")))));
}
private static long nanos(int millis) {

View File

@ -18,12 +18,10 @@ import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.Status;
import io.grpc.stub.StreamObserver;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.util.ThrowingRunnable;
import io.opentelemetry.sdk.testing.assertj.EventDataAssert;
import io.opentelemetry.sdk.testing.assertj.MetricAssertions;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.ArrayList;
import java.util.List;
@ -223,22 +221,20 @@ public abstract class AbstractGrpcStreamingTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.anySatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "Conversation")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(
SemanticAttributes.RPC_METHOD, "Conversation"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@ -246,26 +242,25 @@ public abstract class AbstractGrpcStreamingTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.allSatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_PEER_NAME, "localhost")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(
SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(
SemanticAttributes.NET_PEER_PORT,
server.getPort())
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "Conversation")
.put(
server.getPort()),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(
SemanticAttributes.RPC_METHOD, "Conversation"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
}
private ManagedChannel createChannel(Server server) throws Exception {

View File

@ -40,12 +40,10 @@ import io.grpc.reflection.v1alpha.ServerReflectionGrpc;
import io.grpc.reflection.v1alpha.ServerReflectionRequest;
import io.grpc.reflection.v1alpha.ServerReflectionResponse;
import io.grpc.stub.StreamObserver;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.util.ThrowingRunnable;
import io.opentelemetry.sdk.testing.assertj.MetricAssertions;
import io.opentelemetry.sdk.trace.data.StatusData;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.Queue;
@ -214,22 +212,19 @@ public abstract class AbstractGrpcTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.anySatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "SayHello")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@ -237,26 +232,24 @@ public abstract class AbstractGrpcTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.allSatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_PEER_NAME, "localhost")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(
SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(
SemanticAttributes.NET_PEER_PORT,
server.getPort())
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "SayHello")
.put(
server.getPort()),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
}
@Test
@ -408,22 +401,19 @@ public abstract class AbstractGrpcTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.anySatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "SayHello")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@ -431,26 +421,24 @@ public abstract class AbstractGrpcTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.allSatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_PEER_NAME, "localhost")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(
SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(
SemanticAttributes.NET_PEER_PORT,
server.getPort())
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "SayHello")
.put(
server.getPort()),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
}
@Test
@ -610,22 +598,19 @@ public abstract class AbstractGrpcTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.anySatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "SayHello")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@ -633,26 +618,24 @@ public abstract class AbstractGrpcTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.allSatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_PEER_NAME, "localhost")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(
SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(
SemanticAttributes.NET_PEER_PORT,
server.getPort())
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "SayHello")
.put(
server.getPort()),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
}
@ParameterizedTest
@ -769,22 +752,19 @@ public abstract class AbstractGrpcTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.anySatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "SayHello")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@ -792,26 +772,24 @@ public abstract class AbstractGrpcTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.allSatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_PEER_NAME, "localhost")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(
SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(
SemanticAttributes.NET_PEER_PORT,
server.getPort())
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "SayHello")
.put(
server.getPort()),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
}
@ParameterizedTest
@ -926,22 +904,19 @@ public abstract class AbstractGrpcTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.anySatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "SayHello")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@ -949,26 +924,24 @@ public abstract class AbstractGrpcTest {
metrics ->
metrics.anySatisfy(
metric ->
MetricAssertions.assertThat(metric)
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.allSatisfy(
point ->
MetricAssertions.assertThat(point)
.hasAttributes(
Attributes.builder()
.put(SemanticAttributes.NET_PEER_NAME, "localhost")
.put(
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(
SemanticAttributes.NET_PEER_NAME, "localhost"),
equalTo(
SemanticAttributes.NET_PEER_PORT,
server.getPort())
.put(SemanticAttributes.NET_TRANSPORT, "ip_tcp")
.put(SemanticAttributes.RPC_METHOD, "SayHello")
.put(
server.getPort()),
equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp"),
equalTo(SemanticAttributes.RPC_METHOD, "SayHello"),
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter")
.put(SemanticAttributes.RPC_SYSTEM, "grpc")
.build()))));
"example.Greeter"),
equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
}
static class ErrorProvider implements ArgumentsProvider {

View File

@ -5,20 +5,22 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Metrics;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import org.assertj.core.api.AbstractIterableAssert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
class CounterTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -29,7 +31,7 @@ class CounterTest {
}
@Test
void testCounter() {
void testCounter() throws Exception {
// given
Counter counter =
Counter.builder("testCounter")
@ -52,15 +54,17 @@ class CounterTest {
assertThat(metric)
.hasDescription("This is a test counter")
.hasUnit("items")
.hasDoubleSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(3)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(3)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.clearData();
// when
@ -68,15 +72,8 @@ class CounterTest {
counter.increment();
// then
Thread.sleep(100); // interval of the test metrics exporter
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testCounter",
metrics ->
metrics.allSatisfy(
metric ->
assertThat(metric)
.hasDoubleSum()
.points()
.noneSatisfy(point -> assertThat(point).hasValue(4))));
INSTRUMENTATION_NAME, "testCounter", AbstractIterableAssert::isEmpty);
}
}

View File

@ -5,11 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.DistributionSummary;
import io.micrometer.core.instrument.Metrics;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import org.assertj.core.api.AbstractIterableAssert;
@ -19,7 +20,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
class DistributionSummaryTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -30,7 +31,7 @@ class DistributionSummaryTest {
}
@Test
void testDistributionSummary() {
void testDistributionSummary() throws Exception {
// given
DistributionSummary summary =
DistributionSummary.builder("testSummary")
@ -53,15 +54,16 @@ class DistributionSummaryTest {
assertThat(metric)
.hasDescription("This is a test distribution summary")
.hasUnit("things")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(42)
.hasCount(1)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(42)
.hasCount(1)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.clearData();
// when
@ -69,16 +71,9 @@ class DistributionSummaryTest {
summary.record(6);
// then
Thread.sleep(100); // interval of the test metrics exporter
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testSummary",
metrics ->
metrics.allSatisfy(
metric ->
assertThat(metric)
.hasDoubleHistogram()
.points()
.noneSatisfy(point -> assertThat(point).hasSum(54).hasCount(2))));
INSTRUMENTATION_NAME, "testSummary", AbstractIterableAssert::isEmpty);
}
@Test
@ -107,29 +102,33 @@ class DistributionSummaryTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasDoubleGauge()
.points()
.anySatisfy(
point ->
assertThat(point).hasValue(1).attributes().containsEntry("le", "1"))
.anySatisfy(
point ->
assertThat(point)
.hasValue(2)
.attributes()
.containsEntry("le", "10"))
.anySatisfy(
point ->
assertThat(point)
.hasValue(3)
.attributes()
.containsEntry("le", "100"))
.anySatisfy(
point ->
assertThat(point)
.hasValue(4)
.attributes()
.containsEntry("le", "1000"))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("le"), "1")),
point ->
point
.hasValue(2)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("le"), "10")),
point ->
point
.hasValue(3)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("le"), "100")),
point ->
point
.hasValue(4)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("le"), "1000"))))));
}
@Test
@ -155,14 +154,21 @@ class DistributionSummaryTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasDoubleGauge()
.points()
.anySatisfy(
point -> assertThat(point).attributes().containsEntry("phi", "0.5"))
.anySatisfy(
point -> assertThat(point).attributes().containsEntry("phi", "0.95"))
.anySatisfy(
point -> assertThat(point).attributes().containsEntry("phi", "0.99"))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("phi"), "0.5")),
point ->
point.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("phi"), "0.95")),
point ->
point.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("phi"), "0.99"))))));
}
@Test
@ -189,14 +195,15 @@ class DistributionSummaryTest {
metric ->
assertThat(metric)
.hasDescription("This is a test distribution summary")
.hasDoubleGauge()
.points()
.anySatisfy(
point ->
assertThat(point)
.hasValue(4)
.attributes()
.containsEntry("tag", "value"))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(4)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
// when
Metrics.globalRegistry.remove(summary);

View File

@ -5,11 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.FunctionCounter;
import io.micrometer.core.instrument.Metrics;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.concurrent.atomic.AtomicLong;
@ -20,7 +21,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
class FunctionCounterTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -53,15 +54,17 @@ class FunctionCounterTest {
assertThat(metric)
.hasDescription("This is a test function counter")
.hasUnit("items")
.hasDoubleSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(12)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
// when
Metrics.globalRegistry.remove(counter);
@ -98,20 +101,20 @@ class FunctionCounterTest {
assertThat(metric)
.hasDescription("This is a test function counter")
.hasUnit("items")
.hasDoubleSum()
.isMonotonic()
.points()
.anySatisfy(
point ->
assertThat(point)
.hasValue(12)
.attributes()
.containsOnly(attributeEntry("tag", "1")))
.anySatisfy(
point ->
assertThat(point)
.hasValue(13)
.attributes()
.containsOnly(attributeEntry("tag", "2")))));
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(12)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "1")),
point ->
point
.hasValue(13)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "2"))))));
}
}

View File

@ -5,11 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.FunctionTimer;
import io.micrometer.core.instrument.Metrics;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.concurrent.TimeUnit;
@ -20,7 +21,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
class FunctionTimerSecondsTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -60,15 +61,17 @@ class FunctionTimerSecondsTest {
assertThat(metric)
.hasDescription("This is a test function timer")
.hasUnit("1")
.hasLongSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(1)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasLongSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testFunctionTimerSeconds.sum",
@ -78,14 +81,15 @@ class FunctionTimerSecondsTest {
assertThat(metric)
.hasDescription("This is a test function timer")
.hasUnit("s")
.hasDoubleSum()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(42)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(42)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
// when
Metrics.globalRegistry.remove(functionTimer);

View File

@ -5,11 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.FunctionTimer;
import io.micrometer.core.instrument.Metrics;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.concurrent.TimeUnit;
@ -20,7 +21,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
class FunctionTimerTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -62,15 +63,17 @@ class FunctionTimerTest {
assertThat(metric)
.hasDescription("This is a test function timer")
.hasUnit("1")
.hasLongSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(1)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasLongSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testFunctionTimer.sum",
@ -80,14 +83,15 @@ class FunctionTimerTest {
assertThat(metric)
.hasDescription("This is a test function timer")
.hasUnit("ms")
.hasDoubleSum()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(42_000)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(42_000)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
// when
Metrics.globalRegistry.remove(functionTimer);
@ -125,10 +129,8 @@ class FunctionTimerTest {
metric ->
assertThat(metric)
.hasUnit("ms")
.hasDoubleSum()
.points()
.satisfiesExactly(
point -> assertThat(point).hasValue(1.234).attributes())));
.hasDoubleSumSatisfying(
sum -> sum.hasPointsSatisfying(point -> point.hasValue(1.234)))));
}
@Test
@ -165,19 +167,18 @@ class FunctionTimerTest {
metric ->
assertThat(metric)
.hasUnit("ms")
.hasDoubleSum()
.points()
.anySatisfy(
point ->
assertThat(point)
.hasValue(12_000)
.attributes()
.containsOnly(attributeEntry("tag", "1")))
.anySatisfy(
point ->
assertThat(point)
.hasValue(42_000)
.attributes()
.containsOnly(attributeEntry("tag", "2")))));
.hasDoubleSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(12_000)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "1")),
point ->
point
.hasValue(42_000)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "2"))))));
}
}

View File

@ -5,11 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.Metrics;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.test.utils.GcUtils;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
@ -22,7 +23,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
class GaugeTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -52,14 +53,15 @@ class GaugeTest {
assertThat(metric)
.hasDescription("This is a test gauge")
.hasUnit("items")
.hasDoubleGauge()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(42)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleGaugeSatisfying(
g ->
g.hasPointsSatisfying(
point ->
point
.hasValue(42)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
// when
Metrics.globalRegistry.remove(gauge);
@ -96,20 +98,19 @@ class GaugeTest {
assertThat(metric)
.hasDescription("This is a test gauge")
.hasUnit("items")
.hasDoubleGauge()
.points()
.anySatisfy(
point ->
assertThat(point)
.hasValue(12)
.attributes()
.containsOnly(attributeEntry("tag", "1")))
.anySatisfy(
point ->
assertThat(point)
.hasValue(42)
.attributes()
.containsOnly(attributeEntry("tag", "2")))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(12)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "1")),
point ->
point
.hasValue(42)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "2"))))));
}
@Test
@ -128,9 +129,8 @@ class GaugeTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasDoubleGauge()
.points()
.satisfiesExactly(point -> assertThat(point).hasValue(42))));
.hasDoubleGaugeSatisfying(
gauge -> gauge.hasPointsSatisfying(point -> point.hasValue(42)))));
// when
WeakReference<AtomicLong> numWeakRef = new WeakReference<>(num);

View File

@ -5,11 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.LongTaskTimer;
import io.micrometer.core.instrument.Metrics;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.concurrent.TimeUnit;
@ -20,7 +21,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
class LongTaskTimerSecondsTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -52,15 +53,17 @@ class LongTaskTimerSecondsTest {
assertThat(metric)
.hasDescription("This is a test long task timer")
.hasUnit("tasks")
.hasLongSum()
.isNotMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(1)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testLongTaskTimerSeconds.duration",
@ -70,17 +73,18 @@ class LongTaskTimerSecondsTest {
assertThat(metric)
.hasDescription("This is a test long task timer")
.hasUnit("s")
.hasDoubleSum()
.isNotMonotonic()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.attributes()
.containsOnly(attributeEntry("tag", "value"));
// any value >0 - duration of currently running tasks
assertThat(point.getValue()).isPositive();
})));
.hasDoubleSumSatisfying(
sum ->
sum.isNotMonotonic()
.hasPointsSatisfying(
point -> {
point.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"));
// any value >0 - duration of currently running tasks
assertThat(metric.getDoubleSumData().getPoints())
.satisfiesExactly(
p -> assertThat(p.getValue()).isPositive());
}))));
// when
TimeUnit.MILLISECONDS.sleep(100);
@ -94,14 +98,15 @@ class LongTaskTimerSecondsTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasLongSum()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(0)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasLongSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(0)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testLongTaskTimerSeconds.duration",
@ -109,14 +114,15 @@ class LongTaskTimerSecondsTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasDoubleSum()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(0)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(0)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
// when timer is removed from the registry
Metrics.globalRegistry.remove(timer);

View File

@ -5,11 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.LongTaskTimer;
import io.micrometer.core.instrument.Metrics;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.concurrent.TimeUnit;
@ -20,7 +21,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
class LongTaskTimerTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -52,15 +53,17 @@ class LongTaskTimerTest {
assertThat(metric)
.hasDescription("This is a test long task timer")
.hasUnit("tasks")
.hasLongSum()
.isNotMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(1)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testLongTaskTimer.duration",
@ -70,17 +73,18 @@ class LongTaskTimerTest {
assertThat(metric)
.hasDescription("This is a test long task timer")
.hasUnit("ms")
.hasDoubleSum()
.isNotMonotonic()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.attributes()
.containsOnly(attributeEntry("tag", "value"));
// any value >0 - duration of currently running tasks
assertThat(point.getValue()).isPositive();
})));
.hasDoubleSumSatisfying(
sum ->
sum.isNotMonotonic()
.hasPointsSatisfying(
point -> {
point.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"));
// any value >0 - duration of currently running tasks
assertThat(metric.getDoubleSumData().getPoints())
.satisfiesExactly(
p -> assertThat(p.getValue()).isPositive());
}))));
// when
TimeUnit.MILLISECONDS.sleep(100);
@ -94,14 +98,15 @@ class LongTaskTimerTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasLongSum()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(0)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasLongSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(0)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testLongTaskTimer.duration",
@ -109,14 +114,15 @@ class LongTaskTimerTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasDoubleSum()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(0)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(0)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
// when timer is removed from the registry
Metrics.globalRegistry.remove(timer);

View File

@ -5,13 +5,14 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.Measurement;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Statistic;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.Arrays;
@ -24,7 +25,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
class MeterTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -68,15 +69,17 @@ class MeterTest {
assertThat(metric)
.hasDescription("This is a test meter")
.hasUnit("things")
.hasDoubleSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12345)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(12345)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testMeter.total_time",
@ -86,15 +89,17 @@ class MeterTest {
assertThat(metric)
.hasDescription("This is a test meter")
.hasUnit("things")
.hasDoubleSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12345)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(12345)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testMeter.count",
@ -104,15 +109,17 @@ class MeterTest {
assertThat(metric)
.hasDescription("This is a test meter")
.hasUnit("things")
.hasDoubleSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12345)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(12345)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testMeter.active",
@ -122,15 +129,17 @@ class MeterTest {
assertThat(metric)
.hasDescription("This is a test meter")
.hasUnit("things")
.hasDoubleSum()
.isNotMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12345)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.isNotMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(12345)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testMeter.duration",
@ -140,14 +149,15 @@ class MeterTest {
assertThat(metric)
.hasDescription("This is a test meter")
.hasUnit("things")
.hasDoubleGauge()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12345)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(12345)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testMeter.max",
@ -157,14 +167,15 @@ class MeterTest {
assertThat(metric)
.hasDescription("This is a test meter")
.hasUnit("things")
.hasDoubleGauge()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12345)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(12345)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testMeter.value",
@ -174,14 +185,15 @@ class MeterTest {
assertThat(metric)
.hasDescription("This is a test meter")
.hasUnit("things")
.hasDoubleGauge()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12345)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(12345)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testMeter.unknown",
@ -191,14 +203,15 @@ class MeterTest {
assertThat(metric)
.hasDescription("This is a test meter")
.hasUnit("things")
.hasDoubleGauge()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12345)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(12345)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
// when
Metrics.globalRegistry.remove(meter);

View File

@ -5,8 +5,8 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.DistributionSummary;
@ -15,6 +15,7 @@ import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.LongTaskTimer;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Timer;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.concurrent.TimeUnit;
@ -25,7 +26,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
@SuppressWarnings("PreferJavaTimeOverload")
class PrometheusModeTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -60,15 +61,17 @@ class PrometheusModeTest {
assertThat(metric)
.hasDescription("This is a test counter")
.hasUnit("items")
.hasDoubleSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(12)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
}
@Test
@ -95,15 +98,16 @@ class PrometheusModeTest {
assertThat(metric)
.hasDescription("This is a test summary")
.hasUnit("items")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(54)
.hasCount(2)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(54)
.hasCount(2)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testPrometheusSummary.items.max",
@ -113,14 +117,15 @@ class PrometheusModeTest {
assertThat(metric)
.hasDescription("This is a test summary")
.hasUnit("items")
.hasDoubleGauge()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(42)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(42)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
}
@Test
@ -149,15 +154,17 @@ class PrometheusModeTest {
assertThat(metric)
.hasDescription("This is a test function timer")
.hasUnit("1")
.hasLongSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(1)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasLongSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testPrometheusFunctionTimer.seconds.sum",
@ -167,14 +174,15 @@ class PrometheusModeTest {
assertThat(metric)
.hasDescription("This is a test function timer")
.hasUnit("s")
.hasDoubleSum()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(42)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(42)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
}
@Test
@ -196,14 +204,15 @@ class PrometheusModeTest {
assertThat(metric)
.hasDescription("This is a test gauge")
.hasUnit("items")
.hasDoubleGauge()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(42)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(42)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
}
@Test
@ -228,15 +237,17 @@ class PrometheusModeTest {
assertThat(metric)
.hasDescription("This is a test long task timer")
.hasUnit("tasks")
.hasLongSum()
.isNotMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(1)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testPrometheusLongTaskTimer.seconds.duration",
@ -246,17 +257,18 @@ class PrometheusModeTest {
assertThat(metric)
.hasDescription("This is a test long task timer")
.hasUnit("s")
.hasDoubleSum()
.isNotMonotonic()
.points()
.satisfiesExactly(
point -> {
assertThat(point)
.attributes()
.containsOnly(attributeEntry("tag", "value"));
// any value >0 - duration of currently running tasks
assertThat(point.getValue()).isPositive();
})));
.hasDoubleSumSatisfying(
sum ->
sum.isNotMonotonic()
.hasPointsSatisfying(
point -> {
point.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"));
// any value >0 - duration of currently running tasks
assertThat(metric.getDoubleSumData().getPoints())
.satisfiesExactly(
p -> assertThat(p.getValue()).isPositive());
}))));
// when
TimeUnit.MILLISECONDS.sleep(100);
@ -270,14 +282,15 @@ class PrometheusModeTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasLongSum()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(0)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasLongSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(0)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testPrometheusLongTaskTimer.seconds.duration",
@ -285,14 +298,15 @@ class PrometheusModeTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasDoubleSum()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(0)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.hasPointsSatisfying(
point ->
point
.hasValue(0)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
}
@Test
@ -319,15 +333,16 @@ class PrometheusModeTest {
assertThat(metric)
.hasDescription("This is a test timer")
.hasUnit("s")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(16.789)
.hasCount(3)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(16.789)
.hasCount(3)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testPrometheusTimer.seconds.max",
@ -337,13 +352,14 @@ class PrometheusModeTest {
assertThat(metric)
.hasDescription("This is a test timer")
.hasUnit("s")
.hasDoubleGauge()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(10.789)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(10.789)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
}
}

View File

@ -5,11 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Timer;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.concurrent.TimeUnit;
@ -21,7 +22,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
@SuppressWarnings("PreferJavaTimeOverload")
class TimerSecondsTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -55,15 +56,16 @@ class TimerSecondsTest {
assertThat(metric)
.hasDescription("This is a test timer")
.hasUnit("s")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(23.345)
.hasCount(3)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(23.345)
.hasCount(3)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testTimerSeconds.max",
@ -73,14 +75,15 @@ class TimerSecondsTest {
assertThat(metric)
.hasDescription("This is a test timer")
.hasUnit("s")
.hasDoubleGauge()
.points()
.anySatisfy(
point ->
assertThat(point)
.hasValue(12.345)
.attributes()
.containsEntry("tag", "value"))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(12.345)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.clearData();
// when
@ -92,15 +95,7 @@ class TimerSecondsTest {
// then
Thread.sleep(100); // interval of the test metrics exporter
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testTimerSeconds",
metrics ->
metrics.allSatisfy(
metric ->
assertThat(metric)
.hasDoubleHistogram()
.points()
.noneSatisfy(point -> assertThat(point).hasSum(35.345).hasCount(4))));
INSTRUMENTATION_NAME, "testTimerSeconds", AbstractIterableAssert::isEmpty);
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME, "testTimerMax.max", AbstractIterableAssert::isEmpty);
}

View File

@ -5,11 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.micrometer.v1_5;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Timer;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.time.Duration;
@ -22,7 +23,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
@SuppressWarnings("PreferJavaTimeOverload")
class TimerTest {
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometershim";
static final String INSTRUMENTATION_NAME = "io.opentelemetry.micrometer1shim";
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@ -33,7 +34,7 @@ class TimerTest {
}
@Test
void testTimer() {
void testTimer() throws Exception {
// given
Timer timer =
Timer.builder("testTimer")
@ -54,15 +55,16 @@ class TimerTest {
assertThat(metric)
.hasDescription("This is a test timer")
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasSum(42_000)
.hasCount(1)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(42_000)
.hasCount(1)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
testing.clearData();
// when
@ -70,16 +72,9 @@ class TimerTest {
timer.record(12, TimeUnit.SECONDS);
// then
Thread.sleep(100); // interval of the test metrics exporter
testing.waitAndAssertMetrics(
INSTRUMENTATION_NAME,
"testTimer",
metrics ->
metrics.allSatisfy(
metric ->
assertThat(metric)
.hasDoubleHistogram()
.points()
.noneSatisfy(point -> assertThat(point).hasSum(54_000).hasCount(2))));
INSTRUMENTATION_NAME, "testTimerMax", AbstractIterableAssert::isEmpty);
}
@Test
@ -99,10 +94,10 @@ class TimerTest {
metric ->
assertThat(metric)
.hasUnit("ms")
.hasDoubleHistogram()
.points()
.satisfiesExactly(
point -> assertThat(point).hasSum(1.234).hasCount(1).attributes())));
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point -> point.hasSum(1.234).hasCount(1)))));
}
@Test
@ -134,32 +129,34 @@ class TimerTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasDoubleGauge()
.points()
.anySatisfy(
point ->
assertThat(point)
.hasValue(1)
.attributes()
.containsEntry("le", "1000"))
.anySatisfy(
point ->
assertThat(point)
.hasValue(2)
.attributes()
.containsEntry("le", "10000"))
.anySatisfy(
point ->
assertThat(point)
.hasValue(3)
.attributes()
.containsEntry("le", "100000"))
.anySatisfy(
point ->
assertThat(point)
.hasValue(4)
.attributes()
.containsEntry("le", "1000000"))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("le"), "1000")),
point ->
point
.hasValue(2)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("le"), "10000")),
point ->
point
.hasValue(3)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("le"), "100000")),
point ->
point
.hasValue(4)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(
AttributeKey.stringKey("le"), "1000000"))))));
}
@Test
@ -184,14 +181,21 @@ class TimerTest {
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasDoubleGauge()
.points()
.anySatisfy(
point -> assertThat(point).attributes().containsEntry("phi", "0.5"))
.anySatisfy(
point -> assertThat(point).attributes().containsEntry("phi", "0.95"))
.anySatisfy(
point -> assertThat(point).attributes().containsEntry("phi", "0.99"))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("phi"), "0.5")),
point ->
point.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("phi"), "0.95")),
point ->
point.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("tag"), "value"),
equalTo(AttributeKey.stringKey("phi"), "0.99"))))));
}
@Test
@ -217,14 +221,15 @@ class TimerTest {
metric ->
assertThat(metric)
.hasDescription("This is a test timer")
.hasDoubleGauge()
.points()
.anySatisfy(
point ->
assertThat(point)
.hasValue(4_000)
.attributes()
.containsEntry("tag", "value"))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(4_000)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"), "value"))))));
// when
Metrics.globalRegistry.remove(timer);

View File

@ -5,8 +5,8 @@
package io.opentelemetry.javaagent.instrumentation.opentelemetryapi.v1_10.metrics;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
@ -19,7 +19,6 @@ import io.opentelemetry.api.metrics.LongUpDownCounter;
import io.opentelemetry.api.metrics.Meter;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
@ -65,15 +64,15 @@ class MeterTest {
.hasInstrumentationScope(
InstrumentationScopeInfo.create(
instrumentationName, "1.2.3", /* schemaUrl= */ null))
.hasLongSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(11)
.attributes()
.containsOnly(attributeEntry("q", "r")))));
.hasLongSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(11)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("q"), "r"))))));
}
@Test
@ -96,15 +95,15 @@ class MeterTest {
.hasInstrumentationScope(
InstrumentationScopeInfo.create(
instrumentationName, "1.2.3", /* schemaUrl= */ null))
.hasLongSum()
.isNotMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(11)
.attributes()
.containsOnly(attributeEntry("q", "r")))));
.hasLongSumSatisfying(
sum ->
sum.isNotMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(11)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("q"), "r"))))));
}
@Test
@ -127,15 +126,15 @@ class MeterTest {
.hasInstrumentationScope(
InstrumentationScopeInfo.create(
instrumentationName, "1.2.3", /* schemaUrl= */ null))
.hasDoubleSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12.1)
.attributes()
.containsOnly(attributeEntry("q", "r")))));
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(12.1)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("q"), "r"))))));
}
@Test
@ -158,15 +157,15 @@ class MeterTest {
.hasInstrumentationScope(
InstrumentationScopeInfo.create(
instrumentationName, "1.2.3", /* schemaUrl= */ null))
.hasDoubleSum()
.isNotMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(12.1)
.attributes()
.containsOnly(attributeEntry("q", "r")))));
.hasDoubleSumSatisfying(
sum ->
sum.isNotMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(12.1)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("q"), "r"))))));
}
@Test
@ -182,22 +181,21 @@ class MeterTest {
"test",
metrics ->
metrics.anySatisfy(
metric -> {
assertThat(metric)
.hasDescription("d")
.hasUnit("u")
.hasInstrumentationScope(
InstrumentationScopeInfo.create(
instrumentationName, "1.2.3", /* schemaUrl= */ null))
.hasDoubleHistogram()
.points()
.allSatisfy(
point -> {
Assertions.assertThat(point.getSum()).isEqualTo(11.0);
Assertions.assertThat(point.getAttributes())
.isEqualTo(Attributes.of(AttributeKey.stringKey("q"), "r"));
});
}));
metric ->
assertThat(metric)
.hasDescription("d")
.hasUnit("u")
.hasInstrumentationScope(
InstrumentationScopeInfo.create(
instrumentationName, "1.2.3", /* schemaUrl= */ null))
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(11.0)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("q"), "r"))))));
}
@Test
@ -213,22 +211,21 @@ class MeterTest {
"test",
metrics ->
metrics.anySatisfy(
metric -> {
assertThat(metric)
.hasDescription("d")
.hasUnit("u")
.hasInstrumentationScope(
InstrumentationScopeInfo.create(
instrumentationName, "1.2.3", /* schemaUrl= */ null))
.hasDoubleHistogram()
.points()
.allSatisfy(
point -> {
Assertions.assertThat(point.getSum()).isEqualTo(12.1);
Assertions.assertThat(point.getAttributes())
.isEqualTo(Attributes.of(AttributeKey.stringKey("q"), "r"));
});
}));
metric ->
assertThat(metric)
.hasDescription("d")
.hasUnit("u")
.hasInstrumentationScope(
InstrumentationScopeInfo.create(
instrumentationName, "1.2.3", /* schemaUrl= */ null))
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
point ->
point
.hasSum(12.1)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("q"), "r"))))));
}
@Test
@ -253,14 +250,14 @@ class MeterTest {
.hasInstrumentationScope(
InstrumentationScopeInfo.create(
instrumentationName, "1.2.3", /* schemaUrl= */ null))
.hasLongGauge()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(123)
.attributes()
.containsOnly(attributeEntry("q", "r")))));
.hasLongGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(123)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("q"), "r"))))));
}
@Test
@ -284,13 +281,13 @@ class MeterTest {
.hasInstrumentationScope(
InstrumentationScopeInfo.create(
instrumentationName, "1.2.3", /* schemaUrl= */ null))
.hasDoubleGauge()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(1.23)
.attributes()
.containsOnly(attributeEntry("q", "r")))));
.hasDoubleGaugeSatisfying(
gauge ->
gauge.hasPointsSatisfying(
point ->
point
.hasValue(1.23)
.hasAttributesSatisfying(
equalTo(AttributeKey.stringKey("q"), "r"))))));
}
}

View File

@ -5,7 +5,7 @@
package io.opentelemetry.instrumentation.oshi;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import org.junit.jupiter.api.Test;
@ -31,9 +31,12 @@ public abstract class AbstractProcessMetricsTest {
metric ->
assertThat(metric)
.hasUnit("By")
.hasLongSum()
.points()
.anySatisfy(point -> assertThat(point.getValue()).isPositive())));
// TODO(anuraaga): Provide fuzzy value matching
.hasLongSumSatisfying(
sum ->
assertThat(metric.getLongSumData().getPoints())
.anySatisfy(
point -> assertThat(point.getValue()).isPositive()))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
@ -43,8 +46,11 @@ public abstract class AbstractProcessMetricsTest {
metric ->
assertThat(metric)
.hasUnit("ms")
.hasLongGauge()
.points()
.anySatisfy(point -> assertThat(point.getValue()).isPositive())));
// TODO(anuraaga): Provide fuzzy value matching
.hasLongGaugeSatisfying(
gauge ->
assertThat(metric.getLongGaugeData().getPoints())
.anySatisfy(
point -> assertThat(point.getValue()).isPositive()))));
}
}

View File

@ -5,10 +5,9 @@
package io.opentelemetry.instrumentation.oshi;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
public abstract class AbstractSystemMetricsTest {
@ -32,10 +31,12 @@ public abstract class AbstractSystemMetricsTest {
metric ->
assertThat(metric)
.hasUnit("By")
.hasLongSum()
.points()
.anySatisfy(
point -> Assertions.assertThat(point.getValue()).isPositive())));
// TODO(anuraaga): Provide fuzzy value matching
.hasLongSumSatisfying(
sum ->
assertThat(metric.getLongSumData().getPoints())
.anySatisfy(
point -> assertThat(point.getValue()).isPositive()))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
@ -45,38 +46,49 @@ public abstract class AbstractSystemMetricsTest {
metric ->
assertThat(metric)
.hasUnit("1")
.hasDoubleGauge()
.points()
.anySatisfy(
point -> Assertions.assertThat(point.getValue()).isPositive())));
// TODO(anuraaga): Provide fuzzy value matching
.hasDoubleGaugeSatisfying(
gauge ->
assertThat(metric.getDoubleGaugeData().getPoints())
.anySatisfy(
point -> assertThat(point.getValue()).isPositive()))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
"system.network.io",
metrics -> metrics.anySatisfy(metric -> assertThat(metric).hasUnit("By").hasLongSum()));
metrics ->
metrics.anySatisfy(
metric -> assertThat(metric).hasUnit("By").hasLongSumSatisfying(sum -> {})));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
"system.network.packets",
metrics ->
metrics.anySatisfy(metric -> assertThat(metric).hasUnit("packets").hasLongSum()));
metrics.anySatisfy(
metric ->
assertThat(metric).hasUnit("packets").hasLongSumSatisfying(sum -> {})));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
"system.network.errors",
metrics ->
metrics.anySatisfy(metric -> assertThat(metric).hasUnit("errors").hasLongSum()));
metrics.anySatisfy(
metric ->
assertThat(metric).hasUnit("errors").hasLongSumSatisfying(sum -> {})));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
"system.disk.io",
metrics -> metrics.anySatisfy(metric -> assertThat(metric).hasUnit("By").hasLongSum()));
metrics ->
metrics.anySatisfy(
metric -> assertThat(metric).hasUnit("By").hasLongSumSatisfying(sum -> {})));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.oshi",
"system.disk.operations",
metrics ->
metrics.anySatisfy(
metric -> assertThat(metric).hasUnit("operations").hasLongSum()));
metric ->
assertThat(metric).hasUnit("operations").hasLongSumSatisfying(sum -> {})));
}
}

View File

@ -5,11 +5,12 @@
package io.opentelemetry.javaagent.instrumentation.spring.actuator;
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
@ -36,22 +37,24 @@ class ActuatorTest {
testBean.inc();
testing.waitAndAssertMetrics(
"io.opentelemetry.micrometershim",
"io.opentelemetry.micrometer1shim",
"test-counter",
metrics ->
metrics.anySatisfy(
metric ->
assertThat(metric)
.hasUnit("thingies")
.hasDoubleSum()
.isMonotonic()
.points()
.satisfiesExactly(
point ->
assertThat(point)
.hasValue(1)
.attributes()
.containsOnly(attributeEntry("tag", "value")))));
.hasDoubleSumSatisfying(
sum ->
sum.isMonotonic()
.hasPointsSatisfying(
point ->
point
.hasValue(1)
.hasAttributesSatisfying(
equalTo(
AttributeKey.stringKey("tag"),
"value"))))));
MeterRegistry meterRegistry = context.getBean(MeterRegistry.class);
assertThat(meterRegistry).isNotNull().isInstanceOf(CompositeMeterRegistry.class);

View File

@ -38,7 +38,6 @@ dependencies {
api("io.opentelemetry:opentelemetry-sdk")
api("io.opentelemetry:opentelemetry-sdk-testing")
api("io.opentelemetry:opentelemetry-sdk-metrics")
api("io.opentelemetry:opentelemetry-sdk-metrics-testing")
api("io.opentelemetry:opentelemetry-sdk-logs")
api(project(":instrumentation-api"))

View File

@ -28,7 +28,7 @@ public class AgentTestingExporterFactory {
public static void reset() {
// Flush meter provider to remove any lingering measurements
AgentTestingCustomizer.metricReader.flush().join(10, TimeUnit.SECONDS);
AgentTestingCustomizer.metricReader.forceFlush().join(10, TimeUnit.SECONDS);
spanExporter.reset();
metricExporter.reset();
logExporter.reset();