调准全套的classloader机制,实现自己的classload。保证类所在的classload关系正确。
遗留问题:dubbo插件实现模式错误,应该考虑增强MonitorFilter的invoke方法,而不是新增Filter,新增Filter由于dubbo以spi模式运行,会有问题。 另外,JDBC插件不应该根据url去查找驱动,应该在当前的DriverManager的其他注册驱动中去寻找合适的,进行调用后,包装返回。
This commit is contained in:
parent
fea63c4405
commit
d6507d2fea
|
|
@ -78,22 +78,6 @@
|
|||
<artifactId>h2</artifactId>
|
||||
<version>1.4.192</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-log4j-1.x-plugin</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-log4j-2.x-plugin</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<log4j:configuration>
|
||||
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
|
||||
<layout class="com.ai.cloud.skywalking.plugin.log.log4j.v1.x.TraceIdPatternLayout">
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern"
|
||||
value="%x %d - %c -%-4r [%t] %-5p %x - %m%n" />
|
||||
</layout>
|
||||
|
|
|
|||
|
|
@ -67,14 +67,14 @@
|
|||
<version>0.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-log4j-1.x-plugin</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ai.cloud</groupId>
|
||||
<artifactId>skywalking-log4j-2.x-plugin</artifactId>
|
||||
<version>1.0-Final</version>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@ log4j.rootLogger=DEBUG, A1
|
|||
#log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss.SSS} %c %n[%p] %n%m%n
|
||||
|
||||
log4j.appender.A1=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.A1.layout=com.ai.cloud.skywalking.plugin.log.log4j.v1.x.TraceIdPatternLayout
|
||||
log4j.appender.A1.layout.ConversionPattern=%x %-d{yyyy-MM-dd HH:mm:ss.SSS} %c %n[%p] %n%m%n
|
||||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss.SSS} %c %n[%p] %n%m%n
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ public class SkyWalkingAgent {
|
|||
|
||||
@Override
|
||||
public void onIgnored(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) {
|
||||
logger.info("ignore to enhance class " + typeDescription.getTypeName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -52,7 +51,6 @@ public class SkyWalkingAgent {
|
|||
|
||||
@Override
|
||||
public void onComplete(String typeName, ClassLoader classLoader, JavaModule module) {
|
||||
logger.info("enhance class " + typeName + " complete.");
|
||||
}
|
||||
}).installOn(instrumentation);
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class Config {
|
|||
// log文件文件夹名字
|
||||
public static String LOG_DIR_NAME = "logs";
|
||||
// 最大文件大小
|
||||
public static int MAX_LOG_FILE_LENGTH = 3 * 1024 * 1024;
|
||||
public static int MAX_LOG_FILE_LENGTH = 300 * 1024 * 1024;
|
||||
// skywalking 系统错误文件日志
|
||||
public static String SYSTEM_ERROR_LOG_FILE_NAME = "skywalking-api-error.log";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class ConfigInitializer {
|
|||
|
||||
static void initialize(InputStream inputStream) {
|
||||
if (inputStream == null) {
|
||||
logger.info("No provider sky-walking certification documents, sky-walking api auto shutdown.");
|
||||
logger.info("Not provide sky-walking certification documents, sky-walking api auto shutdown.");
|
||||
} else {
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.ai.cloud.skywalking.plugin.interceptor.enhance;
|
|||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.loader.InterceptorInstanceLoader;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.FieldProxy;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
|
|
@ -13,10 +14,10 @@ public class ClassConstructorInterceptor {
|
|||
private static Logger logger = LogManager
|
||||
.getLogger(ClassConstructorInterceptor.class);
|
||||
|
||||
private InstanceMethodsAroundInterceptor interceptor;
|
||||
private String instanceMethodsAroundInterceptorClassName;
|
||||
|
||||
public ClassConstructorInterceptor(InstanceMethodsAroundInterceptor interceptor) {
|
||||
this.interceptor = interceptor;
|
||||
public ClassConstructorInterceptor(String instanceMethodsAroundInterceptorClassName) {
|
||||
this.instanceMethodsAroundInterceptorClassName = instanceMethodsAroundInterceptorClassName;
|
||||
}
|
||||
|
||||
@RuntimeType
|
||||
|
|
@ -25,6 +26,8 @@ public class ClassConstructorInterceptor {
|
|||
@FieldProxy(ClassEnhancePluginDefine.contextAttrName) FieldSetter accessor,
|
||||
@AllArguments Object[] allArguments) {
|
||||
try {
|
||||
InstanceMethodsAroundInterceptor interceptor = InterceptorInstanceLoader.load(instanceMethodsAroundInterceptorClassName, obj.getClass().getClassLoader());
|
||||
|
||||
EnhancedClassInstanceContext context = new EnhancedClassInstanceContext();
|
||||
accessor.setValue(context);
|
||||
ConstructorInvokeContext interceptorContext = new ConstructorInvokeContext(obj,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import static net.bytebuddy.matcher.ElementMatchers.not;
|
|||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.protocol.util.StringUtil;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.implementation.MethodDelegation;
|
||||
|
|
@ -25,6 +26,7 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
|
||||
public static final String contextAttrName = "_$EnhancedClassInstanceContext";
|
||||
|
||||
@Override
|
||||
protected DynamicType.Builder<?> enhance(String enhanceOriginClassName,
|
||||
DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
newClassBuilder = this.enhanceClass(enhanceOriginClassName, newClassBuilder);
|
||||
|
|
@ -52,9 +54,9 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
* 2.intercept constructor by default, and intercept method which it's
|
||||
* required by interceptorDefineClass. <br/>
|
||||
*/
|
||||
InstanceMethodsAroundInterceptor interceptor = getInstanceMethodsInterceptor();
|
||||
if (interceptor == null) {
|
||||
throw new EnhanceException("no InstanceMethodsAroundInterceptor instance. ");
|
||||
String interceptor = getInstanceMethodsInterceptor();
|
||||
if (StringUtil.isEmpty(interceptor)) {
|
||||
throw new EnhanceException("no InstanceMethodsAroundInterceptor define. ");
|
||||
}
|
||||
|
||||
newClassBuilder = newClassBuilder
|
||||
|
|
@ -116,7 +118,7 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract InstanceMethodsAroundInterceptor getInstanceMethodsInterceptor();
|
||||
protected abstract String getInstanceMethodsInterceptor();
|
||||
|
||||
private DynamicType.Builder<?> enhanceClass(String enhanceOriginClassName,
|
||||
DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
|
|
@ -124,10 +126,10 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
if(methodMatchers == null){
|
||||
return newClassBuilder;
|
||||
}
|
||||
|
||||
StaticMethodsAroundInterceptor interceptor = getStaticMethodsInterceptor();
|
||||
if (interceptor == null) {
|
||||
throw new EnhanceException("no StaticMethodsAroundInterceptor instance. ");
|
||||
|
||||
String interceptor = getStaticMethodsInterceptor();
|
||||
if (StringUtil.isEmpty(interceptor)) {
|
||||
throw new EnhanceException("no StaticMethodsAroundInterceptor define. ");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -178,5 +180,5 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract StaticMethodsAroundInterceptor getStaticMethodsInterceptor();
|
||||
protected abstract String getStaticMethodsInterceptor();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public abstract class ClassInstanceMethodsEnhancePluginDefine extends
|
|||
}
|
||||
|
||||
@Override
|
||||
protected StaticMethodsAroundInterceptor getStaticMethodsInterceptor() {
|
||||
protected String getStaticMethodsInterceptor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,17 @@ package com.ai.cloud.skywalking.plugin.interceptor.enhance;
|
|||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.loader.InterceptorInstanceLoader;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
|
||||
import net.bytebuddy.implementation.bind.annotation.*;
|
||||
import sun.tools.jar.resources.jar;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
|
|
@ -14,31 +22,25 @@ import java.util.concurrent.Callable;
|
|||
* @author wusheng
|
||||
*/
|
||||
public class ClassInstanceMethodsInterceptor {
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(ClassInstanceMethodsInterceptor.class);
|
||||
private static Logger logger = LogManager.getLogger(ClassInstanceMethodsInterceptor.class);
|
||||
|
||||
private InstanceMethodsAroundInterceptor interceptor;
|
||||
private String instanceMethodsAroundInterceptorClassName;
|
||||
|
||||
public ClassInstanceMethodsInterceptor(InstanceMethodsAroundInterceptor interceptor) {
|
||||
this.interceptor = interceptor;
|
||||
public ClassInstanceMethodsInterceptor(String instanceMethodsAroundInterceptorClassName) {
|
||||
this.instanceMethodsAroundInterceptorClassName = instanceMethodsAroundInterceptorClassName;
|
||||
}
|
||||
|
||||
@RuntimeType
|
||||
public Object intercept(
|
||||
@This Object obj,
|
||||
@AllArguments Object[] allArguments,
|
||||
@Origin Method method,
|
||||
@SuperCall Callable<?> zuper,
|
||||
@FieldValue(ClassEnhancePluginDefine.contextAttrName) EnhancedClassInstanceContext instanceContext)
|
||||
throws Exception {
|
||||
InstanceMethodInvokeContext interceptorContext = new InstanceMethodInvokeContext(obj,
|
||||
method.getName(), allArguments);
|
||||
public Object intercept(@This Object obj, @AllArguments Object[] allArguments, @Origin Method method, @SuperCall Callable<?> zuper,
|
||||
@FieldValue(ClassEnhancePluginDefine.contextAttrName) EnhancedClassInstanceContext instanceContext) throws Exception {
|
||||
InstanceMethodsAroundInterceptor interceptor = InterceptorInstanceLoader.load(instanceMethodsAroundInterceptorClassName, obj.getClass().getClassLoader());
|
||||
|
||||
InstanceMethodInvokeContext interceptorContext = new InstanceMethodInvokeContext(obj, method.getName(), allArguments);
|
||||
MethodInterceptResult result = new MethodInterceptResult();
|
||||
try {
|
||||
interceptor.beforeMethod(instanceContext, interceptorContext, result);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] before method[{}] intercept failue:{}",
|
||||
new Object[]{obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
logger.error("class[{}] before method[{}] intercept failue:{}", new Object[] {obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
}
|
||||
if (!result.isContinue()) {
|
||||
return result._ret();
|
||||
|
|
@ -51,16 +53,14 @@ public class ClassInstanceMethodsInterceptor {
|
|||
try {
|
||||
interceptor.handleMethodException(t, instanceContext, interceptorContext, ret);
|
||||
} catch (Throwable t2) {
|
||||
logger.error("class[{}] handle method[{}] exception failue:{}",
|
||||
new Object[]{obj.getClass(), method.getName(), t2.getMessage()}, t2);
|
||||
logger.error("class[{}] handle method[{}] exception failue:{}", new Object[] {obj.getClass(), method.getName(), t2.getMessage()}, t2);
|
||||
}
|
||||
throw t;
|
||||
} finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(instanceContext, interceptorContext, ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] after method[{}] intercept failue:{}",
|
||||
new Object[]{obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
logger.error("class[{}] after method[{}] intercept failue:{}", new Object[] {obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public abstract class ClassStaticMethodsEnhancePluginDefine extends
|
|||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsAroundInterceptor getInstanceMethodsInterceptor() {
|
||||
protected String getInstanceMethodsInterceptor() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.ai.cloud.skywalking.plugin.interceptor.enhance;
|
|||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.loader.InterceptorInstanceLoader;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.Origin;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
|
|
@ -18,14 +19,16 @@ import java.util.concurrent.Callable;
|
|||
public class ClassStaticMethodsInterceptor {
|
||||
private static Logger logger = LogManager.getLogger(ClassStaticMethodsInterceptor.class);
|
||||
|
||||
private StaticMethodsAroundInterceptor interceptor;
|
||||
private String staticMethodsAroundInterceptorClassName;
|
||||
|
||||
public ClassStaticMethodsInterceptor(StaticMethodsAroundInterceptor interceptor) {
|
||||
this.interceptor = interceptor;
|
||||
public ClassStaticMethodsInterceptor(String staticMethodsAroundInterceptorClassName) {
|
||||
this.staticMethodsAroundInterceptorClassName = staticMethodsAroundInterceptorClassName;
|
||||
}
|
||||
|
||||
@RuntimeType
|
||||
public Object intercept(@Origin Class<?> clazz, @AllArguments Object[] allArguments, @Origin Method method, @SuperCall Callable<?> zuper) throws Exception {
|
||||
StaticMethodsAroundInterceptor interceptor = InterceptorInstanceLoader.load(staticMethodsAroundInterceptorClassName, clazz.getClassLoader());
|
||||
|
||||
MethodInvokeContext interceptorContext = new MethodInvokeContext(method.getName(), allArguments);
|
||||
MethodInterceptResult result = new MethodInterceptResult();
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,138 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor.loader;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsInterceptor;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 16/8/2.
|
||||
*/
|
||||
public class InterceptorInstanceLoader {
|
||||
private static Logger logger = LogManager.getLogger(InterceptorInstanceLoader.class);
|
||||
|
||||
private static ConcurrentHashMap<String, Object> INSTANCE_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
private static ReentrantLock instanceLoadLock = new ReentrantLock();
|
||||
|
||||
public static <T> T load(String className, ClassLoader targetClassLoader)
|
||||
throws InvocationTargetException, IllegalAccessException, InstantiationException, ClassNotFoundException {
|
||||
if (InterceptorInstanceLoader.class.getClassLoader().equals(targetClassLoader)) {
|
||||
return (T) targetClassLoader.loadClass(className).newInstance();
|
||||
}
|
||||
|
||||
String instanceKey = className + "_OF_" + targetClassLoader.getClass().getName() + "@" + Integer.toHexString(targetClassLoader.hashCode());
|
||||
Object inst = INSTANCE_CACHE.get(instanceKey);
|
||||
if (inst != null) {
|
||||
return (T) inst;
|
||||
}
|
||||
instanceLoadLock.lock();
|
||||
try {
|
||||
try {
|
||||
inst = findLoadedClass(className, targetClassLoader);
|
||||
if (inst == null) {
|
||||
inst = loadBinary(className, targetClassLoader);
|
||||
}
|
||||
if (inst == null) {
|
||||
throw new ClassNotFoundException(targetClassLoader.toString() + " load interceptor class:" + className + " failure.");
|
||||
}
|
||||
INSTANCE_CACHE.put(instanceKey, inst);
|
||||
return (T) inst;
|
||||
} catch (Exception e) {
|
||||
throw new ClassNotFoundException(targetClassLoader.toString() + " load interceptor class:" + className + " failure.", e);
|
||||
}
|
||||
} finally
|
||||
|
||||
{
|
||||
instanceLoadLock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过二进制读取,直接加载类文件,然后通过上下文所需的classLoader强制加载
|
||||
*
|
||||
* @param className
|
||||
* @param targetClassLoader
|
||||
* @param <T>
|
||||
* @return
|
||||
* @throws InvocationTargetException
|
||||
* @throws IllegalAccessException
|
||||
* @throws InstantiationException
|
||||
*/
|
||||
private static <T> T loadBinary(String className, ClassLoader targetClassLoader) throws InvocationTargetException, IllegalAccessException, InstantiationException {
|
||||
String path = "/" + className.replace('.', '/').concat(".class");
|
||||
byte[] data = null;
|
||||
BufferedInputStream is = null;
|
||||
ByteArrayOutputStream baos = null;
|
||||
try {
|
||||
is = new BufferedInputStream(InterceptorInstanceLoader.class.getResourceAsStream(path));
|
||||
baos = new ByteArrayOutputStream();
|
||||
int ch = 0;
|
||||
while ((ch = is.read()) != -1) {
|
||||
baos.write(ch);
|
||||
}
|
||||
data = baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
if (is != null)
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
if (baos != null)
|
||||
try {
|
||||
baos.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
Method defineClassMethod = null;
|
||||
Class<?> targetClassLoaderType = targetClassLoader.getClass();
|
||||
while (defineClassMethod == null && targetClassLoaderType != null) {
|
||||
try {
|
||||
defineClassMethod = targetClassLoaderType.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class, ProtectionDomain.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
targetClassLoaderType = targetClassLoaderType.getSuperclass();
|
||||
}
|
||||
}
|
||||
defineClassMethod.setAccessible(true);
|
||||
Class<?> type = (Class<?>) defineClassMethod.invoke(targetClassLoader, className, data, 0, data.length, null);
|
||||
return (T) type.newInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 在当前classloader中查找是否已经加载此类。
|
||||
*
|
||||
* @param className
|
||||
* @param targetClassLoader
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
private static <T> T findLoadedClass(String className, ClassLoader targetClassLoader) throws InvocationTargetException, IllegalAccessException, InstantiationException {
|
||||
Method defineClassMethod = null;
|
||||
Class<?> targetClassLoaderType = targetClassLoader.getClass();
|
||||
while (defineClassMethod == null && targetClassLoaderType != null) {
|
||||
try {
|
||||
defineClassMethod = targetClassLoaderType.getDeclaredMethod("findLoadedClass", String.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
targetClassLoaderType = targetClassLoaderType.getSuperclass();
|
||||
}
|
||||
}
|
||||
defineClassMethod.setAccessible(true);
|
||||
Class<?> type = (Class<?>) defineClassMethod.invoke(targetClassLoader, className);
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
return (T) type.newInstance();
|
||||
}
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ public class ExclusionMatcherTest extends TestCase {
|
|||
DynamicType.Builder<?> newClassBuilder =
|
||||
new ByteBuddy().rebase(TypePool.Default.ofClassPath().describe(entry.getKey()).resolve(), ClassFileLocator.ForClassLoader.ofClassPath());
|
||||
|
||||
newClassBuilder = entry.getValue().define(newClassBuilder);
|
||||
newClassBuilder = entry.getValue().define(entry.getKey(), newClassBuilder);
|
||||
newClassBuilder.make().load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.INJECTION).getLoaded();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package test.ai.cloud.matcher;
|
|||
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.matcher.PrivateMethodMatcher;
|
||||
|
||||
/**
|
||||
|
|
@ -28,7 +27,7 @@ public class TestMatcherDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsAroundInterceptor getInstanceMethodsInterceptor() {
|
||||
return new TestAroundInterceptor();
|
||||
protected String getInstanceMethodsInterceptor() {
|
||||
return "test.ai.cloud.matcher.TestMatcherDefine";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package test.ai.cloud.plugin;
|
|||
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassEnhancePluginDefine;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.StaticMethodsAroundInterceptor;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
|
||||
|
|
@ -19,8 +18,8 @@ public class TestInterceptorDefine extends ClassEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InstanceMethodsAroundInterceptor getInstanceMethodsInterceptor() {
|
||||
return new TestAroundInterceptor();
|
||||
public String getInstanceMethodsInterceptor() {
|
||||
return "test.ai.cloud.plugin.TestAroundInterceptor";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -29,8 +28,8 @@ public class TestInterceptorDefine extends ClassEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected StaticMethodsAroundInterceptor getStaticMethodsInterceptor() {
|
||||
return new TestStaticAroundInterceptor();
|
||||
protected String getStaticMethodsInterceptor() {
|
||||
return "test.ai.cloud.plugin.TestStaticAroundInterceptor";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ public class DubboPluginDefine extends ClassStaticMethodsEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected StaticMethodsAroundInterceptor getStaticMethodsInterceptor() {
|
||||
return new ProtocolFilterBuildChainInterceptor();
|
||||
protected String getStaticMethodsInterceptor() {
|
||||
return "com.ai.cloud.skywalking.plugin.dubbo.ProtocolFilterBuildChainInterceptor";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class ProtocolFilterBuildChainInterceptor implements StaticMethodsAroundI
|
|||
final Invoker<?> invoker = (Invoker<?>)args[0];
|
||||
String key = (String)args[1];
|
||||
String group = (String)args[2];
|
||||
|
||||
|
||||
final URL newURL = invoker.getUrl().addParameter(key, "skywalking$enhanceFilter");
|
||||
Invoker<?> last = invoker;
|
||||
List<Filter> filters = ExtensionLoader.getExtensionLoader(Filter.class).getActivateExtension(newURL, key, group);
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@ package com.ai.cloud.skywalking.httpClient.v4.plugin.define;
|
|||
import com.ai.cloud.skywalking.httpClient.v4.plugin.HttpClientExecuteInterceptor;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
|
||||
public abstract class HttpClientPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
||||
@Override
|
||||
public InstanceMethodsAroundInterceptor getInstanceMethodsInterceptor() {
|
||||
return new HttpClientExecuteInterceptor();
|
||||
public String getInstanceMethodsInterceptor() {
|
||||
return "com.ai.cloud.skywalking.httpClient.v4.plugin.HttpClientExecuteInterceptor";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.ai.cloud.skywalking.jedis.v2.plugin.define;
|
|||
import com.ai.cloud.skywalking.jedis.v2.plugin.JedisClusterInterceptor;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.matcher.AnyMethodsMatcher;
|
||||
|
||||
public class JedisClusterPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
|
|
@ -21,7 +20,7 @@ public class JedisClusterPluginDefine extends ClassInstanceMethodsEnhancePluginD
|
|||
}
|
||||
|
||||
@Override
|
||||
public InstanceMethodsAroundInterceptor getInstanceMethodsInterceptor() {
|
||||
return new JedisClusterInterceptor();
|
||||
public String getInstanceMethodsInterceptor() {
|
||||
return "com.ai.cloud.skywalking.jedis.v2.plugin.JedisClusterInterceptor";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.ai.cloud.skywalking.jedis.v2.plugin.define;
|
|||
import com.ai.cloud.skywalking.jedis.v2.plugin.JedisInterceptor;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.matcher.MethodsExclusiveMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.matcher.PrivateMethodMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
|
|
@ -32,8 +31,8 @@ public class JedisPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public InstanceMethodsAroundInterceptor getInstanceMethodsInterceptor() {
|
||||
return new JedisInterceptor();
|
||||
public String getInstanceMethodsInterceptor() {
|
||||
return "com.ai.cloud.skywalking.jedis.v2.plugin.JedisInterceptor";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,24 @@
|
|||
package com.ai.cloud.skywalking.plugin.tomcat78x.define;
|
||||
|
||||
import com.ai.cloud.skywalking.logging.LogManager;
|
||||
import com.ai.cloud.skywalking.logging.Logger;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
import com.ai.cloud.skywalking.plugin.tomcat78x.TomcatPluginInterceptor;
|
||||
import org.apache.catalina.connector.Request;
|
||||
import org.apache.catalina.connector.Response;
|
||||
|
||||
public class TomcatPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
private static Logger logger = LogManager.getLogger(TomcatPluginDefine.class);
|
||||
|
||||
@Override
|
||||
protected MethodMatcher[] getInstanceMethodsMatchers() {
|
||||
|
||||
return new MethodMatcher[]{new SimpleMethodMatcher("invoke", Request.class, Response.class)};
|
||||
return new MethodMatcher[]{new SimpleMethodMatcher("invoke")};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InstanceMethodsAroundInterceptor getInstanceMethodsInterceptor() {
|
||||
return new TomcatPluginInterceptor();
|
||||
protected String getInstanceMethodsInterceptor() {
|
||||
return "com.ai.cloud.skywalking.plugin.tomcat78x.TomcatPluginInterceptor";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue