Adjust Armeria plugin to adapt 0.98.0 (#4362)
Motivation: Support Armeria 0.98.0 in its plugin. Modifications: Add an intercept point that is refactored in Armeria 0.98. Result: Now Armeria plugin supports 0.98.0, and 0.98.1
This commit is contained in:
parent
ae442e364f
commit
ae33ac81c8
|
|
@ -28,7 +28,7 @@
|
|||
<artifactId>apm-armeria-0.85.x-plugin</artifactId>
|
||||
<name>armeria-0.85.x-plugin</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>SkyWalking Agent Plugin for Armeria 0.85.0 ~ 0.97.0</description>
|
||||
<description>SkyWalking Agent Plugin for Armeria 0.85.0 ~ 0.98.0</description>
|
||||
<properties>
|
||||
<compiler.version>1.8</compiler.version>
|
||||
</properties>
|
||||
|
|
|
|||
|
|
@ -20,18 +20,20 @@ package org.apache.skywalking.apm.plugin.armeria;
|
|||
import com.linecorp.armeria.client.UserClient;
|
||||
import com.linecorp.armeria.common.HttpMethod;
|
||||
import com.linecorp.armeria.common.HttpRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@SuppressWarnings({
|
||||
"rawtypes",
|
||||
"unused"
|
||||
})
|
||||
public class Armeria085ClientInterceptor extends ArmeriaClientInterceptor {
|
||||
|
||||
@Override
|
||||
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final MethodInterceptResult result) throws Throwable {
|
||||
final Class<?>[] argumentsTypes, final MethodInterceptResult result) {
|
||||
|
||||
final UserClient userClient = (UserClient) objInst;
|
||||
final URI uri = userClient.uri();
|
||||
|
|
@ -48,7 +50,7 @@ public class Armeria085ClientInterceptor extends ArmeriaClientInterceptor {
|
|||
|
||||
@Override
|
||||
public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final Object ret) {
|
||||
final Class<?>[] argumentsTypes, final Object ret) {
|
||||
|
||||
Object req = allArguments[5];
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.apache.skywalking.apm.plugin.armeria;
|
|||
import com.linecorp.armeria.common.DefaultHttpRequest;
|
||||
import com.linecorp.armeria.common.HttpHeaders;
|
||||
import io.netty.util.AsciiString;
|
||||
import java.lang.reflect.Method;
|
||||
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
|
||||
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.apache.skywalking.apm.agent.core.context.ContextManager;
|
||||
|
|
@ -31,12 +32,11 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceM
|
|||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@SuppressWarnings("unused") // actually used
|
||||
public class Armeria085ServerInterceptor implements InstanceMethodsAroundInterceptor {
|
||||
@Override
|
||||
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final MethodInterceptResult result) throws Throwable {
|
||||
final Class<?>[] argumentsTypes, final MethodInterceptResult result) {
|
||||
|
||||
DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1];
|
||||
HttpHeaders headers = httpRequest.headers();
|
||||
|
|
@ -57,7 +57,7 @@ public class Armeria085ServerInterceptor implements InstanceMethodsAroundInterce
|
|||
|
||||
@Override
|
||||
public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final Object ret) {
|
||||
final Class<?>[] argumentsTypes, final Object ret) {
|
||||
if (ContextManager.isActive()) {
|
||||
ContextManager.stopSpan();
|
||||
}
|
||||
|
|
@ -66,7 +66,7 @@ public class Armeria085ServerInterceptor implements InstanceMethodsAroundInterce
|
|||
|
||||
@Override
|
||||
public void handleMethodException(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final Throwable t) {
|
||||
final Class<?>[] argumentsTypes, final Throwable t) {
|
||||
if (ContextManager.isActive()) {
|
||||
ContextManager.activeSpan().errorOccurred().log(t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,21 +17,23 @@
|
|||
|
||||
package org.apache.skywalking.apm.plugin.armeria;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
import com.linecorp.armeria.client.UserClient;
|
||||
import com.linecorp.armeria.common.HttpMethod;
|
||||
import com.linecorp.armeria.common.HttpRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@SuppressWarnings({
|
||||
"rawtypes",
|
||||
"unused"
|
||||
})
|
||||
public class Armeria086ClientInterceptor extends ArmeriaClientInterceptor {
|
||||
|
||||
@Override
|
||||
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final MethodInterceptResult result) throws Throwable {
|
||||
final Class<?>[] argumentsTypes, final MethodInterceptResult result) {
|
||||
|
||||
final UserClient userClient = (UserClient) objInst;
|
||||
final URI uri = userClient.uri();
|
||||
|
|
@ -48,7 +50,7 @@ public class Armeria086ClientInterceptor extends ArmeriaClientInterceptor {
|
|||
|
||||
@Override
|
||||
public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final Object ret) {
|
||||
final Class<?>[] argumentsTypes, final Object ret) {
|
||||
|
||||
Object req = allArguments[6];
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.armeria;
|
||||
|
||||
import com.linecorp.armeria.client.UserClient;
|
||||
import com.linecorp.armeria.common.HttpMethod;
|
||||
import com.linecorp.armeria.common.HttpRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
|
||||
|
||||
@SuppressWarnings({
|
||||
"rawtypes",
|
||||
"unused"
|
||||
})
|
||||
public class Armeria098ClientInterceptor extends ArmeriaClientInterceptor {
|
||||
|
||||
@Override
|
||||
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final MethodInterceptResult result) {
|
||||
|
||||
final UserClient userClient = (UserClient) objInst;
|
||||
final URI uri = userClient.uri();
|
||||
final HttpMethod httpMethod = (HttpMethod) allArguments[1];
|
||||
final String path = (String) allArguments[2];
|
||||
final Object req = allArguments[5];
|
||||
|
||||
if (!(req instanceof HttpRequest)) {
|
||||
return;
|
||||
}
|
||||
|
||||
beforeMethod(uri, httpMethod, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final Object ret) {
|
||||
|
||||
final Object req = allArguments[5];
|
||||
|
||||
afterMethod(req);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -17,15 +17,14 @@
|
|||
|
||||
package org.apache.skywalking.apm.plugin.armeria;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
import com.linecorp.armeria.client.Clients;
|
||||
import com.linecorp.armeria.common.HttpHeadersBuilder;
|
||||
import com.linecorp.armeria.common.HttpMethod;
|
||||
import com.linecorp.armeria.common.HttpRequest;
|
||||
import com.linecorp.armeria.common.util.SafeCloseable;
|
||||
import io.netty.util.AsciiString;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
|
||||
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
|
||||
import org.apache.skywalking.apm.agent.core.context.ContextManager;
|
||||
|
|
@ -72,7 +71,7 @@ public abstract class ArmeriaClientInterceptor implements InstanceMethodsAroundI
|
|||
|
||||
@Override
|
||||
public void handleMethodException(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
|
||||
final Class<?>[] argumentsTypes, final Throwable t) {
|
||||
final Class<?>[] argumentsTypes, final Throwable t) {
|
||||
if (ContextManager.isActive()) {
|
||||
ContextManager.activeSpan().errorOccurred().log(t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
/**
|
||||
* Instruments Armeria client 0.85.x
|
||||
*/
|
||||
public class Armeria085ClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
private static final String ENHANCE_CLASS = "com.linecorp.armeria.client.UserClient";
|
||||
private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.armeria.Armeria085ClientInterceptor";
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
/**
|
||||
* Instruments Armeria server 0.85.x
|
||||
*/
|
||||
public class Armeria085ServerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
private static final String ENHANCE_CLASS = "com.linecorp.armeria.server.HttpServerHandler";
|
||||
private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.armeria.Armeria085ServerInterceptor";
|
||||
|
|
@ -48,8 +51,9 @@ public class Armeria085ServerInstrumentation extends ClassInstanceMethodsEnhance
|
|||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("handleRequest").and(takesArgument(0, named("io.netty.channel.ChannelHandlerContext")))
|
||||
.and(takesArgument(1, named("com.linecorp.armeria.server.DecodedHttpRequest")));
|
||||
return named("handleRequest")
|
||||
.and(takesArgument(0, named("io.netty.channel.ChannelHandlerContext")))
|
||||
.and(takesArgument(1, named("com.linecorp.armeria.server.DecodedHttpRequest")));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
/**
|
||||
* Instruments Armeria client 0.86.x ~ 0.97.x
|
||||
*/
|
||||
public class Armeria086ClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
private static final String ENHANCE_CLASS = "com.linecorp.armeria.client.UserClient";
|
||||
private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.armeria.Armeria086ClientInterceptor";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.apache.skywalking.apm.plugin.armeria.define;
|
||||
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
|
||||
import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName;
|
||||
|
||||
/**
|
||||
* Instruments Armeria client 0.98.x
|
||||
*/
|
||||
public class Armeria098ClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
private static final String ENHANCE_CLASS = "com.linecorp.armeria.client.UserClient";
|
||||
private static final String INTERCEPTOR_CLASS_98 = "org.apache.skywalking.apm.plugin.armeria.Armeria098ClientInterceptor";
|
||||
|
||||
@Override
|
||||
protected ClassMatch enhanceClass() {
|
||||
return byName(ENHANCE_CLASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
|
||||
return new ConstructorInterceptPoint[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
|
||||
return new InstanceMethodsInterceptPoint[] {
|
||||
new InstanceMethodsInterceptPoint() {
|
||||
@Override
|
||||
public ElementMatcher<MethodDescription> getMethodsMatcher() {
|
||||
return named("execute")
|
||||
.and(takesArguments(7))
|
||||
.and(takesArgument(0, named("com.linecorp.armeria.client.endpoint.EndpointGroup")))
|
||||
.and(takesArgument(1, named("com.linecorp.armeria.common.HttpMethod")))
|
||||
.and(takesArgument(2, named("java.lang.String")))
|
||||
.and(takesArgument(3, named("java.lang.String")))
|
||||
.and(takesArgument(4, named("java.lang.String")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodsInterceptor() {
|
||||
return INTERCEPTOR_CLASS_98;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverrideArgs() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Witness classes that are added since 0.63.0
|
||||
*
|
||||
* @return witness classes
|
||||
*/
|
||||
@Override
|
||||
protected String[] witnessClasses() {
|
||||
return new String[] {
|
||||
"com.linecorp.armeria.common.AbstractHttpHeadersBuilder"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -16,4 +16,5 @@
|
|||
|
||||
armeria-085=org.apache.skywalking.apm.plugin.armeria.define.Armeria085ServerInstrumentation
|
||||
armeria-085=org.apache.skywalking.apm.plugin.armeria.define.Armeria085ClientInstrumentation
|
||||
armeria-086=org.apache.skywalking.apm.plugin.armeria.define.Armeria086ClientInstrumentation
|
||||
armeria-086=org.apache.skywalking.apm.plugin.armeria.define.Armeria086ClientInstrumentation
|
||||
armeria-098=org.apache.skywalking.apm.plugin.armeria.define.Armeria098ClientInstrumentation
|
||||
Loading…
Reference in New Issue