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

WIP: Moved kamon-netty #1113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,22 @@ lazy val `kamon-finagle` = (project in file("instrumentation/kamon-finagle"))
)
).dependsOn(`kamon-core`, `kamon-instrumentation-common`, `kamon-testkit` % "test")

lazy val `kamon-netty` = (project in file("instrumentation/kamon-netty"))
.disablePlugins(AssemblyPlugin)
.enablePlugins(JavaAgent)
.settings(instrumentationSettings)
.settings(
libraryDependencies ++= Seq(
kanelaAgent % "provided",
"io.netty" % "netty-all" % "4.1.65.Final" % "provided",
"io.netty" % "netty-transport-native-epoll" % "4.1.65.Final" % "provided" classifier "linux-x86_64",

scalatest % "test",
logbackClassic % "test",
)
).dependsOn(`kamon-core`, `kamon-instrumentation-common`, `kamon-testkit` % "test")


/**
* Reporters
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kamon.netty.instrumentation.advisor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move all the code to the kamon.instrumentation.netty package to follow the same conventions across all projects


import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpRequest;
import kamon.netty.instrumentation.HttpRequestContext;
import kanela.agent.libs.net.bytebuddy.asm.Advice.Argument;
import kanela.agent.libs.net.bytebuddy.asm.Advice.OnMethodEnter;

public class ClientEncodeMethodAdvisor {

@OnMethodEnter
static void onEnter(@Argument(value = 0) ChannelHandlerContext ctx,
@Argument(value = 1, readOnly = false) Object request) {
if (request instanceof HttpRequest) {
request = HttpRequestContext.withContext((HttpRequest)request, ctx);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package kamon.netty.instrumentation.advisor;

import io.netty.channel.EventLoop;
import java.util.Queue;
import kamon.netty.util.MonitoredQueue;
import kanela.agent.libs.net.bytebuddy.asm.Advice.OnMethodExit;
import kanela.agent.libs.net.bytebuddy.asm.Advice.Return;
import kanela.agent.libs.net.bytebuddy.asm.Advice.This;

public class NewTaskQueueMethodAdvisor {

@OnMethodExit
static void onExit(@This Object eventLoop, @Return(readOnly = false) Queue<Runnable> queue) {
MonitoredQueue.apply((EventLoop) eventLoop, queue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the method that would fail on more recent Netty versions because newTaskQueue was turned into a static method?

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* =========================================================================================
* Copyright © 2013-2017 the kamon project <http://kamon.io/>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
* =========================================================================================
*/


package kamon.netty.util;

import java.util.Collection;
import java.util.Iterator;
import java.util.Queue;

public class QueueWrapperAdapter<E> implements Queue<E> {

private final Queue<E> underlying;

public QueueWrapperAdapter(Queue<E> underlying) {
this.underlying = underlying;
}

@Override
public int size() {
return underlying.size();
}

@Override
public boolean isEmpty() {
return underlying.isEmpty();
}

@Override
public boolean contains(Object o) {
return underlying.contains(o);
}

@Override
public Iterator<E> iterator() {
return underlying.iterator();
}

@Override
public Object[] toArray() {
return underlying.toArray();
}

@Override
public <T> T[] toArray(T[] a) {
return underlying.toArray(a);
}

@Override
public boolean add(E e) {
return underlying.add(e);
}

@Override
public boolean remove(Object o) {
return underlying.remove(o);
}

@Override
public boolean containsAll(Collection<?> c) {
return underlying.containsAll(c);
}

@Override
public boolean addAll(Collection<? extends E> c) {
return underlying.addAll(c);
}

@Override
public boolean removeAll(Collection<?> c) {
return underlying.removeAll(c);
}

@Override
public boolean retainAll(Collection<?> c) {
return underlying.retainAll(c);
}

@Override
public void clear() {
underlying.clear();
}

@Override
public boolean offer(E e) {
return underlying.offer(e);
}

@Override
public E remove() {
return underlying.remove();
}

@Override
public E poll() {
return underlying.poll();
}

@Override
public E element() {
return underlying.element();
}

@Override
public E peek() {
return underlying.peek();
}
}
17 changes: 17 additions & 0 deletions instrumentation/kamon-netty/src/main/resources/META-INF/aop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file


<aspectj>
<aspects>
<aspect name="kamon.netty.instrumentation.mixin.ChannelInstrumentation"/>
<aspect name="kamon.netty.instrumentation.EventLoopMixin"/>
<aspect name="kamon.netty.instrumentation.ServerBootstrapInstrumentation"/>
<aspect name="kamon.netty.instrumentation.EventLoopInstrumentation"/>
<aspect name="kamon.netty.instrumentation.EpollEventLoopInstrumentation"/>
<aspect name="kamon.netty.instrumentation.HttpClientInstrumentation"/>
<aspect name="kamon.netty.instrumentation.HttpServerInstrumentation"/>
</aspects>
<weaver>
<include within="kamon.netty..*"/>
<include within="io.netty..*"/>
</weaver>
</aspectj>
14 changes: 14 additions & 0 deletions instrumentation/kamon-netty/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configuration>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file. You might add one under test/resources for testing purposes, but we can't include a logback.xml with the main artifact


<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Loading