diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisClusterConstructorInterceptor4HostAndPortArg.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisClusterConstructorInterceptor4HostAndPortArg.java deleted file mode 100644 index 021e2ac66..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisClusterConstructorInterceptor4HostAndPortArg.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jedis.v2; - -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import redis.clients.jedis.HostAndPort; - -import static com.a.eye.skywalking.api.plugin.jedis.v2.JedisMethodInterceptor.REDIS_CONN_INFO_KEY; - -/** - * Created by xin on 16-6-12. - */ -public class JedisClusterConstructorInterceptor4HostAndPortArg implements InstanceConstructorInterceptor { - @Override - public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { - StringBuilder redisConnInfo = new StringBuilder(); - HostAndPort hostAndPort = (HostAndPort) interceptorContext.allArguments()[0]; - redisConnInfo.append(hostAndPort.toString()).append(";"); - context.set(REDIS_CONN_INFO_KEY, redisConnInfo.toString()); - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisClusterConstructorInterceptor4SetArg.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisClusterConstructorInterceptor4SetArg.java deleted file mode 100644 index 17a098eb7..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisClusterConstructorInterceptor4SetArg.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jedis.v2; - -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext; - -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import redis.clients.jedis.HostAndPort; - -import java.util.Set; - -import static com.a.eye.skywalking.api.plugin.jedis.v2.JedisMethodInterceptor.REDIS_CONN_INFO_KEY; - -/** - * Created by xin on 16-6-12. - */ -public class JedisClusterConstructorInterceptor4SetArg implements InstanceConstructorInterceptor { - @Override - public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { - StringBuilder redisConnInfo = new StringBuilder(); - Set hostAndPorts = (Set) interceptorContext.allArguments()[0]; - for (HostAndPort hostAndPort : hostAndPorts) { - redisConnInfo.append(hostAndPort.toString()).append(";"); - } - context.set(REDIS_CONN_INFO_KEY, redisConnInfo.toString()); - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4ShardInfoArg.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4ShardInfoArg.java deleted file mode 100644 index b0f3a1580..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4ShardInfoArg.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jedis.v2; - -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; -import redis.clients.jedis.JedisShardInfo; - -import static com.a.eye.skywalking.api.plugin.jedis.v2.JedisMethodInterceptor.REDIS_CONN_INFO_KEY; - -/** - * Created by wusheng on 2016/12/1. - */ -public class JedisConstructorInterceptor4ShardInfoArg implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { - String redisConnInfo; - JedisShardInfo shardInfo = (JedisShardInfo) interceptorContext.allArguments()[0]; - redisConnInfo = shardInfo.getHost() + ":" + shardInfo.getPort(); - context.set(REDIS_CONN_INFO_KEY, redisConnInfo); - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4StringArg.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4StringArg.java deleted file mode 100644 index 9ead9a34a..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4StringArg.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jedis.v2; - -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -import static com.a.eye.skywalking.api.plugin.jedis.v2.JedisMethodInterceptor.REDIS_CONN_INFO_KEY; - -public class JedisConstructorInterceptor4StringArg implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { - String redisConnInfo; - redisConnInfo = (String) interceptorContext.allArguments()[0]; - if (interceptorContext.allArguments().length > 1) { - redisConnInfo += ":" + interceptorContext.allArguments()[1]; - } - context.set(REDIS_CONN_INFO_KEY, redisConnInfo); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4UriArg.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4UriArg.java deleted file mode 100644 index 273d28075..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4UriArg.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jedis.v2; - -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; - -import java.net.URI; - -import static com.a.eye.skywalking.api.plugin.jedis.v2.JedisMethodInterceptor.REDIS_CONN_INFO_KEY; - -/** - * Created by wusheng on 2016/12/1. - */ -public class JedisConstructorInterceptor4UriArg implements InstanceConstructorInterceptor { - - @Override - public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { - String redisConnInfo; - URI uri = (URI) interceptorContext.allArguments()[0]; - redisConnInfo = uri.getHost() + ":" + uri.getPort(); - context.set(REDIS_CONN_INFO_KEY, redisConnInfo); - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisMethodInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisMethodInterceptor.java deleted file mode 100644 index 874d12a28..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisMethodInterceptor.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jedis.v2; - -import com.a.eye.skywalking.model.Identification; -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.assist.NoCocurrencyAceessObject; -import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; - -public class JedisMethodInterceptor extends NoCocurrencyAceessObject { - protected static final String REDIS_CONN_INFO_KEY = "redisClusterConnInfo"; - - - @Override - public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { - this.whenEnter(context, new Runnable() { - @Override public void run() { - /** - * redis server wouldn't process rpc context. ignore the - * return(ContextData) of sender's beforeSend - */ - Identification.IdentificationBuilder builder = Identification - .newBuilder() - .viewPoint( - context.get(REDIS_CONN_INFO_KEY, String.class) - + " " + interceptorContext.methodName()) - .spanType(RedisBuriedPointType.INSTANCE); - if (interceptorContext.allArguments().length > 0 - && interceptorContext.allArguments()[0] instanceof String) { - builder.businessKey("key=" - + interceptorContext.allArguments()[0]); - } - rpcClientInvokeMonitor.beforeInvoke(builder.build()); - } - }); - } - - @Override - public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) { - this.whenExist(context, new Runnable(){ - @Override public void run() { - rpcClientInvokeMonitor.afterInvoke(); - } - }); - - return ret; - } - - @Override - public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) { - rpcClientInvokeMonitor.occurException(t); - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/RedisBuriedPointType.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/RedisBuriedPointType.java deleted file mode 100644 index 3153d27e8..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/RedisBuriedPointType.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jedis.v2; - -import com.a.eye.skywalking.api.IBuriedPointType; - -public enum RedisBuriedPointType implements IBuriedPointType { - INSTANCE; - - @Override - public String getTypeName() { - return "Redis"; - } - - @Override - public CallType getCallType() { - return CallType.SYNC; - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/define/JedisClusterPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/define/JedisClusterPluginDefine.java deleted file mode 100644 index cfebfb463..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/define/JedisClusterPluginDefine.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jedis.v2.define; - -import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.bytebuddy.AllObjectDefaultMethodsMatch; -import com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch; -import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import java.util.Set; - -import static com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static net.bytebuddy.matcher.ElementMatchers.*; - -public class JedisClusterPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { - - @Override - public String enhanceClassName() { - return "redis.clients.jedis.JedisCluster"; - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] {new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgument(0, Set.class); - } - - @Override - public String getConstructorInterceptor() { - return "com.a.eye.skywalking.plugin.jedis.v2.JedisClusterConstructorInterceptor4SetArg"; - } - }, new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgumentWithType(0, "redis.clients.jedis.HostAndPort"); - } - - @Override - public String getConstructorInterceptor() { - return "com.a.eye.skywalking.plugin.jedis.v2.JedisClusterConstructorInterceptor4HostAndPortArg"; - } - }}; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return any().and(not(AllObjectDefaultMethodsMatch.INSTANCE)); - } - - @Override - public String getMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor"; - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/define/JedisPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/define/JedisPluginDefine.java deleted file mode 100644 index d4085b551..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/define/JedisPluginDefine.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jedis.v2.define; - -import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint; -import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.bytebuddy.AllObjectDefaultMethodsMatch; -import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; -import net.bytebuddy.matcher.ElementMatchers; - -import java.net.URI; - -import static com.a.eye.skywalking.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static net.bytebuddy.matcher.ElementMatchers.*; - -public class JedisPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { - - @Override - public String enhanceClassName() { - return "redis.clients.jedis.Jedis"; - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] {new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgument(0, String.class); - } - - @Override - public String getConstructorInterceptor() { - return "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorInterceptor4StringArg"; - } - }, new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgumentWithType(0, "redis.clients.jedis.HostAndPort"); - } - - @Override - public String getConstructorInterceptor() { - return "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorInterceptor4ShardInfoArgg"; - } - }, new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return takesArgument(0, URI.class); - } - - @Override - public String getConstructorInterceptor() { - return "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorInterceptor4UriArg"; - } - }}; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return not(ElementMatchers.isPrivate() - .or(AllObjectDefaultMethodsMatch.INSTANCE) - .or(named("close")) - .or(named("getDB")) - .or(named("connect")) - .or(named("setDataSource")) - .or(named("resetState")) - .or(named("clusterSlots")) - .or(named("checkIsInMultiOrPipeline"))); - } - - @Override - public String getMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor"; - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java new file mode 100644 index 000000000..661c65087 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java @@ -0,0 +1,28 @@ +package com.a.eye.skywalking.plugin.jedis.v2; + +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +import redis.clients.jedis.HostAndPort; + +import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO; +import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_HOSTS; + +/** + * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} will record the host and port information that fetch + * from {@link HostAndPort} into {@link EnhancedClassInstanceContext#context}, and each host and port will spilt ;. + * + * @author zhangxin + */ +public class JedisClusterConstructorWithHostAndPortArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { + StringBuilder redisConnInfo = new StringBuilder(); + HostAndPort hostAndPort = (HostAndPort) interceptorContext.allArguments()[0]; + redisConnInfo.append(hostAndPort.toString()).append(";"); + context.set(KEY_OF_REDIS_CONN_INFO, redisConnInfo.toString()); + context.set(KEY_OF_REDIS_HOSTS, hostAndPort.getHost()); + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java new file mode 100644 index 000000000..1f4ef4650 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java @@ -0,0 +1,30 @@ +package com.a.eye.skywalking.plugin.jedis.v2; + +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +import java.util.Set; + +import redis.clients.jedis.HostAndPort; + +/** + * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} will record the host and port information that fetch + * from {@link HostAndPort} collector into {@link EnhancedClassInstanceContext#context}, and each host and port will spilt ;. + * + * @author zhangxin + */ +public class JedisClusterConstructorWithListHostAndPortArgInterceptor implements InstanceConstructorInterceptor { + @Override + public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { + StringBuilder redisConnInfo = new StringBuilder(); + StringBuilder redisHost = new StringBuilder(); + Set hostAndPorts = (Set) interceptorContext.allArguments()[0]; + for (HostAndPort hostAndPort : hostAndPorts) { + redisConnInfo.append(hostAndPort.toString()).append(";"); + redisHost.append(hostAndPort.getHost()).append(";"); + } + context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo.toString()); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, redisHost); + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java new file mode 100644 index 000000000..25edc5591 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java @@ -0,0 +1,25 @@ +package com.a.eye.skywalking.plugin.jedis.v2; + +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +import redis.clients.jedis.JedisShardInfo; + +/** + * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} will record the host and port information that fetch + * from {@link JedisShardInfo} argument into {@link EnhancedClassInstanceContext#context}. + * + * @author zhangxin + */ +public class JedisConstructorWithShardInfoArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { + String redisConnInfo; + JedisShardInfo shardInfo = (JedisShardInfo) interceptorContext.allArguments()[0]; + redisConnInfo = shardInfo.getHost() + ":" + shardInfo.getPort(); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, shardInfo.getHost()); + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java new file mode 100644 index 000000000..c01440ff0 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java @@ -0,0 +1,26 @@ +package com.a.eye.skywalking.plugin.jedis.v2; + +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +/** + * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} will record the host and port information that fetch + * from string argument into {@link EnhancedClassInstanceContext#context}. + * + * @author zhangxin + */ +public class JedisConstructorWithStringArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { + String redisConnInfo; + redisConnInfo = (String) interceptorContext.allArguments()[0]; + if (interceptorContext.allArguments().length > 1) { + redisConnInfo += ":" + interceptorContext.allArguments()[1]; + } + context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, interceptorContext.allArguments()[0]); + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java new file mode 100644 index 000000000..25599a212 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java @@ -0,0 +1,25 @@ +package com.a.eye.skywalking.plugin.jedis.v2; + +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; + +import java.net.URI; + +/** + * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} will record the host and port information that fetch + * from {@link URI} argument into {@link EnhancedClassInstanceContext#context}. + * + * @author zhangxin + */ +public class JedisConstructorWithUriArgInterceptor implements InstanceConstructorInterceptor { + + @Override + public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { + String redisConnInfo; + URI uri = (URI) interceptorContext.allArguments()[0]; + redisConnInfo = uri.getHost() + ":" + uri.getPort(); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, uri.getHost()); + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java new file mode 100644 index 000000000..377f78cae --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java @@ -0,0 +1,60 @@ +package com.a.eye.skywalking.plugin.jedis.v2; + +import com.a.eye.skywalking.api.context.ContextManager; +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.api.plugin.interceptor.assist.NoCocurrencyAceessObject; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; +import com.a.eye.skywalking.trace.Span; +import com.a.eye.skywalking.trace.tag.Tags; + +/** + * {@link JedisMethodInterceptor} create span and set redis host and redis connection information + * from {@link EnhancedClassInstanceContext#context} to span tags. + * + * @author zhangxin + */ +public class JedisMethodInterceptor extends NoCocurrencyAceessObject { + /** + * The key name that redis connection information in {@link EnhancedClassInstanceContext#context}. + */ + protected static final String KEY_OF_REDIS_CONN_INFO = "REDIS_CONNECTION_INFO"; + /** + * The key name that redis host in {@link EnhancedClassInstanceContext#context}. + */ + protected static final String KEY_OF_REDIS_HOSTS = "KEY_OF_REDIS_HOSTS"; + + @Override + public void beforeMethod(final EnhancedClassInstanceContext context, final InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { + this.whenEnter(context, new Runnable() { + @Override + public void run() { + Span span = ContextManager.INSTANCE.createSpan(context.get(KEY_OF_REDIS_CONN_INFO, String.class) + " " + interceptorContext.methodName()); + Tags.COMPONENT.set(span, "Redis"); + Tags.PEER_HOST.set(span, (String) context.get(KEY_OF_REDIS_HOSTS)); + + Tags.SPAN_LAYER.asDB(span); + if (interceptorContext.allArguments().length > 0 + && interceptorContext.allArguments()[0] instanceof String) { + span.setTag("operation_key", (String) interceptorContext.allArguments()[0]); + } + } + }); + } + + @Override + public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) { + this.whenExist(context, new Runnable() { + @Override + public void run() { + ContextManager.INSTANCE.stopSpan(); + } + }); + return ret; + } + + @Override + public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) { + ContextManager.INSTANCE.activeSpan().log(t); + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisClusterInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisClusterInstrumentation.java new file mode 100644 index 000000000..b31c7f487 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisClusterInstrumentation.java @@ -0,0 +1,97 @@ +package com.a.eye.skywalking.plugin.jedis.v2.define; + +import com.a.eye.skywalking.api.plugin.bytebuddy.AllObjectDefaultMethodsMatch; +import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint; +import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import com.a.eye.skywalking.plugin.jedis.v2.JedisClusterConstructorWithListHostAndPortArgInterceptor; +import com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import java.util.Set; + +import static com.a.eye.skywalking.api.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.not; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; + +/** + * {@link JedisClusterInstrumentation} presents that skywalking will intercept all constructors and methods of {@link redis.clients.jedis.JedisCluster}. + * There are two intercept classes to intercept the constructor of {@link redis.clients.jedis.JedisCluster}. + * {@link com.a.eye.skywalking.plugin.jedis.v2.JedisClusterConstructorWithHostAndPortArgInterceptor} intercepts all constructor with argument {@link redis.clients.jedis.HostAndPort} + * and the other constructor will intercept by class {@link JedisClusterConstructorWithListHostAndPortArgInterceptor}. + * {@link JedisMethodInterceptor} will intercept all methods of {@link redis.clients.jedis.JedisCluster} + * + * @author zhangxin + */ +public class JedisClusterInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + /** + * {@link redis.clients.jedis.HostAndPort} argument type name + */ + private static final String ARGUMENT_TYPE_NAME = "redis.clients.jedis.HostAndPort"; + /** + * Enhance class + */ + private static final String ENHANCE_CLASS = "redis.clients.jedis.JedisCluster"; + /** + * Class that intercept all constructors with arg. + */ + private static final String CONSTRUCTOR_WITH_LIST_HOSTANDPORT_ARG_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jedis.v2.JedisClusterConstructorWithListHostAndPortArgInterceptor"; + /** + * Class that intercept all methods. + */ + private static final String METHOD_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor"; + /** + * Class that intercept all constructors with {@link redis.clients.jedis.HostAndPort} + */ + private static final String CONSTRUCTOR_WITH_HOSTANDPORT_ARG_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jedis.v2.JedisClusterConstructorWithHostAndPortArgInterceptor"; + + + @Override + public String enhanceClassName() { + return ENHANCE_CLASS; + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[]{new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgument(0, Set.class); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_LIST_HOSTANDPORT_ARG_INTERCEPT_CLASS; + } + }, new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgumentWithType(0, ARGUMENT_TYPE_NAME); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_HOSTANDPORT_ARG_INTERCEPT_CLASS; + } + }}; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return any().and(not(AllObjectDefaultMethodsMatch.INSTANCE)); + } + + @Override + public String getMethodsInterceptor() { + return METHOD_INTERCEPT_CLASS; + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisInstrumentation.java new file mode 100644 index 000000000..ee9def3c2 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisInstrumentation.java @@ -0,0 +1,117 @@ +package com.a.eye.skywalking.plugin.jedis.v2.define; + +import com.a.eye.skywalking.api.plugin.bytebuddy.AllObjectDefaultMethodsMatch; +import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint; +import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorWithUriArgInterceptor; +import com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorWithShardInfoArgInterceptor; +import com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import net.bytebuddy.matcher.ElementMatchers; + +import java.net.URI; + +import static com.a.eye.skywalking.api.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.not; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; + +/** + * {@link JedisInstrumentation} presents that skywalking will intercept all constructors and methods of {@link redis.clients.jedis.Jedis}. + * There are three intercept classes to intercept the constructor of {@link redis.clients.jedis.Jedis}. + * {@link JedisConstructorWithShardInfoArgInterceptor} intercepts all constructor with argument {@link redis.clients.jedis.HostAndPort} + * ,the constructors with uri will intercept by class {@link JedisConstructorWithUriArgInterceptor} and + * the other constructor will intercept by class {@link JedisConstructorWithShardInfoArgInterceptor}. + * {@link JedisMethodInterceptor} will intercept all methods of {@link redis.clients.jedis.Jedis}. + * + * @author zhangxin + */ +public class JedisInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + /** + * {@link redis.clients.jedis.HostAndPort} argument type name + */ + private static final String HOST_AND_PROT_ARG_TYPE_NAME = "redis.clients.jedis.HostAndPort"; + /** + * Enhance class + */ + private static final String ENHANCE_CLASS = "redis.clients.jedis.Jedis"; + /** + * Class that intercept all constructors with string arg + */ + private static final String CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorWithStringArgInterceptor"; + /** + * Class that intercept all constructors with shard info + */ + private static final String CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorWithShardInfoArgInterceptor"; + /** + * Class that intercept all constructors with uri arg + */ + private static final String CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorWithUriArgInterceptor"; + + @Override + public String enhanceClassName() { + return ENHANCE_CLASS; + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[]{new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgument(0, String.class); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS; + } + }, new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgumentWithType(0, HOST_AND_PROT_ARG_TYPE_NAME); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS; + } + }, new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return takesArgument(0, URI.class); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS; + } + }}; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return not(ElementMatchers.isPrivate() + .or(AllObjectDefaultMethodsMatch.INSTANCE) + .or(named("close")) + .or(named("getDB")) + .or(named("connect")) + .or(named("setDataSource")) + .or(named("resetState")) + .or(named("clusterSlots")) + .or(named("checkIsInMultiOrPipeline"))); + } + + @Override + public String getMethodsInterceptor() { + return "com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor"; + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/resources/skywalking-plugin.def index de54ba9fd..9876bd990 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/resources/skywalking-plugin.def +++ b/skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,2 @@ -com.a.eye.skywalking.plugin.jedis.v2.define.JedisPluginDefine -com.a.eye.skywalking.plugin.jedis.v2.define.JedisClusterPluginDefine +com.a.eye.skywalking.plugin.jedis.v2.define.JedisClusterInstrumentation +com.a.eye.skywalking.plugin.jedis.v2.define.JedisInstrumentation