From 41be35f819d07a4af206175c879253b40bee89e6 Mon Sep 17 00:00:00 2001 From: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:06:24 +0900 Subject: [PATCH] Improve `JettyConnectionMetrics` connection type detection The `HttpConnection` class was relocated to a different package in Jetty 12 which was causing a `NoClassDefFoundError` when doing an instanceof check on it. The goal of it is to determine whether the connection instrumented is a server connection or a client connection. However, it specifically checks against `HttpConnection` and assumes that all server connections will be an instanceof `HttpConnection` and any not an instanceof it are client connections. This is brittle because Jetty supports more implementations of `Connection` on the server side than `HttpConnection` and there could in theory be an arbitrary implementation where we do not know whether it is a server or client connection (it could also be neither). This instead checks whether the package name contains `server` or `client` or neither. This is admittedly also brittle, but given the known implementations of `Connection` provided by the Jetty project, this pattern generally seems to hold, and it is at least more honest using `UNKNOWN` when our heuristic fails. It also avoids the `NoClassDefFoundError` when using `JettyConnectionMetrics` with Jetty 12. Resolves gh-4324 --- micrometer-core/build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/micrometer-core/build.gradle b/micrometer-core/build.gradle index 726aecb324..2fa4fa575d 100644 --- a/micrometer-core/build.gradle +++ b/micrometer-core/build.gradle @@ -198,8 +198,6 @@ dependencies { testImplementation 'io.grpc:grpc-inprocess' testImplementation 'io.grpc:grpc-testing-proto' testImplementation 'com.squareup.retrofit2:retrofit' - - testImplementation libs.jetty9http2Server } task shenandoahTest(type: Test) {