-
Notifications
You must be signed in to change notification settings - Fork 881
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Netty4.1: remove our handler when original handler is removed (#3026)
* Netty4.1: remove our handler when orignal handler is removed * Update instrumentation/netty/netty-4.1/javaagent/src/test/groovy/ChannelPipelineTest.groovy Co-authored-by: Mateusz Rzeszutek <[email protected]> * disable epoll to see whether it makes any difference * fix netty with epoll/kqueue native library Co-authored-by: Mateusz Rzeszutek <[email protected]>
- Loading branch information
Showing
9 changed files
with
233 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
instrumentation/netty/netty-4.1/javaagent/src/test/groovy/ChannelPipelineTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import io.netty.channel.DefaultChannelPipeline | ||
import io.netty.channel.embedded.EmbeddedChannel | ||
import io.netty.handler.codec.http.HttpClientCodec | ||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification | ||
import io.opentelemetry.javaagent.instrumentation.netty.v4_1.client.HttpClientTracingHandler | ||
import spock.lang.Unroll | ||
|
||
class ChannelPipelineTest extends AgentInstrumentationSpecification { | ||
// regression test for https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1373 | ||
@Unroll | ||
def "test remove our handler #testName"() { | ||
setup: | ||
def channel = new EmbeddedChannel() | ||
def channelPipeline = new DefaultChannelPipeline(channel) | ||
def handler = new HttpClientCodec() | ||
|
||
when: | ||
// no handlers | ||
channelPipeline.first() == null | ||
|
||
then: | ||
// add handler | ||
channelPipeline.addLast("http", handler) | ||
channelPipeline.first() == handler | ||
// our handler was also added | ||
channelPipeline.last().getClass() == HttpClientTracingHandler | ||
|
||
and: | ||
removeMethod.call(channelPipeline, handler) | ||
// removing handler also removes our handler | ||
channelPipeline.first() == null | ||
|
||
where: | ||
testName | removeMethod | ||
"by instance" | { pipeline, h -> pipeline.remove(h) } | ||
"by class" | { pipeline, h -> pipeline.remove(h.getClass()) } | ||
"by name" | { pipeline, h -> pipeline.remove("http") } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41NativeClientTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import io.netty.channel.Channel | ||
import io.netty.channel.EventLoopGroup | ||
import io.netty.channel.epoll.Epoll | ||
import io.netty.channel.epoll.EpollEventLoopGroup | ||
import io.netty.channel.epoll.EpollSocketChannel | ||
import io.netty.channel.kqueue.KQueue | ||
import io.netty.channel.kqueue.KQueueEventLoopGroup | ||
import io.netty.channel.kqueue.KQueueSocketChannel | ||
import org.junit.Assume | ||
|
||
// netty client test with epoll/kqueue native library | ||
class Netty41NativeClientTest extends Netty41ClientTest { | ||
|
||
EventLoopGroup getEventLoopGroup() { | ||
// linux | ||
if (Epoll.isAvailable()) { | ||
return new EpollEventLoopGroup() | ||
} | ||
// mac | ||
if (KQueueHelper.isAvailable()) { | ||
return new KQueueEventLoopGroup() | ||
} | ||
|
||
// skip test when native library was not found | ||
Assume.assumeTrue("Native library was not found", false) | ||
return super.getEventLoopGroup() | ||
} | ||
|
||
@Override | ||
Class<Channel> getChannelClass() { | ||
if (Epoll.isAvailable()) { | ||
return EpollSocketChannel | ||
} | ||
if (KQueueHelper.isAvailable()) { | ||
return KQueueSocketChannel | ||
} | ||
return null | ||
} | ||
|
||
static class KQueueHelper { | ||
static boolean isAvailable() { | ||
try { | ||
return KQueue.isAvailable() | ||
} catch (NoClassDefFoundError error) { | ||
// kqueue is available only in latest dep tests | ||
// in regular tests we only have a compile time dependency because kqueue support was added | ||
// after 4.1.0 | ||
return false | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...mentation/ratpack-1.4/javaagent/src/test/groovy/client/RatpackPooledHttpClientTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package client | ||
|
||
import ratpack.http.client.HttpClientSpec | ||
|
||
class RatpackPooledHttpClientTest extends RatpackHttpClientTest { | ||
|
||
@Override | ||
void configureClient(HttpClientSpec spec) { | ||
spec.poolSize(5) | ||
} | ||
} |