Skip to content

Commit

Permalink
Improve JettyConnectionMetrics connection type detection
Browse files Browse the repository at this point in the history
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 micrometer-metricsgh-4324
  • Loading branch information
shakuzen committed Nov 9, 2023
1 parent 5d78074 commit 41be35f
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions micrometer-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 41be35f

Please sign in to comment.