Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Class Cast Exception when using OpenTelemetry and max-connections property #43919

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.quarkus.opentelemetry.deployment.metrics;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.opentelemetry.deployment.common.exporter.InMemoryMetricExporter;
import io.quarkus.opentelemetry.deployment.common.exporter.InMemoryMetricExporterProvider;
import io.quarkus.opentelemetry.deployment.common.exporter.TestSpanExporter;
import io.quarkus.opentelemetry.deployment.common.exporter.TestSpanExporterProvider;
import io.quarkus.test.QuarkusUnitTest;

public class ClassCastExceptionTest {

@RegisterExtension
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
.setArchiveProducer(
() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(TestSpanExporter.class, TestSpanExporterProvider.class)
.addClasses(InMemoryMetricExporter.class, InMemoryMetricExporterProvider.class)
.addAsResource(new StringAsset(InMemoryMetricExporterProvider.class.getCanonicalName()),
"META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider")
.add(new StringAsset(
"quarkus.otel.metrics.enabled=true\n" +
"quarkus.otel.metrics.exporter=in-memory\n" +
"quarkus.otel.metric.export.interval=300ms\n" +
"quarkus.http.limits.max-connections=50\n" +
"quarkus.otel.traces.exporter=none\n" +
"quarkus.otel.logs.exporter=none\n"),
"application.properties"));

/**
* ClassCastException when using OpenTelemetry and max-connections property
* See https://github.com/quarkusio/quarkus/issues/43852
*/
@Test
public void testReproducer() {
// This test is successful if it does not throw an exception
Assertions.assertTrue(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Optional;

import io.quarkus.vertx.http.runtime.ExtendedQuarkusVertxHttpMetrics;
import io.vertx.core.Context;
import io.vertx.core.VertxOptions;
import io.vertx.core.http.HttpServerOptions;
Expand All @@ -16,7 +17,7 @@
* This is used to retrieve the route name from Vert.x. This is useful for OpenTelemetry to generate the Span name and
* <code>http.route</code> attribute. Right now, there is no other way to retrieve the route name from Vert.x using the
* Telemetry SPI, so we need to rely on the Metrics SPI.
*
* <p>
* Right now, it is not possible to register multiple <code>VertxMetrics</code>, meaning that only a single one is
* available per Quarkus instance. To avoid clashing with other extensions that provide Metrics data (like the
* Micrometer extension), we only register the {@link OpenTelemetryVertxMetricsFactory} if the
Expand All @@ -25,17 +26,19 @@
public class OpenTelemetryVertxMetricsFactory implements VertxMetricsFactory {
@Override
public VertxMetrics metrics(final VertxOptions options) {
return new VertxMetrics() {
@Override
public HttpServerMetrics<?, ?, ?> createHttpServerMetrics(final HttpServerOptions options,
final SocketAddress localAddress) {
return new OpenTelemetryHttpServerMetrics();
}
};
return new OpenTelemetryHttpServerMetrics();
}

public static class OpenTelemetryHttpServerMetrics
implements HttpServerMetrics<OpenTelemetryHttpServerMetrics.MetricRequest, Object, Object> {
implements HttpServerMetrics<OpenTelemetryHttpServerMetrics.MetricRequest, Object, Object>,
VertxMetrics, ExtendedQuarkusVertxHttpMetrics {

@Override
public HttpServerMetrics<?, ?, ?> createHttpServerMetrics(final HttpServerOptions options,
final SocketAddress localAddress) {
return this;
}

@Override
public MetricRequest requestBegin(final Object socketMetric, final HttpRequest request) {
return MetricRequest.request(request);
Expand All @@ -48,6 +51,12 @@ public void requestRouted(final MetricRequest requestMetric, final String route)
}
}

@Override
public ConnectionTracker getHttpConnectionTracker() {
// To be implemented if we decide to instrument with OpenTelemetry. See VertxMeterBinderAdapter for an example.
return ExtendedQuarkusVertxHttpMetrics.NOOP_CONNECTION_TRACKER;
}

static final class MetricRequest {
private final HttpRequest request;

Expand Down
Loading