From a86266b8d5078f735c0120e2483e4e9299450f9c Mon Sep 17 00:00:00 2001 From: zhangxin Date: Tue, 21 Feb 2017 17:30:48 +0800 Subject: [PATCH 01/12] Modify the Dubbo plugin using the new API --- .../plugin/dubbo/DubboBuriedPointType.java | 18 -- .../api/plugin/dubbo/DubboPluginDefine.java | 36 --- .../dubbo/MonitorFilterInterceptor.java | 155 ------------ .../dubbox/bugfix/below283/BugFixAcitve.java | 9 - .../dubbox/bugfix/below283/SWBaseBean.java | 15 -- .../plugin/dubbo/DubboInstrumentation.java | 56 +++++ .../plugin/dubbo/DubboInterceptor.java | 202 ++++++++++++++++ .../plugin/dubbox/BugFixActive.java | 26 ++ .../skywalking/plugin/dubbox/SWBaseBean.java | 24 ++ .../plugin/dubbo/DubboInterceptorTest.java | 228 ++++++++++++++++++ .../dubbo/RequestParamForTestBelow283.java | 24 ++ 11 files changed, 560 insertions(+), 233 deletions(-) delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/DubboBuriedPointType.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/DubboPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/MonitorFilterInterceptor.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbox/bugfix/below283/BugFixAcitve.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbox/bugfix/below283/SWBaseBean.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/DubboBuriedPointType.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/DubboBuriedPointType.java deleted file mode 100644 index d165ae736..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/DubboBuriedPointType.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.a.eye.skywalking.api.plugin.dubbo; - -import com.a.eye.skywalking.api.IBuriedPointType; - -public enum DubboBuriedPointType implements IBuriedPointType { - INSTANCE; - - @Override - public String getTypeName() { - return "D"; - } - - @Override - public CallType getCallType() { - return CallType.SYNC; - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/DubboPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/DubboPluginDefine.java deleted file mode 100644 index 90a1eaf95..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/DubboPluginDefine.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.a.eye.skywalking.api.plugin.dubbo; - -import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; -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 static net.bytebuddy.matcher.ElementMatchers.named; - -public class DubboPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { - @Override - protected String enhanceClassName() { - return "com.alibaba.dubbo.monitor.support.MonitorFilter"; - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("invoke"); - } - - @Override - public String getMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.dubbo.MonitorFilterInterceptor"; - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/MonitorFilterInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/MonitorFilterInterceptor.java deleted file mode 100644 index 22e01ebf6..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbo/MonitorFilterInterceptor.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.a.eye.skywalking.api.plugin.dubbo; - -import com.a.eye.skywalking.api.plugin.dubbox.bugfix.below283.BugFixAcitve; -import com.a.eye.skywalking.api.plugin.dubbox.bugfix.below283.SWBaseBean; -import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor; -import com.a.eye.skywalking.invoke.monitor.RPCServerInvokeMonitor; -import com.a.eye.skywalking.model.ContextData; -import com.a.eye.skywalking.model.Identification; -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; -import com.alibaba.dubbo.rpc.Invocation; -import com.alibaba.dubbo.rpc.Invoker; -import com.alibaba.dubbo.rpc.Result; -import com.alibaba.dubbo.rpc.RpcContext; - -public class MonitorFilterInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, - MethodInterceptResult result) { - Object[] arguments = interceptorContext.allArguments(); - Invoker invoker = (Invoker) arguments[0]; - Invocation invocation = (Invocation) arguments[1]; - - RpcContext rpcContext = RpcContext.getContext(); - boolean isConsumer = rpcContext.isConsumerSide(); - context.set("isConsumer", isConsumer); - if (isConsumer) { - ContextData contextData = - new RPCClientInvokeMonitor().beforeInvoke(createIdentification(invoker, invocation, true)); - String contextDataStr = contextData.toString(); - - //追加参数 - if (!BugFixAcitve.isActive) { - // context.setAttachment("contextData", contextDataStr); - // context的setAttachment方法在重试机制的时候并不会覆盖原有的Attachment - // 参见Dubbo源代码:“com.alibaba.dubbo.rpc.RpcInvocation” - // public void setAttachmentIfAbsent(String key, String value) { - // if (attachments == null) { - // attachments = new HashMap(); - // } - // if (! attachments.containsKey(key)) { - // attachments.put(key, value); - // } - // } - // 在Rest模式中attachment会被抹除,不会传入到服务端 - // Rest模式会将attachment存放到header里面,具体见com.alibaba.dubbo.rpc.protocol.rest.RpcContextFilter - //invocation.getAttachments().put("contextData", contextDataStr); - rpcContext.getAttachments().put("contextData", contextDataStr); - } else { - fix283SendNoAttachmentIssue(invocation, contextDataStr); - } - } else { - // 读取参数 - String contextDataStr; - - if (!BugFixAcitve.isActive) { - contextDataStr = rpcContext.getAttachment("contextData"); - } else { - contextDataStr = fix283RecvNoAttachmentIssue(invocation); - } - - ContextData contextData = null; - if (contextDataStr != null && contextDataStr.length() > 0) { - contextData = new ContextData(contextDataStr); - } - - new RPCServerInvokeMonitor().beforeInvoke(contextData, createIdentification(invoker, invocation, false)); - } - - } - - @Override - public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, - Object ret) { - Result result = (Result) ret; - if (result != null && result.getException() != null) { - dealException(result.getException(), context); - } - - if (isConsumer(context)) { - new RPCClientInvokeMonitor().afterInvoke(); - } else { - new RPCServerInvokeMonitor().afterInvoke(); - } - - return ret; - } - - @Override - public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, - InstanceMethodInvokeContext interceptorContext) { - dealException(t, context); - } - - - private boolean isConsumer(EnhancedClassInstanceContext context) { - return (Boolean) context.get("isConsumer"); - } - - private void dealException(Throwable t, EnhancedClassInstanceContext context) { - if (isConsumer(context)) { - new RPCClientInvokeMonitor().occurException(t); - } else { - new RPCServerInvokeMonitor().occurException(t); - } - } - - private static Identification createIdentification(Invoker invoker, Invocation invocation, boolean isConsumer) { - StringBuilder viewPoint = new StringBuilder(); - if (isConsumer) { - viewPoint.append("comsumer:"); - } else { - viewPoint.append("provider:"); - } - viewPoint.append(invoker.getUrl().getProtocol() + "://"); - viewPoint.append(invoker.getUrl().getHost()); - viewPoint.append(":" + invoker.getUrl().getPort()); - viewPoint.append(invoker.getUrl().getAbsolutePath()); - viewPoint.append("." + invocation.getMethodName() + "("); - for (Class classes : invocation.getParameterTypes()) { - viewPoint.append(classes.getSimpleName() + ","); - } - - if (invocation.getParameterTypes().length > 0) { - viewPoint.delete(viewPoint.length() - 1, viewPoint.length()); - } - - viewPoint.append(")"); - return Identification.newBuilder().viewPoint(viewPoint.toString()).spanType(DubboBuriedPointType.INSTANCE) - .build(); - } - - - private static void fix283SendNoAttachmentIssue(Invocation invocation, String contextDataStr) { - - for (Object parameter : invocation.getArguments()) { - if (parameter instanceof SWBaseBean) { - ((SWBaseBean) parameter).setContextData(contextDataStr); - return; - } - } - } - - private static String fix283RecvNoAttachmentIssue(Invocation invocation) { - for (Object parameter : invocation.getArguments()) { - if (parameter instanceof SWBaseBean) { - return ((SWBaseBean) parameter).getContextData(); - } - } - - return null; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbox/bugfix/below283/BugFixAcitve.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbox/bugfix/below283/BugFixAcitve.java deleted file mode 100644 index 735c6868e..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbox/bugfix/below283/BugFixAcitve.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.a.eye.skywalking.api.plugin.dubbox.bugfix.below283; - -public final class BugFixAcitve { - public static boolean isActive = false; - - public BugFixAcitve(){ - isActive = true; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbox/bugfix/below283/SWBaseBean.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbox/bugfix/below283/SWBaseBean.java deleted file mode 100644 index 42dca3074..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/api/plugin/dubbox/bugfix/below283/SWBaseBean.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.a.eye.skywalking.api.plugin.dubbox.bugfix.below283; - -import java.io.Serializable; - -public class SWBaseBean implements Serializable { - private String contextData; - - public String getContextData() { - return contextData; - } - - public void setContextData(String contextData) { - this.contextData = contextData; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java new file mode 100644 index 000000000..2f65c34e1 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java @@ -0,0 +1,56 @@ +package com.a.eye.skywalking.plugin.dubbo; + +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.alibaba.dubbo.rpc.Invocation; +import com.alibaba.dubbo.rpc.Invoker; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link DubboInstrumentation} present that skywalking use class {@link DubboInterceptor} to + * enhance class {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)} + * for support trace of the dubbo framework. + * + * @author zhangxin + */ +public class DubboInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + /** + * Enhance class + */ + private static final String ENHANCE_CLASS = "com.alibaba.dubbo.monitor.support.MonitorFilter"; + /** + * Intercept class + */ + private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.dubbo.DubboInterceptor"; + + @Override + protected String enhanceClassName() { + return ENHANCE_CLASS; + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("invoke"); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java new file mode 100644 index 000000000..304db4ebb --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java @@ -0,0 +1,202 @@ +package com.a.eye.skywalking.plugin.dubbo; + +import com.a.eye.skywalking.api.context.ContextCarrier; +import com.a.eye.skywalking.api.context.ContextManager; +import com.a.eye.skywalking.plugin.dubbox.BugFixActive; +import com.a.eye.skywalking.plugin.dubbox.SWBaseBean; +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +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; +import com.alibaba.dubbo.rpc.Invocation; +import com.alibaba.dubbo.rpc.Invoker; +import com.alibaba.dubbo.rpc.Result; +import com.alibaba.dubbo.rpc.RpcContext; + +/** + * {@link DubboInterceptor} define how to enhance class{@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}. + * the context data will transport to the provider side by {@link RpcContext#attachments}.but all the version of dubbo framework below 2.8.3 + * don't support {@link RpcContext#attachments}, we support another way to support it. it is that all request parameters of dubbo service + * need to extend {@link SWBaseBean}, and {@link DubboInterceptor} will inject the serialized context data to the {@link SWBaseBean} bean and + * extract the serialized context data from {@link SWBaseBean}, or the context data will not transport to the provider side. + * + * @author zhangxin + */ +public class DubboInterceptor implements InstanceMethodsAroundInterceptor { + + public static final String ATTACHMENT_NAME_OF_CONTEXT_DATA = "contextData"; + public static final String DUBBO_COMPONENT = "Dubbo"; + + /** + *

Consumer:

+ * The serialized context data will inject the first param that extend {@link SWBaseBean} of dubbo service + * if the method {@link BugFixActive#active()} be called. or the serialized context data will inject to the + * {@link RpcContext#attachments} for transport to provider side. + * + *

Provider:

+ * The serialized context data will extract from the first param that extend {@link SWBaseBean} of dubbo service + * if the method {@link BugFixActive#active()} be called. or it will extract from {@link RpcContext#attachments}. + * current trace segment will ref if the serialize context data is not null. + * + * @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance. + * @param interceptorContext method context, includes class name, method name, etc. + * @param result change this result, if you want to truncate the method. + */ + @Override + public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, + MethodInterceptResult result) { + Object[] arguments = interceptorContext.allArguments(); + Invoker invoker = (Invoker) arguments[0]; + Invocation invocation = (Invocation) arguments[1]; + RpcContext rpcContext = RpcContext.getContext(); + boolean isConsumer = rpcContext.isConsumerSide(); + + Span span = ContextManager.INSTANCE.createSpan(generateOperationName(invoker, invocation)); + if (isConsumer) { + Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT); + ContextCarrier contextCarrier = new ContextCarrier(); + ContextManager.INSTANCE.inject(contextCarrier); + if (!BugFixActive.isActive()) { + // context.setAttachment("contextData", contextDataStr); + // context的setAttachment方法在重试机制的时候并不会覆盖原有的Attachment + // 参见Dubbo源代码:“com.alibaba.dubbo.rpc.RpcInvocation” + // public void setAttachmentIfAbsent(String key, String value) { + // if (attachments == null) { + // attachments = new HashMap(); + // } + // if (! attachments.containsKey(key)) { + // attachments.put(key, value); + // } + // } + // 在Rest模式中attachment会被抹除,不会传入到服务端 + // Rest模式会将attachment存放到header里面,具体见com.alibaba.dubbo.rpc.protocol.rest.RpcContextFilter + //invocation.getAttachments().put("contextData", contextDataStr); + rpcContext.getAttachments().put(ATTACHMENT_NAME_OF_CONTEXT_DATA, contextCarrier.serialize()); + } else { + fix283SendNoAttachmentIssue(invocation, contextCarrier.serialize()); + } + } else { + Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER); + + String contextDataStr; + if (!BugFixActive.isActive()) { + contextDataStr = rpcContext.getAttachment(ATTACHMENT_NAME_OF_CONTEXT_DATA); + } else { + contextDataStr = fix283RecvNoAttachmentIssue(invocation); + } + + if (contextDataStr != null && contextDataStr.length() > 0) { + ContextManager.INSTANCE.extract(new ContextCarrier().deserialize(contextDataStr)); + } + } + + Tags.URL.set(span, generateRequestURL(invoker, invocation)); + Tags.COMPONENT.set(span, DUBBO_COMPONENT); + Tags.SPAN_LAYER.asRPCFramework(span); + } + + /** + * {@link DubboInterceptor#afterMethod(EnhancedClassInstanceContext, InstanceMethodInvokeContext, Object)} be executed after + * {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}, and it will check {@link Result#getException()} if is null. + * current active span will log the exception and set true to the value of error tag if the {@link Result#getException()} is not null. + * + * @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance. + * @param interceptorContext method context, includes class name, method name, etc. + * @param ret the method's original return value. + */ + @Override + public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, + Object ret) { + Result result = (Result) ret; + if (result != null && result.getException() != null) { + dealException(result.getException()); + } + + ContextManager.INSTANCE.stopSpan(); + return ret; + } + + @Override + public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, + InstanceMethodInvokeContext interceptorContext) { + dealException(t); + } + + /** + * Active span will log the exception and set current span value of error tag. + */ + private void dealException(Throwable throwable) { + Span span = ContextManager.INSTANCE.activeSpan(); + Tags.ERROR.set(span, true); + span.log(throwable); + } + + /** + * Generate operation name. + * the operation name should be like this com.a.eye.skywalking.plugin.test.Test.test(String) + * + * @return operation name + */ + private static String generateOperationName(Invoker invoker, Invocation invocation) { + StringBuilder operationName = new StringBuilder(); + operationName.append(invoker.getUrl().getPath()); + operationName.append("." + invocation.getMethodName() + "("); + for (Class classes : invocation.getParameterTypes()) { + operationName.append(classes.getSimpleName() + ","); + } + + if (invocation.getParameterTypes().length > 0) { + operationName.delete(operationName.length() - 1, operationName.length()); + } + + operationName.append(")"); + + return operationName.toString(); + } + + /** + * Generate request url. + * The request url may be like this dubbo://127.0.0.1:20880/com.a.eye.skywalking.plugin.test.Test.test(String) + * + * @return request url + */ + private static String generateRequestURL(Invoker invoker, Invocation invocation) { + StringBuilder requestURL = new StringBuilder(); + requestURL.append(invoker.getUrl().getProtocol() + "://"); + requestURL.append(invoker.getUrl().getHost()); + requestURL.append(":" + invoker.getUrl().getPort() + "/"); + requestURL.append(generateOperationName(invoker, invocation)); + return requestURL.toString(); + } + + /** + * Set the serialized context data to the first request param that extend {@link SWBaseBean} of dubbo service + * + * @param contextDataStr serialized context data + */ + private static void fix283SendNoAttachmentIssue(Invocation invocation, String contextDataStr) { + for (Object parameter : invocation.getArguments()) { + if (parameter instanceof SWBaseBean) { + ((SWBaseBean) parameter).setContextData(contextDataStr); + return; + } + } + } + + /** + * Fetch the serialize context data from the first request param that extend {@link SWBaseBean} of dubbo service. + * + * @return serialized context data + */ + private static String fix283RecvNoAttachmentIssue(Invocation invocation) { + for (Object parameter : invocation.getArguments()) { + if (parameter instanceof SWBaseBean) { + return ((SWBaseBean) parameter).getContextData(); + } + } + + return null; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java new file mode 100644 index 000000000..12e316218 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java @@ -0,0 +1,26 @@ +package com.a.eye.skywalking.plugin.dubbox; + +/** + * {@link BugFixActive#active} is an flag that present the dubbox version is below 2.8.3, + * The version 2.8.3 of dubbox don't support attachment. so skywalking provided another way + * to support the function that transport the serialized context data. the way that + * + * @author zhangxin + */ +public final class BugFixActive { + + private static boolean active = false; + + /** + * This method should be call first if the dubbo version is below 2.8.3. + */ + public static void active() { + BugFixActive.active = true; + } + + + public static boolean isActive(){ + return BugFixActive.active; + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java new file mode 100644 index 000000000..5f478d1ca --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java @@ -0,0 +1,24 @@ +package com.a.eye.skywalking.plugin.dubbox; + +import java.io.Serializable; + +/** + * All the request parameter of dubbox service need to extend {@link SWBaseBean} to transport + * the serialized context data to the provider side if the version of dubbox is below 2.8.3. + * + * @author zhangxin + */ +public class SWBaseBean implements Serializable { + /** + * Serialized context data + */ + private String contextData; + + public String getContextData() { + return contextData; + } + + public void setContextData(String contextData) { + this.contextData = contextData; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java new file mode 100644 index 000000000..26b88e7b0 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java @@ -0,0 +1,228 @@ +package com.a.eye.skywalking.plugin.dubbo; + +import com.a.eye.skywalking.api.context.TracerContext; +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +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.plugin.dubbox.BugFixActive; +import com.a.eye.skywalking.sniffer.mock.context.MockTracerContextListener; +import com.a.eye.skywalking.sniffer.mock.context.SegmentAssert; +import com.a.eye.skywalking.trace.LogData; +import com.a.eye.skywalking.trace.Span; +import com.a.eye.skywalking.trace.TraceSegment; +import com.a.eye.skywalking.trace.TraceSegmentRef; +import com.a.eye.skywalking.trace.tag.Tags; +import com.alibaba.dubbo.common.URL; +import com.alibaba.dubbo.rpc.Invocation; +import com.alibaba.dubbo.rpc.Invoker; +import com.alibaba.dubbo.rpc.Result; +import com.alibaba.dubbo.rpc.RpcContext; + +import org.hamcrest.CoreMatchers; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNull; +import static org.powermock.api.mockito.PowerMockito.mockStatic; +import static org.powermock.api.mockito.PowerMockito.when; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({RpcContext.class, BugFixActive.class}) +public class DubboInterceptorTest { + + private MockTracerContextListener mockTracerContextListener; + private DubboInterceptor dubboInterceptor; + private RequestParamForTestBelow283 testParam; + @Mock + private RpcContext rpcContext; + @Mock + private Invoker invoker; + @Mock + private Invocation invocation; + @Mock + private EnhancedClassInstanceContext classInstanceContext; + @Mock + private InstanceMethodInvokeContext methodInvokeContext; + @Mock + private MethodInterceptResult methodInterceptResult; + @Mock + private Result result; + + @Before + public void setUp() throws Exception { + dubboInterceptor = new DubboInterceptor(); + testParam = new RequestParamForTestBelow283(); + mockTracerContextListener = new MockTracerContextListener(); + TracerContext.ListenerManager.add(mockTracerContextListener); + + mockStatic(RpcContext.class); + mockStatic(BugFixActive.class); + when(invoker.getUrl()).thenReturn(URL.valueOf("dubbo://127.0.0.1:20880/com.a.eye.skywalking.test.TestDubboService")); + when(invocation.getMethodName()).thenReturn("test"); + when(invocation.getParameterTypes()).thenReturn(new Class[]{String.class}); + when(invocation.getArguments()).thenReturn(new Object[]{testParam}); + Mockito.when(RpcContext.getContext()).thenReturn(rpcContext); + when(rpcContext.isConsumerSide()).thenReturn(true); + when(methodInvokeContext.allArguments()).thenReturn(new Object[]{invoker, invocation}); + } + + + @Test + public void testConsumerBelow283() { + when(BugFixActive.isActive()).thenReturn(true); + + dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); + dubboInterceptor.afterMethod(classInstanceContext, methodInvokeContext, result); + + mockTracerContextListener.assertSize(1); + mockTracerContextListener.assertTraceSegment(0, new SegmentAssert() { + @Override + public void call(TraceSegment traceSegment) { + assertThat(traceSegment.getSpans().size(), is(1)); + assertConsumerSpan(traceSegment.getSpans().get(0)); + testParam.assertSelf("0"); + } + }); + } + + @Test + public void testConsumerWithAttachment() { + dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); + dubboInterceptor.afterMethod(classInstanceContext, methodInvokeContext, result); + + mockTracerContextListener.assertSize(1); + mockTracerContextListener.assertTraceSegment(0, new SegmentAssert() { + @Override + public void call(TraceSegment traceSegment) { + assertThat(traceSegment.getSpans().size(), is(1)); + assertConsumerSpan(traceSegment.getSpans().get(0)); + } + }); + } + + @Test + public void testConsumerWithException() { + dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); + dubboInterceptor.handleMethodException(new RuntimeException(), classInstanceContext, methodInvokeContext); + dubboInterceptor.afterMethod(classInstanceContext, methodInvokeContext, result); + + mockTracerContextListener.assertSize(1); + mockTracerContextListener.assertTraceSegment(0, new SegmentAssert() { + @Override + public void call(TraceSegment traceSegment) { + assertConsumerTraceSegmentInErrorCase(traceSegment); + } + }); + } + + @Test + public void testConsumerWithResultHasException() { + when(result.getException()).thenReturn(new RuntimeException()); + + dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); + dubboInterceptor.afterMethod(classInstanceContext, methodInvokeContext, result); + + mockTracerContextListener.assertSize(1); + mockTracerContextListener.assertTraceSegment(0, new SegmentAssert() { + @Override + public void call(TraceSegment traceSegment) { + assertConsumerTraceSegmentInErrorCase(traceSegment); + } + }); + } + + @Test + public void testProviderWithAttachment() { + when(rpcContext.isConsumerSide()).thenReturn(false); + when(rpcContext.getAttachment(DubboInterceptor.ATTACHMENT_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1"); + + dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); + dubboInterceptor.afterMethod(classInstanceContext, methodInvokeContext, result); + assertProvider(); + } + + + @Test + public void testProviderBelow283() { + when(rpcContext.isConsumerSide()).thenReturn(false); + when(BugFixActive.isActive()).thenReturn(true); + + testParam.setContextData("302017.1487666919810.624424584.17332.1.1|1"); + + + dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); + dubboInterceptor.afterMethod(classInstanceContext, methodInvokeContext, result); + + assertProvider(); + } + + + private void assertConsumerTraceSegmentInErrorCase(TraceSegment traceSegment) { + assertThat(traceSegment.getSpans().size(), is(1)); + assertConsumerSpan(traceSegment.getSpans().get(0)); + Span span = traceSegment.getSpans().get(0); + assertThat(span.getLogs().size(), is(1)); + assertErrorLog(span.getLogs().get(0)); + } + + private void assertErrorLog(LogData logData) { + assertThat(logData.getFields().size(), is(3)); + assertThat(logData.getFields().get("error.kind"), CoreMatchers.is(RuntimeException.class.getName())); + assertNull(logData.getFields().get("message")); + } + + + private void assertProvider() { + final TraceSegmentRef expect = new TraceSegmentRef(); + expect.setSpanId(1); + expect.setTraceSegmentId("302017.1487666919810.624424584.17332.1.1"); + + mockTracerContextListener.assertSize(1); + mockTracerContextListener.assertTraceSegment(0, new SegmentAssert() { + @Override + public void call(TraceSegment traceSegment) { + assertThat(traceSegment.getSpans().size(), is(1)); + assertProviderSpan(traceSegment.getSpans().get(0)); + assertTraceSegmentRef(traceSegment.getPrimaryRef(), expect); + } + }); + } + + private void assertTraceSegmentRef(TraceSegmentRef actual, TraceSegmentRef expect) { + assertThat(actual.getSpanId(), is(expect.getSpanId())); + assertThat(actual.getTraceSegmentId(), is(expect.getTraceSegmentId())); + } + + + private void assertProviderSpan(Span span) { + assertCommonsAttribute(span); + assertThat(Tags.SPAN_KIND.get(span), is(Tags.SPAN_KIND_SERVER)); + } + + private void assertConsumerSpan(Span span) { + assertCommonsAttribute(span); + assertThat(Tags.SPAN_KIND.get(span), is(Tags.SPAN_KIND_CLIENT)); + } + + private void assertCommonsAttribute(Span span) { + assertThat(Tags.SPAN_LAYER.isRPCFramework(span), is(true)); + assertThat(Tags.COMPONENT.get(span), is(DubboInterceptor.DUBBO_COMPONENT)); + assertThat(Tags.URL.get(span), is("dubbo://127.0.0.1:20880/com.a.eye.skywalking.test.TestDubboService.test(String)")); + assertThat(span.getOperationName(), is("com.a.eye.skywalking.test.TestDubboService.test(String)")); + } + + @After + public void tearDown() throws Exception { + TracerContext.ListenerManager.remove(mockTracerContextListener); + } + +} \ No newline at end of file diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java new file mode 100644 index 000000000..3ca038a17 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java @@ -0,0 +1,24 @@ +package com.a.eye.skywalking.plugin.dubbo; + +import com.a.eye.skywalking.plugin.dubbox.SWBaseBean; + +import static org.hamcrest.CoreMatchers.endsWith; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +/** + * {@link RequestParamForTestBelow283} store context data for test. + */ +public class RequestParamForTestBelow283 extends SWBaseBean { + + /** + * This method assert that {@link SWBaseBean#getContextData()} if it's not null and context data + * will end with the expect span id. + * + * @param expectSpanId expect span id + */ + public void assertSelf(String expectSpanId) { + assertNotNull(getContextData()); + assertThat(getContextData(), endsWith(expectSpanId)); + } +} From 82ce2ad225268b52882b014106947d45ebff5bd8 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Tue, 21 Feb 2017 21:59:33 +0800 Subject: [PATCH 02/12] Modify the Tomcat plugin using the new API --- .../plugin/dubbo/DubboInstrumentation.java | 5 +- .../skywalking-sdk-plugin/pom.xml | 6 + .../tomcat78x/TomcatPluginInterceptor.java | 70 --------- .../plugin/tomcat78x/WebBuriedPointType.java | 18 --- .../tomcat78x/define/TomcatPluginDefine.java | 36 ----- .../plugin/tomcat78x/TomcatInterceptor.java | 68 +++++++++ .../define/TomcatInstrumentation.java | 52 +++++++ .../src/main/resources/skywalking-plugin.def | 2 +- .../tomcat78x/TomcatInterceptorTest.java | 140 ++++++++++++++++++ 9 files changed, 269 insertions(+), 128 deletions(-) delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/TomcatPluginInterceptor.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/WebBuriedPointType.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/define/TomcatPluginDefine.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java index 2f65c34e1..0890dcdcc 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java @@ -12,9 +12,8 @@ import net.bytebuddy.matcher.ElementMatcher; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link DubboInstrumentation} present that skywalking use class {@link DubboInterceptor} to - * enhance class {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)} - * for support trace of the dubbo framework. + * {@link DubboInstrumentation} presents that skywalking use class {@link DubboInterceptor} to + * intercept {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}. * * @author zhangxin */ diff --git a/skywalking-sniffer/skywalking-sdk-plugin/pom.xml b/skywalking-sniffer/skywalking-sdk-plugin/pom.xml index ee2399093..e1a61be3c 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/pom.xml +++ b/skywalking-sniffer/skywalking-sdk-plugin/pom.xml @@ -33,6 +33,12 @@ skywalking-api 3.0-2017 + + com.a.eye + skywalking-sniffer-mock + 3.0-2017 + test + diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/TomcatPluginInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/TomcatPluginInterceptor.java deleted file mode 100644 index e46e1b6ab..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/TomcatPluginInterceptor.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.a.eye.skywalking.api.plugin.tomcat78x; - -import com.a.eye.skywalking.api.Tracing; -import com.a.eye.skywalking.invoke.monitor.RPCServerInvokeMonitor; -import com.a.eye.skywalking.model.ContextData; -import com.a.eye.skywalking.model.Identification; -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class TomcatPluginInterceptor implements InstanceMethodsAroundInterceptor { - private final String secondKey = "ContextData"; - private String tracingName = DEFAULT_TRACE_NAME; - private static final String DEFAULT_TRACE_NAME = "SkyWalking-TRACING-NAME"; - private static final String TRACE_ID_HEADER_NAME = "SW-TraceId"; - - @Override - public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { - Object[] args = interceptorContext.allArguments(); - HttpServletRequest requests = (HttpServletRequest) args[0]; - String tracingHeaderValue = requests.getHeader(tracingName); - ContextData contextData = null; - if (tracingHeaderValue != null) { - String contextDataStr = null; - int index = tracingHeaderValue.indexOf("="); - if (index > 0) { - String key = tracingHeaderValue.substring(0, index); - if (secondKey.equals(key)) { - contextDataStr = tracingHeaderValue.substring(index + 1); - } - } - - if (contextDataStr != null && contextDataStr.length() > 0) { - contextData = new ContextData(contextDataStr); - } - } - RPCServerInvokeMonitor rpcServerInvokeMonitor = new RPCServerInvokeMonitor(); - rpcServerInvokeMonitor.beforeInvoke(contextData, generateIdentification(requests)); - } - - - private Identification generateIdentification(HttpServletRequest request) { - return Identification.newBuilder() - .viewPoint(request.getRequestURL().toString()) - .spanType(WebBuriedPointType.INSTANCE) - .build(); - } - - - @Override - public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) { - Object[] args = interceptorContext.allArguments(); - HttpServletResponse httpServletResponse = (HttpServletResponse) args[1]; - httpServletResponse.addHeader(TRACE_ID_HEADER_NAME, Tracing.getTraceId()); - new RPCServerInvokeMonitor().afterInvoke(); - return ret; - } - - @Override - public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, - InstanceMethodInvokeContext interceptorContext) { - new RPCServerInvokeMonitor().occurException(t); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/WebBuriedPointType.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/WebBuriedPointType.java deleted file mode 100644 index d353c784a..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/WebBuriedPointType.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.a.eye.skywalking.api.plugin.tomcat78x; - -import com.a.eye.skywalking.api.IBuriedPointType; - -public enum WebBuriedPointType implements IBuriedPointType { - INSTANCE; - - @Override - public String getTypeName() { - return "W"; - } - - @Override - public CallType getCallType() { - return CallType.SYNC; - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/define/TomcatPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/define/TomcatPluginDefine.java deleted file mode 100644 index d79b185c9..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/tomcat78x/define/TomcatPluginDefine.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.a.eye.skywalking.api.plugin.tomcat78x.define; - -import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; -import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.named; - -public class TomcatPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { - @Override - protected String enhanceClassName() { - return "org.apache.catalina.core.StandardEngineValve"; - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("invoke"); - } - - @Override - public String getMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.tomcat78x.TomcatPluginInterceptor"; - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java new file mode 100644 index 000000000..ef9421ea6 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java @@ -0,0 +1,68 @@ +package com.a.eye.skywalking.plugin.tomcat78x; + +import com.a.eye.skywalking.api.context.ContextCarrier; +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.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; +import com.a.eye.skywalking.api.util.StringUtil; +import com.a.eye.skywalking.trace.Span; +import com.a.eye.skywalking.trace.tag.Tags; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * {@link TomcatInterceptor} fetch the serialized context data by use {@link HttpServletRequest#getHeader(String)}. + * The {@link com.a.eye.skywalking.trace.TraceSegment#primaryRef} of current trace segment will reference to the trace segment id + * of the previous level if the serialized context is not null. + */ +public class TomcatInterceptor implements InstanceMethodsAroundInterceptor { + public static final String HEADER_NAME_OF_CONTEXT_DATA = "SKYWALKING_CONTEXT_DATA"; + public static final String TOMCAT_COMPONENT = "Tomcat"; + + /** + * The {@link com.a.eye.skywalking.trace.TraceSegment#primaryRef} of current trace segment will reference to the trace segment id + * of the previous level if the serialized context is not null. + * + * @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance. + * @param interceptorContext method context, includes class name, method name, etc. + * @param result change this result, if you want to truncate the method. + */ + @Override + public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { + Object[] args = interceptorContext.allArguments(); + HttpServletRequest request = (HttpServletRequest) args[0]; + + Span span = ContextManager.INSTANCE.createSpan(request.getRequestURI()); + Tags.COMPONENT.set(span, TOMCAT_COMPONENT); + Tags.URL.set(span, request.getRequestURL().toString()); + Tags.SPAN_LAYER.asHttp(span); + + String tracingHeaderValue = request.getHeader(HEADER_NAME_OF_CONTEXT_DATA); + if (!StringUtil.isEmpty(tracingHeaderValue)) { + ContextManager.INSTANCE.extract(new ContextCarrier().deserialize(tracingHeaderValue)); + } + } + + @Override + public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) { + HttpServletResponse response = (HttpServletResponse) interceptorContext.allArguments()[1]; + + Span span = ContextManager.INSTANCE.activeSpan(); + Tags.STATUS_CODE.set(span, response.getStatus()); + ContextManager.INSTANCE.stopSpan(); + + return ret; + } + + @Override + public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, + InstanceMethodInvokeContext interceptorContext) { + Span span = ContextManager.INSTANCE.activeSpan(); + span.log(t); + Tags.ERROR.set(span, true); + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java new file mode 100644 index 000000000..c512d84ff --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java @@ -0,0 +1,52 @@ +package com.a.eye.skywalking.plugin.tomcat78x.define; + +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.tomcat78x.TomcatInterceptor; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import org.apache.catalina.connector.Request; +import org.apache.catalina.connector.Response; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link TomcatInstrumentation} presents that skywalking use class {@link TomcatInterceptor} to + * intercept {@link org.apache.catalina.core.StandardEngineValve#invoke(Request, Response)}. + * + * @author zhangxin + */ +public class TomcatInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "org.apache.catalina.core.StandardEngineValve"; + + private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.tomcat78x.TomcatInterceptor"; + + @Override + protected String enhanceClassName() { + return ENHANCE_CLASS; + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("invoke"); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def index 9433b13c2..b98f1ae95 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -com.a.eye.skywalking.plugin.tomcat78x.define.TomcatPluginDefine +com.a.eye.skywalking.plugin.tomcat78x.define.TomcatInstrumentation diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java new file mode 100644 index 000000000..fbe643dda --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java @@ -0,0 +1,140 @@ +package com.a.eye.skywalking.plugin.tomcat78x; + +import com.a.eye.skywalking.api.context.TracerContext; +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +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.sniffer.mock.context.MockTracerContextListener; +import com.a.eye.skywalking.sniffer.mock.context.SegmentAssert; +import com.a.eye.skywalking.trace.LogData; +import com.a.eye.skywalking.trace.Span; +import com.a.eye.skywalking.trace.TraceSegment; +import com.a.eye.skywalking.trace.TraceSegmentRef; +import com.a.eye.skywalking.trace.tag.Tags; + +import org.hamcrest.CoreMatchers; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class TomcatInterceptorTest { + + private TomcatInterceptor tomcatInterceptor; + private MockTracerContextListener contextListener; + + @Mock + private HttpServletRequest request; + @Mock + private HttpServletResponse response; + @Mock + private EnhancedClassInstanceContext classInstanceContext; + @Mock + private InstanceMethodInvokeContext methodInvokeContext; + @Mock + private MethodInterceptResult methodInterceptResult; + + @Before + public void setUp() throws Exception { + tomcatInterceptor = new TomcatInterceptor(); + contextListener = new MockTracerContextListener(); + + TracerContext.ListenerManager.add(contextListener); + + when(request.getRequestURI()).thenReturn("/test/testRequestURL"); + when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/testRequestURL")); + when(response.getStatus()).thenReturn(200); + when(methodInvokeContext.allArguments()).thenReturn(new Object[]{request, response}); + } + + @Test + public void testWithoutSerializedContextData() { + tomcatInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); + tomcatInterceptor.afterMethod(classInstanceContext, methodInvokeContext, null); + + contextListener.assertSize(1); + contextListener.assertTraceSegment(0, new SegmentAssert() { + @Override + public void call(TraceSegment traceSegment) { + assertThat(traceSegment.getSpans().size(), is(1)); + Span span = traceSegment.getSpans().get(0); + assertHttpSpan(span); + } + }); + } + + @Test + public void testWithSerializedContextData() { + when(request.getHeader(TomcatInterceptor.HEADER_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1"); + + tomcatInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); + tomcatInterceptor.afterMethod(classInstanceContext, methodInvokeContext, null); + + contextListener.assertSize(1); + contextListener.assertTraceSegment(0, new SegmentAssert() { + @Override + public void call(TraceSegment traceSegment) { + assertThat(traceSegment.getSpans().size(), is(1)); + Span span = traceSegment.getSpans().get(0); + assertHttpSpan(span); + assertTraceSegmentRef(traceSegment.getPrimaryRef()); + } + }); + } + + @Test + public void testWithOccurException(){ + tomcatInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); + tomcatInterceptor.handleMethodException(new RuntimeException(), classInstanceContext, methodInvokeContext); + tomcatInterceptor.afterMethod(classInstanceContext, methodInvokeContext, null); + + contextListener.assertSize(1); + contextListener.assertTraceSegment(0, new SegmentAssert() { + @Override + public void call(TraceSegment traceSegment) { + assertThat(traceSegment.getSpans().size(), is(1)); + Span span = traceSegment.getSpans().get(0); + assertHttpSpan(span); + assertThat(span.getLogs().size(), is(1)); + assertSpanLog(span.getLogs().get(0)); + } + }); + } + + private void assertSpanLog(LogData logData) { + assertThat(logData.getFields().size(), is(3)); + assertThat(logData.getFields().get("error.kind"), CoreMatchers.is(RuntimeException.class.getName())); + assertNull(logData.getFields().get("message")); + } + + private void assertTraceSegmentRef(TraceSegmentRef ref) { + assertThat(ref.getSpanId(), is(1)); + assertThat(ref.getTraceSegmentId(), is("302017.1487666919810.624424584.17332.1.1")); + } + + private void assertHttpSpan(Span span) { + assertThat(span.getOperationName(), is("/test/testRequestURL")); + assertThat(Tags.COMPONENT.get(span), is("Tomcat")); + assertThat(Tags.URL.get(span), is("http://localhost:8080/test/testRequestURL")); + assertThat(Tags.STATUS_CODE.get(span), is(200)); + assertTrue(Tags.SPAN_LAYER.isHttp(span)); + } + + @After + public void tearDown() throws Exception { + TracerContext.ListenerManager.remove(new MockTracerContextListener()); + } + +} \ No newline at end of file From 316c09b01232ae4ce1709ce88a95df4e4db557d4 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 22 Feb 2017 21:47:36 +0800 Subject: [PATCH 03/12] Modify the motan plugin using the new API --- .../plugin/motan/MotanBuriedPointType.java | 19 ---- .../motan/MotanClientCallInterceptor.java | 60 ------------ .../MotanClientFetchCallURLInterceptor.java | 29 ------ .../plugin/motan/MotanServerInterceptor.java | 57 ------------ .../motan/define/MotanClientDefine.java | 47 ---------- .../motan/define/MotanServerDefine.java | 49 ---------- .../ConsumerFetchRequestURLInterceptor.java | 39 ++++++++ .../motan/ConsumerInvokeInterceptor.java | 93 +++++++++++++++++++ .../plugin/motan/ProviderInterceptor.java | 88 ++++++++++++++++++ .../motan/define/ConsumerInstrumentation.java | 60 ++++++++++++ .../motan/define/ProviderInstrumentation.java | 69 ++++++++++++++ .../src/main/resources/skywalking-plugin.def | 4 +- 12 files changed, 351 insertions(+), 263 deletions(-) delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanBuriedPointType.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanClientCallInterceptor.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanClientFetchCallURLInterceptor.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanServerInterceptor.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/define/MotanClientDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/define/MotanServerDefine.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanBuriedPointType.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanBuriedPointType.java deleted file mode 100644 index 766351815..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanBuriedPointType.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.a.eye.skywalking.api.plugin.motan; - -import com.a.eye.skywalking.api.IBuriedPointType; - -public enum MotanBuriedPointType implements IBuriedPointType { - - INSTANCE; - - @Override - public String getTypeName() { - return "MO"; - } - - @Override - public CallType getCallType() { - return CallType.SYNC; - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanClientCallInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanClientCallInterceptor.java deleted file mode 100644 index c06cb9ba6..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanClientCallInterceptor.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.a.eye.skywalking.api.plugin.motan; - -import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor; -import com.a.eye.skywalking.model.ContextData; -import com.a.eye.skywalking.model.Identification; -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; -import com.weibo.api.motan.rpc.Request; -import com.weibo.api.motan.rpc.URL; - -/** - * Motan client interceptor - */ -public class MotanClientCallInterceptor implements InstanceMethodsAroundInterceptor{ - - private static final String REQUEST_URL = "REQUEST_URL"; - - @Override - public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, - MethodInterceptResult result) { - URL url = (URL) context.get(REQUEST_URL); - Request request = (Request) interceptorContext.allArguments()[0]; - if (url != null) { - ContextData contextData = new RPCClientInvokeMonitor() - .beforeInvoke(generateIdentify(request, url)); - String contextDataStr = contextData.toString(); - request.setAttachment("contextData", contextDataStr); - } - } - - @Override - public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, - Object ret) { - new RPCClientInvokeMonitor().afterInvoke(); - return ret; - } - - @Override - public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, - InstanceMethodInvokeContext interceptorContext) { - new RPCClientInvokeMonitor().occurException(t); - } - - - private static String generateViewPoint(URL serviceURI, Request request) { - StringBuilder viewPoint = new StringBuilder(serviceURI.getUri()); - viewPoint.append("." + request.getMethodName()); - viewPoint.append("(" + request.getParamtersDesc() + ")?group=" + serviceURI.getGroup()); - return viewPoint.toString(); - } - - - public static Identification generateIdentify(Request request, URL serviceURI) { - return Identification.newBuilder().viewPoint(generateViewPoint(serviceURI, request)) - .spanType(MotanBuriedPointType.INSTANCE).build(); - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanClientFetchCallURLInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanClientFetchCallURLInterceptor.java deleted file mode 100644 index 637a56116..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanClientFetchCallURLInterceptor.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.a.eye.skywalking.api.plugin.motan; - -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; - -/** - * Created by xin on 2017/1/23. - */ -public class MotanClientFetchCallURLInterceptor implements InstanceMethodsAroundInterceptor { - - private static final String REQUEST_URL = "REQUEST_URL"; - - @Override - public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { - context.set(REQUEST_URL, interceptorContext.allArguments()[0]); - } - - @Override - public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) { - return ret; - } - - @Override - public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) { - - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanServerInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanServerInterceptor.java deleted file mode 100644 index 9a1570aee..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/MotanServerInterceptor.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.a.eye.skywalking.api.plugin.motan; - -import com.a.eye.skywalking.invoke.monitor.RPCServerInvokeMonitor; -import com.a.eye.skywalking.model.ContextData; -import com.a.eye.skywalking.model.Identification; -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 com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; -import com.weibo.api.motan.rpc.Request; -import com.weibo.api.motan.rpc.URL; - -public class MotanServerInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor { - @Override - public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { - context.set("serviceURI", interceptorContext.allArguments()[0]); - } - - @Override - public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, - MethodInterceptResult result) { - com.weibo.api.motan.rpc.Request request = (com.weibo.api.motan.rpc.Request) interceptorContext.allArguments()[0]; - if (request != null) { - new RPCServerInvokeMonitor().beforeInvoke(new ContextData(request.getAttachments().get("contextData")), - generateIdentify(request, (com.weibo.api.motan.rpc.URL) context.get("serviceURI"))); - } - } - - @Override - public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, - Object ret) { - new RPCServerInvokeMonitor().afterInvoke(); - return ret; - } - - @Override - public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, - InstanceMethodInvokeContext interceptorContext) { - new RPCServerInvokeMonitor().occurException(t); - } - - - private static String generateViewPoint(URL serviceURI, Request request) { - StringBuilder viewPoint = new StringBuilder(serviceURI.getUri()); - viewPoint.append("." + request.getMethodName()); - viewPoint.append("(" + request.getParamtersDesc() + ")?group=" + serviceURI.getGroup()); - return viewPoint.toString(); - } - - - public static Identification generateIdentify(Request request, URL serviceURI) { - return Identification.newBuilder().viewPoint(generateViewPoint(serviceURI, request)) - .spanType(MotanBuriedPointType.INSTANCE).build(); - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/define/MotanClientDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/define/MotanClientDefine.java deleted file mode 100644 index e838dda1e..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/define/MotanClientDefine.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.a.eye.skywalking.api.plugin.motan.define; - -import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; -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 static net.bytebuddy.matcher.ElementMatchers.named; - -public class MotanClientDefine extends ClassInstanceMethodsEnhancePluginDefine { - @Override - protected String enhanceClassName() { - return "com.weibo.api.motan.cluster.support.ClusterSpi"; - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[0]; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("setUrl"); - } - - @Override - public String getMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.motan.MotanClientFetchCallURLInterceptor"; - } - }, new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("call"); - } - - @Override - public String getMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.motan.MotanClientCallInterceptor"; - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/define/MotanServerDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/define/MotanServerDefine.java deleted file mode 100644 index 4649f3a40..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/api/plugin/motan/define/MotanServerDefine.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.a.eye.skywalking.api.plugin.motan.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.interceptor.ConstructorInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.any; -import static net.bytebuddy.matcher.ElementMatchers.named; - -public class MotanServerDefine extends ClassInstanceMethodsEnhancePluginDefine { - - @Override - protected String enhanceClassName() { - return "com.weibo.api.motan.rpc.AbstractProvider"; - } - - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return new ConstructorInterceptPoint[] {new ConstructorInterceptPoint() { - @Override - public ElementMatcher getConstructorMatcher() { - return any(); - } - - @Override - public String getConstructorInterceptor() { - return "com.a.eye.skywalking.plugin.motan.MotanServerInterceptor"; - } - }}; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("call"); - } - - @Override - public String getMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.motan.MotanServerInterceptor"; - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java new file mode 100644 index 000000000..214f9b537 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java @@ -0,0 +1,39 @@ +package com.a.eye.skywalking.plugin.motan; + +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; + +/** + * {@link ConsumerFetchRequestURLInterceptor} record {@link com.weibo.api.motan.rpc.URL} to {@link EnhancedClassInstanceContext#context} + * for the operation name that create span need. + * + * @author zhangxin + */ +public class ConsumerFetchRequestURLInterceptor implements InstanceMethodsAroundInterceptor { + + private static final String CONTEXT_NAME_OF_REQUEST_URL = "REQUEST_URL"; + + /** + * Fetch the request url from the first param of all constructor, and put request url into {@link EnhancedClassInstanceContext#context}. + * + * @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance. + * @param interceptorContext method context, includes class name, method name, etc. + * @param result change this result, if you want to truncate the method. + */ + @Override + public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { + context.set(CONTEXT_NAME_OF_REQUEST_URL, interceptorContext.allArguments()[0]); + } + + @Override + public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) { + return ret; + } + + @Override + public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) { + // do nothing + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java new file mode 100644 index 000000000..a0d269888 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java @@ -0,0 +1,93 @@ +package com.a.eye.skywalking.plugin.motan; + +import com.a.eye.skywalking.api.context.ContextCarrier; +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.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +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; +import com.weibo.api.motan.rpc.Request; +import com.weibo.api.motan.rpc.Response; +import com.weibo.api.motan.rpc.URL; + +/** + * {@link ConsumerInvokeInterceptor} create span by fetch request url from {@link EnhancedClassInstanceContext#context} and + * transport serialized context data to provider side through {@link Request#setAttachment(String, String)}. + * + * @author zhangxin + */ +public class ConsumerInvokeInterceptor implements InstanceMethodsAroundInterceptor { + + /** + * Context name of request url in {@link EnhancedClassInstanceContext#context} + */ + private static final String CONTEXT_NAME_OF_REQUEST_URL = "REQUEST_URL"; + + /** + * Attachment key of the serialized context data + */ + private static final String ATTACHMENT_KEY_OF_CONTEXT_DATA = "contextData"; + + /** + * Motan component + */ + private static final String MOTAN_COMPONENT = "Motan"; + + @Override + public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, + MethodInterceptResult result) { + URL url = (URL) context.get(CONTEXT_NAME_OF_REQUEST_URL); + + if (url != null) { + Request request = (Request) interceptorContext.allArguments()[0]; + + Span span = ContextManager.INSTANCE.createSpan(generateOperationName(url, request)); + Tags.PEER_HOST.set(span, url.getHost()); + Tags.PEER_PORT.set(span, url.getPort()); + Tags.COMPONENT.set(span, MOTAN_COMPONENT); + Tags.URL.set(span, url.getIdentity()); + Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT); + Tags.SPAN_LAYER.asRPCFramework(span); + + ContextCarrier contextCarrier = new ContextCarrier(); + ContextManager.INSTANCE.inject(contextCarrier); + request.setAttachment(ATTACHMENT_KEY_OF_CONTEXT_DATA, contextCarrier.serialize()); + } + } + + @Override + public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, + Object ret) { + Response response = (Response) ret; + if (response != null && response.getException() != null) { + Span span = ContextManager.INSTANCE.activeSpan(); + span.log(response.getException()); + Tags.ERROR.set(span, true); + } + + ContextManager.INSTANCE.stopSpan(); + return ret; + } + + @Override + public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, + InstanceMethodInvokeContext interceptorContext) { + ContextManager.INSTANCE.activeSpan().log(t); + } + + + /** + * Generate operation name. + * + * @return operation name + */ + private static String generateOperationName(URL serviceURI, Request request) { + StringBuilder viewPoint = new StringBuilder(serviceURI.getPath()); + viewPoint.append("." + request.getMethodName()); + viewPoint.append("(" + request.getParamtersDesc() + ")"); + return viewPoint.toString(); + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java new file mode 100644 index 000000000..0413cb985 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java @@ -0,0 +1,88 @@ +package com.a.eye.skywalking.plugin.motan; + +import com.a.eye.skywalking.api.context.ContextCarrier; +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.enhance.ConstructorInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorInterceptor; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +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; +import com.weibo.api.motan.rpc.Request; +import com.weibo.api.motan.rpc.Response; +import com.weibo.api.motan.rpc.URL; + +/** + * Current trace segment will ref the trace segment from previous level if the serialized context data that fetch + * from {@link Request#getAttachments()} is not null. + * + * {@link ProviderInterceptor} intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} for record + * the request url from consumer side. + * + * @author zhangxin + */ +public class ProviderInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor { + + /** + * The key name of request url that stored in {@link EnhancedClassInstanceContext#context} + */ + private static final String KEY_NAME_OF_REQUEST_URL = "REQUEST_URL"; + + /** + * The key name that the serialized context data stored in {@link Request#getAttachments()} + */ + private static final String ATTACHMENT_KEY_OF_CONTEXT_DATA = "contextData"; + + @Override + public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { + context.set(KEY_NAME_OF_REQUEST_URL, interceptorContext.allArguments()[0]); + } + + @Override + public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, + MethodInterceptResult result) { + URL url = (URL) context.get(KEY_NAME_OF_REQUEST_URL); + if (url != null) { + com.weibo.api.motan.rpc.Request request = (com.weibo.api.motan.rpc.Request) interceptorContext.allArguments()[0]; + Span span = ContextManager.INSTANCE.createSpan(generateViewPoint(url, request)); + Tags.COMPONENT.set(span, "Motan"); + Tags.URL.set(span, url.getIdentity()); + Tags.PEER_PORT.set(span, url.getPort()); + Tags.PEER_HOST.set(span, url.getHost()); + Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER); + Tags.SPAN_LAYER.asRPCFramework(span); + + String serializedContextData = request.getAttachments().get(ATTACHMENT_KEY_OF_CONTEXT_DATA); + ContextManager.INSTANCE.extract(new ContextCarrier().deserialize(serializedContextData)); + } + } + + @Override + public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, + Object ret) { + Response response = (Response) ret; + if (response != null && response.getException() != null) { + Span span = ContextManager.INSTANCE.activeSpan(); + Tags.ERROR.set(span, true); + span.log(response.getException()); + } + return ret; + } + + @Override + public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, + InstanceMethodInvokeContext interceptorContext) { + ContextManager.INSTANCE.activeSpan().log(t); + } + + + private static String generateViewPoint(URL serviceURI, Request request) { + StringBuilder viewPoint = new StringBuilder(serviceURI.getUri()); + viewPoint.append("." + request.getMethodName()); + viewPoint.append("(" + request.getParamtersDesc() + ")"); + return viewPoint.toString(); + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java new file mode 100644 index 000000000..cf90c0f1a --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java @@ -0,0 +1,60 @@ +package com.a.eye.skywalking.plugin.motan.define; + +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.motan.ConsumerFetchRequestURLInterceptor; +import com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor; +import com.weibo.api.motan.rpc.Request; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link ConsumerInstrumentation} presents that skywalking use {@link ConsumerInvokeInterceptor} + * to intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} and use {@link ConsumerFetchRequestURLInterceptor} + * to intercept{@link ConsumerFetchRequestURLInterceptor} + */ +public class ConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + private static final String ENHANCE_CLASS = "com.weibo.api.motan.cluster.support.ClusterSpi"; + private static final String FETCH_REQUEST_URL_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerFetchRequestURLInterceptor"; + private static final String INVOKE_INTECEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor"; + + @Override + protected String enhanceClassName() { + return ENHANCE_CLASS; + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("setUrl"); + } + + @Override + public String getMethodsInterceptor() { + return FETCH_REQUEST_URL_INTERCEPT_CLASS; + } + }, new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("call"); + } + + @Override + public String getMethodsInterceptor() { + return INVOKE_INTECEPT_CLASS; + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java new file mode 100644 index 000000000..29ee2f2b5 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java @@ -0,0 +1,69 @@ +package com.a.eye.skywalking.plugin.motan.define; + +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.weibo.api.motan.rpc.Request; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import static net.bytebuddy.matcher.ElementMatchers.any; +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link ProviderInstrumentation} presents that skywalking will use {@link com.a.eye.skywalking.plugin.motan.ProviderInterceptor} + * to intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)} + * + * @author zhangxin + */ +public class ProviderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + /** + * Enhance class + */ + private static final String ENHANCE_CLASS = "com.weibo.api.motan.rpc.AbstractProvider"; + /** + * Class that intercept all constructor of ${@link com.weibo.api.motan.rpc.AbstractProvider} + */ + private static final String CONSTRUCTOR_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ProviderInterceptor"; + /** + * Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)} + */ + private static final String PROVIDER_INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ProviderInterceptor"; + + @Override + protected String enhanceClassName() { + return ENHANCE_CLASS; + } + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[]{new ConstructorInterceptPoint() { + @Override + public ElementMatcher getConstructorMatcher() { + return any(); + } + + @Override + public String getConstructorInterceptor() { + return CONSTRUCTOR_INTERCEPT_CLASS; + } + }}; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("call"); + } + + @Override + public String getMethodsInterceptor() { + return PROVIDER_INVOKE_INTERCEPT_CLASS; + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def index e70bf5478..f223bc720 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,2 @@ -com.a.eye.skywalking.plugin.motan.define.MotanClientDefine -com.a.eye.skywalking.plugin.motan.define.MotanServerDefine +com.a.eye.skywalking.plugin.motan.define.ConsumerInstrumentation +com.a.eye.skywalking.plugin.motan.define.ProviderInstrumentation From 5db289a21ba8195d4cb3c9b60847f7c4fd820de9 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 22 Feb 2017 23:06:52 +0800 Subject: [PATCH 04/12] Modify the redis plugin using the new API --- ...ConstructorInterceptor4HostAndPortArg.java | 21 ---- ...sClusterConstructorInterceptor4SetArg.java | 26 ---- ...isConstructorInterceptor4ShardInfoArg.java | 22 ---- ...JedisConstructorInterceptor4StringArg.java | 21 ---- .../JedisConstructorInterceptor4UriArg.java | 23 ---- .../jedis/v2/JedisMethodInterceptor.java | 52 -------- .../plugin/jedis/v2/RedisBuriedPointType.java | 18 --- .../v2/define/JedisClusterPluginDefine.java | 62 ---------- .../jedis/v2/define/JedisPluginDefine.java | 81 ------------ ...structorWithHostAndPortArgInterceptor.java | 28 +++++ ...ctorWithListHostAndPortArgInterceptor.java | 30 +++++ ...onstructorWithShardInfoArgInterceptor.java | 25 ++++ ...isConstructorWithStringArgInterceptor.java | 26 ++++ ...JedisConstructorWithUriArgInterceptor.java | 25 ++++ .../jedis/v2/JedisMethodInterceptor.java | 60 +++++++++ .../define/JedisClusterInstrumentation.java | 97 +++++++++++++++ .../jedis/v2/define/JedisInstrumentation.java | 117 ++++++++++++++++++ .../src/main/resources/skywalking-plugin.def | 4 +- 18 files changed, 410 insertions(+), 328 deletions(-) delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisClusterConstructorInterceptor4HostAndPortArg.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisClusterConstructorInterceptor4SetArg.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4ShardInfoArg.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4StringArg.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisConstructorInterceptor4UriArg.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/JedisMethodInterceptor.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/RedisBuriedPointType.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/define/JedisClusterPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jedis/v2/define/JedisPluginDefine.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithHostAndPortArgInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisClusterConstructorWithListHostAndPortArgInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithShardInfoArgInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithStringArgInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisConstructorWithUriArgInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/JedisMethodInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisClusterInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jedis-2.x-plugin/src/main/java/com/a/eye/skywalking/plugin/jedis/v2/define/JedisInstrumentation.java 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 From cea88f981daf14c130f0453973a86489ecf8e565 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Fri, 24 Feb 2017 15:01:38 +0800 Subject: [PATCH 05/12] Rewrite plugins by using new API --- .../com/a/eye/skywalking/trace/tag/Tags.java | 37 +- .../a/eye/skywalking/trace/SpanTestCase.java | 1 - .../trace/TraceSegmentTestCase.java | 2 +- .../eye/skywalking/agent/SkyWalkingAgent.java | 7 +- .../plugin/interceptor/EnhanceException.java | 1 + .../enhance/ClassEnhancePluginDefine.java | 6 +- ...assInstanceMethodsEnhancePluginDefine.java | 1 + .../plugin/dubbo/DubboInstrumentation.java | 4 +- .../plugin/dubbo/DubboInterceptor.java | 56 +- .../plugin/dubbox/BugFixActive.java | 6 +- .../skywalking/plugin/dubbox/SWBaseBean.java | 2 +- .../plugin/dubbo/DubboInterceptorTest.java | 9 +- .../dubbo/RequestParamForTestBelow283.java | 4 +- .../v4/HttpClientExecuteInterceptor.java | 70 -- .../httpClient/v4/WebBuriedPointType.java | 18 - .../AbstractHttpClientPluginDefine.java | 36 - .../DefaultRequestDirectorPluginDefine.java | 34 - .../v4/define/HttpClientPluginDefine.java | 15 - .../InternalHttpClientPluginDefine.java | 29 - .../define/MinimalHttpClientPluginDefine.java | 29 - .../src/main/resources/skywalking-plugin.def | 8 +- .../skywalking-sdk-plugin/jdbc-plugin/pom.xml | 128 +- .../plugin/jdbc/CallableStatementTracing.java | 42 - .../api/plugin/jdbc/ConnectionTracing.java | 42 - .../plugin/jdbc/PreparedStatementTracing.java | 36 - .../api/plugin/jdbc/SWCallableStatement.java | 1039 ----------------- .../api/plugin/jdbc/SWConnection.java | 304 ----- .../api/plugin/jdbc/SWPreparedStatement.java | 518 -------- .../api/plugin/jdbc/SWStatement.java | 251 ---- .../api/plugin/jdbc/StatementTracing.java | 42 - .../define/AbstractDatabasePluginDefine.java | 32 - .../plugin/jdbc/define/H2PluginDefine.java | 8 - .../jdbc/define/JDBCBuriedPointType.java | 19 - .../jdbc/define/JDBCDriverInterceptor.java | 32 - .../plugin/jdbc/define/MysqlPluginDefine.java | 11 - .../jdbc/define/OraclePluginDefine.java | 11 - .../src/main/resources/skywalking-plugin.def | 6 +- .../connectionurl/parser/URLParserTest.java | 107 ++ ...structorWithHostAndPortArgInterceptor.java | 5 +- ...ctorWithListHostAndPortArgInterceptor.java | 4 +- ...onstructorWithShardInfoArgInterceptor.java | 3 +- ...isConstructorWithStringArgInterceptor.java | 11 +- ...JedisConstructorWithUriArgInterceptor.java | 3 +- .../jedis/v2/JedisMethodInterceptor.java | 42 +- .../ConsumerFetchRequestURLInterceptor.java | 3 +- .../motan/ConsumerInvokeInterceptor.java | 17 +- .../plugin/motan/ProviderInterceptor.java | 6 +- .../motan/define/ConsumerInstrumentation.java | 19 +- .../motan/define/ProviderInstrumentation.java | 12 +- .../plugin/tomcat78x/TomcatInterceptor.java | 15 +- .../define/TomcatInstrumentation.java | 8 +- .../tomcat78x/TomcatInterceptorTest.java | 6 +- 52 files changed, 365 insertions(+), 2792 deletions(-) delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/HttpClientExecuteInterceptor.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/WebBuriedPointType.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/HttpClientPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/CallableStatementTracing.java delete mode 100755 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/ConnectionTracing.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/PreparedStatementTracing.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWCallableStatement.java delete mode 100755 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWConnection.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWPreparedStatement.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWStatement.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/StatementTracing.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/AbstractDatabasePluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/H2PluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCBuriedPointType.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCDriverInterceptor.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/MysqlPluginDefine.java delete mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/OraclePluginDefine.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/test/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParserTest.java diff --git a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java index 67e841e45..6f80d42c2 100644 --- a/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java +++ b/skywalking-commons/skywalking-trace/src/main/java/com/a/eye/skywalking/trace/tag/Tags.java @@ -48,22 +48,18 @@ public final class Tags { public static final class SPAN_LAYER { private static StringTag SPAN_LAYER_TAG = new StringTag("span.layer"); - private static final String RDB_LAYER = "rdb"; + private static final String DB_LAYER = "db"; private static final String RPC_FRAMEWORK_LAYER = "rpc"; - private static final String NOSQL_LAYER = "nosql"; private static final String HTTP_LAYER = "http"; - public static void asRDB(Span span) { - SPAN_LAYER_TAG.set(span, RDB_LAYER); + public static void asDB(Span span) { + SPAN_LAYER_TAG.set(span, DB_LAYER); } public static void asRPCFramework(Span span) { SPAN_LAYER_TAG.set(span, RPC_FRAMEWORK_LAYER); } - public static void asNoSQL(Span span) { - SPAN_LAYER_TAG.set(span, NOSQL_LAYER); - } public static void asHttp(Span span) { SPAN_LAYER_TAG.set(span, HTTP_LAYER); @@ -73,18 +69,14 @@ public final class Tags { return SPAN_LAYER_TAG.get(span); } - public static boolean isRDB(Span span) { - return RDB_LAYER.equals(get(span)); + public static boolean isDB(Span span) { + return DB_LAYER.equals(get(span)); } public static boolean isRPCFramework(Span span) { return RPC_FRAMEWORK_LAYER.equals(get(span)); } - public static boolean isNoSQL(Span span) { - return NOSQL_LAYER.equals(get(span)); - } - public static boolean isHttp(Span span) { return HTTP_LAYER.equals(get(span)); } @@ -107,9 +99,24 @@ public final class Tags { public static final StringTag PEER_HOST = new StringTag("peer.host"); /** - * DB_URL records the url of the database access. + * PEER_PORT records remote port of the peer */ - public static final StringTag DB_URL = new StringTag("db.url"); + public static final IntTag PEER_PORT = new IntTag("peer.port"); + + /** + * PEERS records multiple host address and port of remote + */ + public static final StringTag PEERS = new StringTag("peers"); + + /** + * DB_TYPE records database type, such as sql, redis, cassandra and so on. + */ + public static final StringTag DB_TYPE = new StringTag("db.type"); + + /** + * DB_INSTANCE records database instance name. + */ + public static final StringTag DB_INSTANCE = new StringTag("db.instance"); /** * DB_STATEMENT records the sql statement of the database access. diff --git a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java index f1b05855b..517a4bfcb 100644 --- a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java +++ b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java @@ -45,7 +45,6 @@ public class SpanTestCase { Tags.ERROR.set(span1, true); Tags.STATUS_CODE.set(span1, 302); Tags.URL.set(span1, "http://127.0.0.1/serviceA"); - Tags.DB_URL.set(span1, "jdbc:127.0.0.1:user"); Tags.DB_STATEMENT.set(span1, "select * from users"); Map tags = span1.getTags(); diff --git a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java index 46843831f..51e6947b9 100644 --- a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java +++ b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/TraceSegmentTestCase.java @@ -96,7 +96,7 @@ public class TraceSegmentTestCase { segment.archive(span1); Span span2 = new Span(2, span1, "/db/sql"); - Tags.SPAN_LAYER.asNoSQL(span2); + Tags.SPAN_LAYER.asDB(span2); span2.log(new NullPointerException()); segment.archive(span2); diff --git a/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java b/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java index 21868ecc7..74a72a64b 100644 --- a/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java +++ b/skywalking-sniffer/skywalking-agent/src/main/java/com/a/eye/skywalking/agent/SkyWalkingAgent.java @@ -1,15 +1,16 @@ package com.a.eye.skywalking.agent; import com.a.eye.skywalking.agent.junction.SkyWalkingEnhanceMatcher; -import com.a.eye.skywalking.conf.Config; +import com.a.eye.skywalking.api.conf.Config; import com.a.eye.skywalking.api.conf.SnifferConfigInitializer; -import com.a.eye.skywalking.logging.EasyLogResolver; +import com.a.eye.skywalking.api.logging.EasyLogResolver; import com.a.eye.skywalking.api.logging.api.ILog; import com.a.eye.skywalking.api.logging.api.LogManager; import com.a.eye.skywalking.api.plugin.AbstractClassEnhancePluginDefine; import com.a.eye.skywalking.api.plugin.PluginBootstrap; import com.a.eye.skywalking.api.plugin.PluginDefineCategory; -import com.a.eye.skywalking.plugin.PluginException; +import com.a.eye.skywalking.api.plugin.PluginException; + import net.bytebuddy.agent.builder.AgentBuilder; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.type.TypeDescription; diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/EnhanceException.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/EnhanceException.java index dec61a839..4e3139f1b 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/EnhanceException.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/EnhanceException.java @@ -1,5 +1,6 @@ package com.a.eye.skywalking.api.plugin.interceptor; + import com.a.eye.skywalking.api.plugin.PluginException; public class EnhanceException extends PluginException { diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassEnhancePluginDefine.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassEnhancePluginDefine.java index cd0f92858..4dfd7709e 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassEnhancePluginDefine.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassEnhancePluginDefine.java @@ -10,6 +10,7 @@ import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; import com.a.eye.skywalking.api.plugin.interceptor.StaticMethodsInterceptPoint; import com.a.eye.skywalking.api.util.StringUtil; + import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.implementation.MethodDelegation; @@ -25,7 +26,7 @@ import static net.bytebuddy.matcher.ElementMatchers.not; * This class controls all enhance operations, including enhance constructors, instance methods and static methods. * All the enhances base on three types interceptor point: {@link ConstructorInterceptPoint}, {@link InstanceMethodsInterceptPoint} and {@link StaticMethodsInterceptPoint} * If plugin is going to enhance constructors, instance methods, or both, - * {@link ClassEnhancePluginDefine} will add a field of {@link EnhancedClassInstanceContext} type. + * {@link ClassEnhancePluginDefine} will add a field of {@link com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext} type. * * @author wusheng */ @@ -44,7 +45,6 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi * @param enhanceOriginClassName target class name * @param newClassBuilder byte-buddy's builder to manipulate class bytecode. * @return new byte-buddy's builder for further manipulation. - * @throws PluginException */ @Override protected DynamicType.Builder enhance(String enhanceOriginClassName, DynamicType.Builder newClassBuilder) throws PluginException { @@ -61,7 +61,6 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi * @param enhanceOriginClassName target class name * @param newClassBuilder byte-buddy's builder to manipulate class bytecode. * @return new byte-buddy's builder for further manipulation. - * @throws PluginException */ private DynamicType.Builder enhanceInstance(String enhanceOriginClassName, DynamicType.Builder newClassBuilder) throws PluginException { ConstructorInterceptPoint[] constructorInterceptPoints = getConstructorsInterceptPoints(); @@ -150,7 +149,6 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi * @param enhanceOriginClassName target class name * @param newClassBuilder byte-buddy's builder to manipulate class bytecode. * @return new byte-buddy's builder for further manipulation. - * @throws PluginException */ private DynamicType.Builder enhanceClass(String enhanceOriginClassName, DynamicType.Builder newClassBuilder) throws PluginException { StaticMethodsInterceptPoint[] staticMethodsInterceptPoints = getStaticMethodsInterceptPoints(); diff --git a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java index 9a3888775..8f5cb2a0e 100644 --- a/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java +++ b/skywalking-sniffer/skywalking-api/src/main/java/com/a/eye/skywalking/api/plugin/interceptor/enhance/ClassInstanceMethodsEnhancePluginDefine.java @@ -1,5 +1,6 @@ package com.a.eye.skywalking.api.plugin.interceptor.enhance; + import com.a.eye.skywalking.api.plugin.interceptor.StaticMethodsInterceptPoint; /** diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java index 0890dcdcc..330b2cc63 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java @@ -20,11 +20,11 @@ import static net.bytebuddy.matcher.ElementMatchers.named; public class DubboInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { /** - * Enhance class + * Enhance class. */ private static final String ENHANCE_CLASS = "com.alibaba.dubbo.monitor.support.MonitorFilter"; /** - * Intercept class + * Intercept class. */ private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.dubbo.DubboInterceptor"; diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java index 304db4ebb..1ec77436d 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java @@ -2,21 +2,22 @@ package com.a.eye.skywalking.plugin.dubbo; import com.a.eye.skywalking.api.context.ContextCarrier; import com.a.eye.skywalking.api.context.ContextManager; -import com.a.eye.skywalking.plugin.dubbox.BugFixActive; -import com.a.eye.skywalking.plugin.dubbox.SWBaseBean; import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext; import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; +import com.a.eye.skywalking.plugin.dubbox.BugFixActive; +import com.a.eye.skywalking.plugin.dubbox.SWBaseBean; import com.a.eye.skywalking.trace.Span; import com.a.eye.skywalking.trace.tag.Tags; +import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invoker; import com.alibaba.dubbo.rpc.Result; import com.alibaba.dubbo.rpc.RpcContext; /** - * {@link DubboInterceptor} define how to enhance class{@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}. + * {@link DubboInterceptor} define how to enhance class {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}. * the context data will transport to the provider side by {@link RpcContext#attachments}.but all the version of dubbo framework below 2.8.3 * don't support {@link RpcContext#attachments}, we support another way to support it. it is that all request parameters of dubbo service * need to extend {@link SWBaseBean}, and {@link DubboInterceptor} will inject the serialized context data to the {@link SWBaseBean} bean and @@ -39,10 +40,6 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { * The serialized context data will extract from the first param that extend {@link SWBaseBean} of dubbo service * if the method {@link BugFixActive#active()} be called. or it will extract from {@link RpcContext#attachments}. * current trace segment will ref if the serialize context data is not null. - * - * @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance. - * @param interceptorContext method context, includes class name, method name, etc. - * @param result change this result, if you want to truncate the method. */ @Override public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, @@ -52,8 +49,15 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { Invocation invocation = (Invocation) arguments[1]; RpcContext rpcContext = RpcContext.getContext(); boolean isConsumer = rpcContext.isConsumerSide(); + URL requestURL = invoker.getUrl(); + + Span span = ContextManager.INSTANCE.createSpan(generateOperationName(requestURL, invocation)); + Tags.URL.set(span, generateRequestURL(requestURL, invocation)); + Tags.COMPONENT.set(span, DUBBO_COMPONENT); + Tags.PEER_HOST.set(span, requestURL.getHost()); + Tags.PEER_PORT.set(span, requestURL.getPort()); + Tags.SPAN_LAYER.asRPCFramework(span); - Span span = ContextManager.INSTANCE.createSpan(generateOperationName(invoker, invocation)); if (isConsumer) { Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT); ContextCarrier contextCarrier = new ContextCarrier(); @@ -91,20 +95,12 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { ContextManager.INSTANCE.extract(new ContextCarrier().deserialize(contextDataStr)); } } - - Tags.URL.set(span, generateRequestURL(invoker, invocation)); - Tags.COMPONENT.set(span, DUBBO_COMPONENT); - Tags.SPAN_LAYER.asRPCFramework(span); } /** * {@link DubboInterceptor#afterMethod(EnhancedClassInstanceContext, InstanceMethodInvokeContext, Object)} be executed after * {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}, and it will check {@link Result#getException()} if is null. * current active span will log the exception and set true to the value of error tag if the {@link Result#getException()} is not null. - * - * @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance. - * @param interceptorContext method context, includes class name, method name, etc. - * @param ret the method's original return value. */ @Override public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, @@ -135,13 +131,13 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { /** * Generate operation name. - * the operation name should be like this com.a.eye.skywalking.plugin.test.Test.test(String) + * the operation name should be like this com.a.eye.skywalking.plugin.test.Test.test(String). * - * @return operation name + * @return operation name. */ - private static String generateOperationName(Invoker invoker, Invocation invocation) { + private static String generateOperationName(URL requestURL, Invocation invocation) { StringBuilder operationName = new StringBuilder(); - operationName.append(invoker.getUrl().getPath()); + operationName.append(requestURL.getPath()); operationName.append("." + invocation.getMethodName() + "("); for (Class classes : invocation.getParameterTypes()) { operationName.append(classes.getSimpleName() + ","); @@ -158,23 +154,23 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { /** * Generate request url. - * The request url may be like this dubbo://127.0.0.1:20880/com.a.eye.skywalking.plugin.test.Test.test(String) + * The request url may be like this dubbo://127.0.0.1:20880/com.a.eye.skywalking.plugin.test.Test.test(String). * - * @return request url + * @return request url. */ - private static String generateRequestURL(Invoker invoker, Invocation invocation) { + private static String generateRequestURL(URL url, Invocation invocation) { StringBuilder requestURL = new StringBuilder(); - requestURL.append(invoker.getUrl().getProtocol() + "://"); - requestURL.append(invoker.getUrl().getHost()); - requestURL.append(":" + invoker.getUrl().getPort() + "/"); - requestURL.append(generateOperationName(invoker, invocation)); + requestURL.append(url.getProtocol() + "://"); + requestURL.append(url.getHost()); + requestURL.append(":" + url.getPort() + "/"); + requestURL.append(generateOperationName(url, invocation)); return requestURL.toString(); } /** - * Set the serialized context data to the first request param that extend {@link SWBaseBean} of dubbo service + * Set the serialized context data to the first request param that extend {@link SWBaseBean} of dubbo service. * - * @param contextDataStr serialized context data + * @param contextDataStr serialized context data. */ private static void fix283SendNoAttachmentIssue(Invocation invocation, String contextDataStr) { for (Object parameter : invocation.getArguments()) { @@ -188,7 +184,7 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { /** * Fetch the serialize context data from the first request param that extend {@link SWBaseBean} of dubbo service. * - * @return serialized context data + * @return serialized context data. */ private static String fix283RecvNoAttachmentIssue(Invocation invocation) { for (Object parameter : invocation.getArguments()) { diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java index 12e316218..e09f536b2 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java @@ -3,7 +3,9 @@ package com.a.eye.skywalking.plugin.dubbox; /** * {@link BugFixActive#active} is an flag that present the dubbox version is below 2.8.3, * The version 2.8.3 of dubbox don't support attachment. so skywalking provided another way - * to support the function that transport the serialized context data. the way that + * to support the function that transport the serialized context data. The way is that + * all parameters of dubbo service need to extend {@link SWBaseBean}, {@link com.a.eye.skywalking.plugin.dubbo.DubboInterceptor} + * fetch the serialized context data by using {@link SWBaseBean#getContextData()}. * * @author zhangxin */ @@ -19,7 +21,7 @@ public final class BugFixActive { } - public static boolean isActive(){ + public static boolean isActive() { return BugFixActive.active; } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java index 5f478d1ca..eaf6f71fe 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java @@ -10,7 +10,7 @@ import java.io.Serializable; */ public class SWBaseBean implements Serializable { /** - * Serialized context data + * Serialized context data. */ private String contextData; diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java index 26b88e7b0..7e6cfb214 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java @@ -89,7 +89,7 @@ public class DubboInterceptorTest { public void call(TraceSegment traceSegment) { assertThat(traceSegment.getSpans().size(), is(1)); assertConsumerSpan(traceSegment.getSpans().get(0)); - testParam.assertSelf("0"); + testParam.assertSelf("0", "127.0.0.1"); } }); } @@ -143,7 +143,7 @@ public class DubboInterceptorTest { @Test public void testProviderWithAttachment() { when(rpcContext.isConsumerSide()).thenReturn(false); - when(rpcContext.getAttachment(DubboInterceptor.ATTACHMENT_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1"); + when(rpcContext.getAttachment(DubboInterceptor.ATTACHMENT_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1"); dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); dubboInterceptor.afterMethod(classInstanceContext, methodInvokeContext, result); @@ -156,7 +156,7 @@ public class DubboInterceptorTest { when(rpcContext.isConsumerSide()).thenReturn(false); when(BugFixActive.isActive()).thenReturn(true); - testParam.setContextData("302017.1487666919810.624424584.17332.1.1|1"); + testParam.setContextData("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1"); dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); @@ -175,7 +175,8 @@ public class DubboInterceptorTest { } private void assertErrorLog(LogData logData) { - assertThat(logData.getFields().size(), is(3)); + assertThat(logData.getFields().size(), is(4)); + assertThat(logData.getFields().get("event"), CoreMatchers.is("error")); assertThat(logData.getFields().get("error.kind"), CoreMatchers.is(RuntimeException.class.getName())); assertNull(logData.getFields().get("message")); } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java index 3ca038a17..7c3783b82 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java @@ -17,8 +17,8 @@ public class RequestParamForTestBelow283 extends SWBaseBean { * * @param expectSpanId expect span id */ - public void assertSelf(String expectSpanId) { + public void assertSelf(String expectSpanId, String expectHost) { assertNotNull(getContextData()); - assertThat(getContextData(), endsWith(expectSpanId)); + assertThat(getContextData(), endsWith(expectSpanId + "|" + expectHost)); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/HttpClientExecuteInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/HttpClientExecuteInterceptor.java deleted file mode 100644 index 514dd6151..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/HttpClientExecuteInterceptor.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.a.eye.skywalking.api.plugin.httpClient.v4; - -import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; -import com.a.eye.skywalking.plugin.interceptor.enhance.ConstructorInvokeContext; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; - -import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor; -import com.a.eye.skywalking.model.Identification; -import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; - -public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterceptor { - /** - * default headname of sky walking context
- */ - public static String TRACE_HEAD_NAME = "SkyWalking-TRACING-NAME"; - - private static RPCClientInvokeMonitor rpcClientInvokeMonitor = new RPCClientInvokeMonitor(); - - @Override - public void beforeMethod(EnhancedClassInstanceContext context, - InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { - Object[] allArguments = interceptorContext.allArguments(); - if (allArguments[0] == null || allArguments[1] == null) { - // illegal args, can't trace. ignore. - return; - } - HttpHost httpHost = (HttpHost) allArguments[0]; - HttpRequest httpRequest = (HttpRequest) allArguments[1]; - httpRequest - .setHeader( - TRACE_HEAD_NAME, - "ContextData=" - + rpcClientInvokeMonitor.beforeInvoke( - Identification - .newBuilder() - .viewPoint( - httpHost.toURI() - .toString()) - .spanType( - WebBuriedPointType - .INSTANCE) - .build()).toString()); - } - - @Override - public Object afterMethod(EnhancedClassInstanceContext context, - InstanceMethodInvokeContext interceptorContext, Object ret) { - Object[] allArguments = interceptorContext.allArguments(); - if (allArguments[0] == null || allArguments[1] == null) { - // illegal args, can't trace. ignore. - return ret; - } - rpcClientInvokeMonitor.afterInvoke(); - return ret; - } - - @Override - public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext) { - Object[] allArguments = interceptorContext.allArguments(); - if (allArguments[0] == null || allArguments[1] == null) { - // illegal args, can't trace. ignore. - return; - } - rpcClientInvokeMonitor.occurException(t); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/WebBuriedPointType.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/WebBuriedPointType.java deleted file mode 100644 index b4e60faa7..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/WebBuriedPointType.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.a.eye.skywalking.api.plugin.httpClient.v4; - -import com.a.eye.skywalking.api.IBuriedPointType; - -public enum WebBuriedPointType implements IBuriedPointType { - INSTANCE; - - @Override - public String getTypeName() { - return "W"; - } - - @Override - public CallType getCallType() { - return CallType.SYNC; - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java deleted file mode 100644 index 33f7505fe..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/AbstractHttpClientPluginDefine.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.a.eye.skywalking.api.plugin.httpClient.v4.define; - -import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.named; - -public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine { - - @Override - public String enhanceClassName() { - return "org.apache.http.impl.client.AbstractHttpClient"; - } - - /** - * version 4.2, intercept method: execute, intercept
- * public final HttpResponse execute(HttpHost target, HttpRequest request, - * HttpContext context)
- * - */ - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("doExecute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java deleted file mode 100644 index 540b2fbbf..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/DefaultRequestDirectorPluginDefine.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.a.eye.skywalking.api.plugin.httpClient.v4.define; - -import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.named; - -public class DefaultRequestDirectorPluginDefine extends HttpClientPluginDefine { - /** - * DefaultRequestDirector is default implement.
- * usually use in version 4.0-4.2
- * since 4.3, this class is Deprecated. - */ - @Override - public String enhanceClassName() { - return "org.apache.http.impl.client.DefaultRequestDirector"; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("execute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/HttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/HttpClientPluginDefine.java deleted file mode 100644 index fd1616114..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/HttpClientPluginDefine.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.a.eye.skywalking.api.plugin.httpClient.v4.define; - -import com.a.eye.skywalking.plugin.interceptor.ConstructorInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; - -public abstract class HttpClientPluginDefine extends ClassInstanceMethodsEnhancePluginDefine { - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - protected String getInstanceMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.httpClient.v4.HttpClientExecuteInterceptor"; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java deleted file mode 100644 index 832c3390d..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/InternalHttpClientPluginDefine.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.a.eye.skywalking.api.plugin.httpClient.v4.define; - -import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.named; - -public class InternalHttpClientPluginDefine extends HttpClientPluginDefine { - @Override - public String enhanceClassName() { - return "org.apache.http.impl.client.InternalHttpClient"; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("doExecute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java deleted file mode 100644 index 100a8a37f..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/api/plugin/httpClient/v4/define/MinimalHttpClientPluginDefine.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.a.eye.skywalking.api.plugin.httpClient.v4.define; - -import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.named; - -public class MinimalHttpClientPluginDefine extends HttpClientPluginDefine { - @Override - public String enhanceClassName() { - return "org.apache.http.impl.client.MinimalHttpClient"; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("doExecute"); - } - - @Override - public String getMethodsInterceptor() { - return getInstanceMethodsInterceptor(); - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def index 200935980..da07902ec 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,4 +1,4 @@ -com.a.eye.skywalking.plugin.httpClient.v4.define.AbstractHttpClientPluginDefine -com.a.eye.skywalking.plugin.httpClient.v4.define.InternalHttpClientPluginDefine -com.a.eye.skywalking.plugin.httpClient.v4.define.MinimalHttpClientPluginDefine -com.a.eye.skywalking.plugin.httpClient.v4.define.DefaultRequestDirectorPluginDefine +com.a.eye.skywalking.plugin.httpClient.v4.define.AbstractHttpClientInstrumentation +com.a.eye.skywalking.plugin.httpClient.v4.define.InternalHttpClientInstrumentation +com.a.eye.skywalking.plugin.httpClient.v4.define.MinimalHttpClientInstrumentation +com.a.eye.skywalking.plugin.httpClient.v4.define.DefaultRequestDirectorInstrumentation diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml index 43e773797..db239652d 100755 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/pom.xml @@ -1,68 +1,74 @@ - - skywalking-sdk-plugin - com.a.eye - 3.0-2017 - - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + skywalking-sdk-plugin + com.a.eye + 3.0-2017 + + 4.0.0 - skywalking-jdbc-plugin - jar + skywalking-jdbc-plugin + jar - jdbc-plugin - http://maven.apache.org + jdbc-plugin + http://maven.apache.org - - UTF-8 - + + UTF-8 + - - - com.a.eye - skywalking-api - 3.0-2017 - - - mysql - mysql-connector-java - 5.1.36 - test - - - com.oracle - ojdbc14 - 10.2.0.4.0 - test - - - com.h2database - h2 - 1.4.192 - test - - + + + com.a.eye + skywalking-api + 3.0-2017 + + + mysql + mysql-connector-java + 5.1.36 + test + + + com.oracle + ojdbc14 + 10.2.0.4.0 + test + + + com.h2database + h2 + 1.4.192 + provided + + + mysql + mysql-connector-java + [2.0.14,) + provided + + - - - - org.apache.maven.plugins - maven-deploy-plugin - - - - org.apache.maven.plugins - maven-source-plugin - - - - attach-sources - - jar - - - - - - + + + + org.apache.maven.plugins + maven-deploy-plugin + + + + org.apache.maven.plugins + maven-source-plugin + + + + attach-sources + + jar + + + + + + diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/CallableStatementTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/CallableStatementTracing.java deleted file mode 100644 index 48dc1b55e..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/CallableStatementTracing.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc; - -import com.a.eye.skywalking.api.plugin.jdbc.define.JDBCBuriedPointType; -import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor; -import com.a.eye.skywalking.model.Identification; - -import java.sql.SQLException; - -/** - * 连接级追踪,用于追踪用于Connection的操作追踪 - * - * @author wusheng - */ -public class CallableStatementTracing { - private static RPCClientInvokeMonitor rpcClientInvokeMonitor = new RPCClientInvokeMonitor(); - - public static R execute(java.sql.CallableStatement realStatement, - String connectInfo, String method, String sql, Executable exec) - throws SQLException { - try { - rpcClientInvokeMonitor.beforeInvoke(Identification - .newBuilder() - .viewPoint(connectInfo) - .businessKey( - "callableStatement." - + method - + (sql == null || sql.length() == 0 ? "" - : ":" + sql)).spanType(JDBCBuriedPointType.INSTANCE).build()); - return exec.exe(realStatement, sql); - } catch (SQLException e) { - rpcClientInvokeMonitor.occurException(e); - throw e; - } finally { - rpcClientInvokeMonitor.afterInvoke(); - } - } - - public interface Executable { - public R exe(java.sql.CallableStatement realConnection, String sql) - throws SQLException; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/ConnectionTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/ConnectionTracing.java deleted file mode 100755 index d100efa44..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/ConnectionTracing.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc; - -import com.a.eye.skywalking.api.plugin.jdbc.define.JDBCBuriedPointType; -import com.a.eye.skywalking.model.Identification; -import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor; - -import java.sql.SQLException; - -/** - * 连接级追踪,用于追踪用于Connection的操作追踪 - * - * @author wusheng - */ -public class ConnectionTracing { - private static RPCClientInvokeMonitor rpcClientInvokeMonitor = new RPCClientInvokeMonitor(); - - public static R execute(java.sql.Connection realConnection, - String connectInfo, String method, String sql, Executable exec) - throws SQLException { - try { - rpcClientInvokeMonitor.beforeInvoke(Identification - .newBuilder() - .viewPoint(connectInfo) - .businessKey( - "connection." - + method - + (sql == null || sql.length() == 0 ? "" - : ":" + sql)).spanType(JDBCBuriedPointType.INSTANCE).build()); - return exec.exe(realConnection, sql); - } catch (SQLException e) { - rpcClientInvokeMonitor.occurException(e); - throw e; - } finally { - rpcClientInvokeMonitor.afterInvoke(); - } - } - - public interface Executable { - public R exe(java.sql.Connection realConnection, String sql) - throws SQLException; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/PreparedStatementTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/PreparedStatementTracing.java deleted file mode 100644 index d20d97106..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/PreparedStatementTracing.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc; - -import com.a.eye.skywalking.api.context.ContextManager; -import com.a.eye.skywalking.trace.Span; -import com.a.eye.skywalking.trace.tag.Tags; -import java.sql.SQLException; - -/** - * 连接级追踪,用于追踪用于Connection的操作追踪 - * - * @author wusheng - */ -public class PreparedStatementTracing { - - public static R execute(java.sql.PreparedStatement realStatement, - String connectInfo, String method, String sql, Executable exec) - throws SQLException { - Span span = ContextManager.INSTANCE.createSpan("JDBC/PreparedStatement/" + method); - try { - Tags.SPAN_LAYER.asRDB(span); - Tags.DB_URL.set(span, connectInfo); - Tags.DB_STATEMENT.set(span, sql); - return exec.exe(realStatement, sql); - } catch (SQLException e) { - span.log(e); - throw e; - } finally { - ContextManager.INSTANCE.stopSpan(span); - } - } - - public interface Executable { - R exe(java.sql.PreparedStatement realConnection, String sql) - throws SQLException; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWCallableStatement.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWCallableStatement.java deleted file mode 100644 index 70141c53d..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWCallableStatement.java +++ /dev/null @@ -1,1039 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.*; -import java.util.Calendar; -import java.util.Map; - -public class SWCallableStatement implements CallableStatement { - private Connection realConnection; - private CallableStatement realStatement; - private String connectInfo; - private String sql; - - SWCallableStatement(Connection realConnection, - CallableStatement realStatement, String connectInfo, - String sql) { - this.realConnection = realConnection; - this.realStatement = realStatement; - this.connectInfo = connectInfo; - this.sql = sql; - } - - public ResultSet executeQuery() throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeQuery", sql, new CallableStatementTracing.Executable() { - public ResultSet exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeQuery(); - } - }); - } - - public int executeUpdate() throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeUpdate", sql, new CallableStatementTracing.Executable() { - public Integer exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(); - } - }); - } - - public void setNull(int parameterIndex, int sqlType) throws SQLException { - realStatement.setNull(parameterIndex, sqlType); - } - - public void setBoolean(int parameterIndex, boolean x) throws SQLException { - realStatement.setBoolean(parameterIndex, x); - } - - public void setByte(int parameterIndex, byte x) throws SQLException { - realStatement.setByte(parameterIndex, x); - } - - public void setShort(int parameterIndex, short x) throws SQLException { - realStatement.setShort(parameterIndex, x); - } - - public void setInt(int parameterIndex, int x) throws SQLException { - realStatement.setInt(parameterIndex, x); - } - - public void setLong(int parameterIndex, long x) throws SQLException { - realStatement.setLong(parameterIndex, x); - } - - public void setFloat(int parameterIndex, float x) throws SQLException { - realStatement.setFloat(parameterIndex, x); - } - - public void setDouble(int parameterIndex, double x) throws SQLException { - realStatement.setDouble(parameterIndex, x); - } - - public void setBigDecimal(int parameterIndex, BigDecimal x) - throws SQLException { - realStatement.setBigDecimal(parameterIndex, x); - } - - public void setString(int parameterIndex, String x) throws SQLException { - realStatement.setString(parameterIndex, x); - } - - public void setBytes(int parameterIndex, byte[] x) throws SQLException { - realStatement.setBytes(parameterIndex, x); - } - - public void setDate(int parameterIndex, Date x) throws SQLException { - realStatement.setDate(parameterIndex, x); - } - - public void setTime(int parameterIndex, Time x) throws SQLException { - realStatement.setTime(parameterIndex, x); - } - - public void setTimestamp(int parameterIndex, Timestamp x) - throws SQLException { - realStatement.setTimestamp(parameterIndex, x); - } - - public void setAsciiStream(int parameterIndex, InputStream x, int length) - throws SQLException { - realStatement.setAsciiStream(parameterIndex, x, length); - } - - @Deprecated - public void setUnicodeStream(int parameterIndex, InputStream x, int length) - throws SQLException { - realStatement.setUnicodeStream(parameterIndex, x, length); - } - - public void setBinaryStream(int parameterIndex, InputStream x, int length) - throws SQLException { - realStatement.setBinaryStream(parameterIndex, x, length); - } - - public void clearParameters() throws SQLException { - realStatement.clearParameters(); - } - - public void setObject(int parameterIndex, Object x, int targetSqlType) - throws SQLException { - realStatement.setObject(parameterIndex, x, targetSqlType); - } - - public void setObject(int parameterIndex, Object x) throws SQLException { - realStatement.setObject(parameterIndex, x); - } - - public boolean execute() throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "execute", sql, new CallableStatementTracing.Executable() { - public Boolean exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(); - } - }); - } - - public void addBatch() throws SQLException { - realStatement.addBatch(); - } - - public void setCharacterStream(int parameterIndex, Reader reader, int length) - throws SQLException { - realStatement.setCharacterStream(parameterIndex, reader, length); - } - - public void setRef(int parameterIndex, Ref x) throws SQLException { - realStatement.setRef(parameterIndex, x); - } - - public void setBlob(int parameterIndex, Blob x) throws SQLException { - realStatement.setBlob(parameterIndex, x); - } - - public void setClob(int parameterIndex, Clob x) throws SQLException { - realStatement.setClob(parameterIndex, x); - } - - public void setArray(int parameterIndex, Array x) throws SQLException { - realStatement.setArray(parameterIndex, x); - } - - public ResultSetMetaData getMetaData() throws SQLException { - return realStatement.getMetaData(); - } - - public void setDate(int parameterIndex, Date x, Calendar cal) - throws SQLException { - realStatement.setDate(parameterIndex, x, cal); - } - - public void setTime(int parameterIndex, Time x, Calendar cal) - throws SQLException { - realStatement.setTime(parameterIndex, x, cal); - } - - public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) - throws SQLException { - realStatement.setTimestamp(parameterIndex, x, cal); - } - - public void setNull(int parameterIndex, int sqlType, String typeName) - throws SQLException { - realStatement.setNull(parameterIndex, sqlType, typeName); - } - - public void setURL(int parameterIndex, URL x) throws SQLException { - realStatement.setURL(parameterIndex, x); - } - - public ParameterMetaData getParameterMetaData() throws SQLException { - return realStatement.getParameterMetaData(); - } - - public void setRowId(int parameterIndex, RowId x) throws SQLException { - realStatement.setRowId(parameterIndex, x); - } - - public void setNString(int parameterIndex, String value) - throws SQLException { - realStatement.setNString(parameterIndex, value); - } - - public void setNCharacterStream(int parameterIndex, Reader value, - long length) throws SQLException { - realStatement.setNCharacterStream(parameterIndex, value, length); - } - - public void setNClob(int parameterIndex, NClob value) throws SQLException { - realStatement.setNClob(parameterIndex, value); - } - - public void setClob(int parameterIndex, Reader reader, long length) - throws SQLException { - realStatement.setClob(parameterIndex, reader, length); - } - - public void setBlob(int parameterIndex, InputStream inputStream, long length) - throws SQLException { - realStatement.setBlob(parameterIndex, inputStream, length); - } - - public void setNClob(int parameterIndex, Reader reader, long length) - throws SQLException { - realStatement.setNClob(parameterIndex, reader, length); - } - - public void setSQLXML(int parameterIndex, SQLXML xmlObject) - throws SQLException { - realStatement.setSQLXML(parameterIndex, xmlObject); - } - - public void setObject(int parameterIndex, Object x, int targetSqlType, - int scaleOrLength) throws SQLException { - realStatement - .setObject(parameterIndex, x, targetSqlType, scaleOrLength); - } - - public void setAsciiStream(int parameterIndex, InputStream x, long length) - throws SQLException { - realStatement.setAsciiStream(parameterIndex, x, length); - } - - public void setBinaryStream(int parameterIndex, InputStream x, long length) - throws SQLException { - realStatement.setBinaryStream(parameterIndex, x, length); - } - - public void setCharacterStream(int parameterIndex, Reader reader, - long length) throws SQLException { - realStatement.setCharacterStream(parameterIndex, reader, length); - } - - public void setAsciiStream(int parameterIndex, InputStream x) - throws SQLException { - realStatement.setAsciiStream(parameterIndex, x); - } - - public void setBinaryStream(int parameterIndex, InputStream x) - throws SQLException { - realStatement.setBinaryStream(parameterIndex, x); - } - - public void setCharacterStream(int parameterIndex, Reader reader) - throws SQLException { - realStatement.setCharacterStream(parameterIndex, reader); - } - - public void setNCharacterStream(int parameterIndex, Reader value) - throws SQLException { - realStatement.setNCharacterStream(parameterIndex, value); - } - - public void setClob(int parameterIndex, Reader reader) throws SQLException { - realStatement.setClob(parameterIndex, reader); - } - - public void setBlob(int parameterIndex, InputStream inputStream) - throws SQLException { - realStatement.setBlob(parameterIndex, inputStream); - } - - public void setNClob(int parameterIndex, Reader reader) throws SQLException { - realStatement.setNClob(parameterIndex, reader); - } - - public ResultSet executeQuery(String sql) throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeQuery", sql, new CallableStatementTracing.Executable() { - public ResultSet exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeQuery(sql); - } - }); - } - - public int executeUpdate(String sql) throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeUpdate", sql, new CallableStatementTracing.Executable() { - public Integer exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql); - } - }); - } - - public void close() throws SQLException { - realStatement.close(); - } - - public int getMaxFieldSize() throws SQLException { - return realStatement.getMaxFieldSize(); - } - - public void setMaxFieldSize(int max) throws SQLException { - realStatement.setMaxFieldSize(max); - } - - public int getMaxRows() throws SQLException { - return realStatement.getMaxRows(); - } - - public void setMaxRows(int max) throws SQLException { - realStatement.setMaxRows(max); - } - - public void setEscapeProcessing(boolean enable) throws SQLException { - realStatement.setEscapeProcessing(enable); - } - - public int getQueryTimeout() throws SQLException { - return realStatement.getQueryTimeout(); - } - - public void setQueryTimeout(int seconds) throws SQLException { - realStatement.setQueryTimeout(seconds); - } - - public void cancel() throws SQLException { - realStatement.cancel(); - } - - public SQLWarning getWarnings() throws SQLException { - return realStatement.getWarnings(); - } - - public void clearWarnings() throws SQLException { - realStatement.clearWarnings(); - } - - public void setCursorName(String name) throws SQLException { - realStatement.setCursorName(name); - } - - public boolean execute(String sql) throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "execute", sql, new CallableStatementTracing.Executable() { - public Boolean exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql); - } - }); - } - - public ResultSet getResultSet() throws SQLException { - return realStatement.getResultSet(); - } - - public int getUpdateCount() throws SQLException { - return realStatement.getUpdateCount(); - } - - public boolean getMoreResults() throws SQLException { - return realStatement.getMoreResults(); - } - - public void setFetchDirection(int direction) throws SQLException { - realStatement.setFetchDirection(direction); - } - - public int getFetchDirection() throws SQLException { - return realStatement.getFetchDirection(); - } - - public void setFetchSize(int rows) throws SQLException { - realStatement.setFetchSize(rows); - } - - public int getFetchSize() throws SQLException { - return realStatement.getFetchSize(); - } - - public int getResultSetConcurrency() throws SQLException { - return realStatement.getResultSetConcurrency(); - } - - public int getResultSetType() throws SQLException { - return realStatement.getResultSetType(); - } - - public void addBatch(String sql) throws SQLException { - realStatement.addBatch(); - } - - public void clearBatch() throws SQLException { - realStatement.clearBatch(); - } - - public int[] executeBatch() throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeBatch", "", new CallableStatementTracing.Executable() { - public int[] exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeBatch(); - } - }); - } - - public Connection getConnection() throws SQLException { - return this.realConnection; - } - - public boolean getMoreResults(int current) throws SQLException { - return realStatement.getMoreResults(current); - } - - public ResultSet getGeneratedKeys() throws SQLException { - return realStatement.getGeneratedKeys(); - } - - public int executeUpdate(String sql, final int autoGeneratedKeys) - throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeUpdate", sql, new CallableStatementTracing.Executable() { - public Integer exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, autoGeneratedKeys); - } - }); - } - - public int executeUpdate(String sql, final int[] columnIndexes) - throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeUpdate", sql, new CallableStatementTracing.Executable() { - public Integer exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, columnIndexes); - } - }); - } - - public int executeUpdate(String sql, final String[] columnNames) - throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "executeUpdate", sql, new CallableStatementTracing.Executable() { - public Integer exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, columnNames); - } - }); - } - - public boolean execute(String sql, final int autoGeneratedKeys) - throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "execute", sql, new CallableStatementTracing.Executable() { - public Boolean exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, autoGeneratedKeys); - } - }); - } - - public boolean execute(String sql, final int[] columnIndexes) throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "execute", sql, new CallableStatementTracing.Executable() { - public Boolean exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, columnIndexes); - } - }); - } - - public boolean execute(String sql, final String[] columnNames) - throws SQLException { - return CallableStatementTracing.execute(realStatement, connectInfo, - "execute", sql, new CallableStatementTracing.Executable() { - public Boolean exe( - CallableStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, columnNames); - } - }); - } - - public int getResultSetHoldability() throws SQLException { - return realStatement.getResultSetHoldability(); - } - - public boolean isClosed() throws SQLException { - return realStatement.isClosed(); - } - - public void setPoolable(boolean poolable) throws SQLException { - realStatement.setPoolable(poolable); - } - - public boolean isPoolable() throws SQLException { - return realStatement.isPoolable(); - } - - public void closeOnCompletion() throws SQLException { - realStatement.closeOnCompletion(); - } - - public boolean isCloseOnCompletion() throws SQLException { - return realStatement.isCloseOnCompletion(); - } - - public T unwrap(Class iface) throws SQLException { - return realStatement.unwrap(iface); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return realStatement.isWrapperFor(iface); - } - - public void registerOutParameter(int parameterIndex, int sqlType) - throws SQLException { - realStatement.registerOutParameter(parameterIndex, sqlType); - } - - public void registerOutParameter(int parameterIndex, int sqlType, int scale) - throws SQLException { - realStatement.registerOutParameter(parameterIndex, sqlType, scale); - } - - public boolean wasNull() throws SQLException { - return realStatement.wasNull(); - } - - public String getString(int parameterIndex) throws SQLException { - return realStatement.getString(parameterIndex); - } - - public boolean getBoolean(int parameterIndex) throws SQLException { - return realStatement.getBoolean(parameterIndex); - } - - public byte getByte(int parameterIndex) throws SQLException { - return realStatement.getByte(parameterIndex); - } - - public short getShort(int parameterIndex) throws SQLException { - return realStatement.getShort(parameterIndex); - } - - public int getInt(int parameterIndex) throws SQLException { - return realStatement.getInt(parameterIndex); - } - - public long getLong(int parameterIndex) throws SQLException { - return realStatement.getLong(parameterIndex); - } - - public float getFloat(int parameterIndex) throws SQLException { - return realStatement.getFloat(parameterIndex); - } - - public double getDouble(int parameterIndex) throws SQLException { - return realStatement.getDouble(parameterIndex); - } - - @Deprecated - public BigDecimal getBigDecimal(int parameterIndex, int scale) - throws SQLException { - return realStatement.getBigDecimal(parameterIndex, scale); - } - - public byte[] getBytes(int parameterIndex) throws SQLException { - return realStatement.getBytes(parameterIndex); - } - - public Date getDate(int parameterIndex) throws SQLException { - return realStatement.getDate(parameterIndex); - } - - public Time getTime(int parameterIndex) throws SQLException { - return realStatement.getTime(parameterIndex); - } - - public Timestamp getTimestamp(int parameterIndex) throws SQLException { - return realStatement.getTimestamp(parameterIndex); - } - - public Object getObject(int parameterIndex) throws SQLException { - return realStatement.getObject(parameterIndex); - } - - public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { - return realStatement.getBigDecimal(parameterIndex); - } - - public Object getObject(int parameterIndex, Map> map) - throws SQLException { - return realStatement.getObject(parameterIndex, map); - } - - public Ref getRef(int parameterIndex) throws SQLException { - return realStatement.getRef(parameterIndex); - } - - public Blob getBlob(int parameterIndex) throws SQLException { - return realStatement.getBlob(parameterIndex); - } - - public Clob getClob(int parameterIndex) throws SQLException { - return realStatement.getClob(parameterIndex); - } - - public Array getArray(int parameterIndex) throws SQLException { - return realStatement.getArray(parameterIndex); - } - - public Date getDate(int parameterIndex, Calendar cal) throws SQLException { - return realStatement.getDate(parameterIndex, cal); - } - - public Time getTime(int parameterIndex, Calendar cal) throws SQLException { - return realStatement.getTime(parameterIndex, cal); - } - - public Timestamp getTimestamp(int parameterIndex, Calendar cal) - throws SQLException { - return realStatement.getTimestamp(parameterIndex, cal); - } - - public void registerOutParameter(int parameterIndex, int sqlType, - String typeName) throws SQLException { - realStatement.registerOutParameter(parameterIndex, sqlType, typeName); - } - - public void registerOutParameter(String parameterName, int sqlType) - throws SQLException { - realStatement.registerOutParameter(parameterName, sqlType); - } - - public void registerOutParameter(String parameterName, int sqlType, - int scale) throws SQLException { - realStatement.registerOutParameter(parameterName, sqlType, scale); - } - - public void registerOutParameter(String parameterName, int sqlType, - String typeName) throws SQLException { - realStatement.registerOutParameter(parameterName, sqlType, typeName); - } - - public URL getURL(int parameterIndex) throws SQLException { - return realStatement.getURL(parameterIndex); - } - - public void setURL(String parameterName, URL val) throws SQLException { - realStatement.setURL(parameterName, val); - } - - public void setNull(String parameterName, int sqlType) throws SQLException { - realStatement.setNull(parameterName, sqlType); - } - - public void setBoolean(String parameterName, boolean x) throws SQLException { - realStatement.setBoolean(parameterName, x); - } - - public void setByte(String parameterName, byte x) throws SQLException { - realStatement.setByte(parameterName, x); - } - - public void setShort(String parameterName, short x) throws SQLException { - realStatement.setShort(parameterName, x); - } - - public void setInt(String parameterName, int x) throws SQLException { - realStatement.setInt(parameterName, x); - } - - public void setLong(String parameterName, long x) throws SQLException { - realStatement.setLong(parameterName, x); - } - - public void setFloat(String parameterName, float x) throws SQLException { - realStatement.setFloat(parameterName, x); - } - - public void setDouble(String parameterName, double x) throws SQLException { - realStatement.setDouble(parameterName, x); - } - - public void setBigDecimal(String parameterName, BigDecimal x) - throws SQLException { - realStatement.setBigDecimal(parameterName, x); - } - - public void setString(String parameterName, String x) throws SQLException { - realStatement.setString(parameterName, x); - } - - public void setBytes(String parameterName, byte[] x) throws SQLException { - realStatement.setBytes(parameterName, x); - } - - public void setDate(String parameterName, Date x) throws SQLException { - realStatement.setDate(parameterName, x); - } - - public void setTime(String parameterName, Time x) throws SQLException { - realStatement.setTime(parameterName, x); - } - - public void setTimestamp(String parameterName, Timestamp x) - throws SQLException { - realStatement.setTimestamp(parameterName, x); - } - - public void setAsciiStream(String parameterName, InputStream x, int length) - throws SQLException { - realStatement.setAsciiStream(parameterName, x, length); - } - - public void setBinaryStream(String parameterName, InputStream x, int length) - throws SQLException { - realStatement.setBinaryStream(parameterName, x, length); - } - - public void setObject(String parameterName, Object x, int targetSqlType, - int scale) throws SQLException { - realStatement.setObject(parameterName, x, targetSqlType, scale); - } - - public void setObject(String parameterName, Object x, int targetSqlType) - throws SQLException { - realStatement.setObject(parameterName, x, targetSqlType); - } - - public void setObject(String parameterName, Object x) throws SQLException { - realStatement.setObject(parameterName, x); - } - - public void setCharacterStream(String parameterName, Reader reader, - int length) throws SQLException { - realStatement.setCharacterStream(parameterName, reader, length); - } - - public void setDate(String parameterName, Date x, Calendar cal) - throws SQLException { - realStatement.setDate(parameterName, x, cal); - } - - public void setTime(String parameterName, Time x, Calendar cal) - throws SQLException { - realStatement.setTime(parameterName, x, cal); - } - - public void setTimestamp(String parameterName, Timestamp x, Calendar cal) - throws SQLException { - realStatement.setTimestamp(parameterName, x, cal); - } - - public void setNull(String parameterName, int sqlType, String typeName) - throws SQLException { - realStatement.setNull(parameterName, sqlType, typeName); - } - - public String getString(String parameterName) throws SQLException { - return realStatement.getString(parameterName); - } - - public boolean getBoolean(String parameterName) throws SQLException { - return realStatement.getBoolean(parameterName); - } - - public byte getByte(String parameterName) throws SQLException { - return realStatement.getByte(parameterName); - } - - public short getShort(String parameterName) throws SQLException { - return realStatement.getShort(parameterName); - } - - public int getInt(String parameterName) throws SQLException { - return realStatement.getInt(parameterName); - } - - public long getLong(String parameterName) throws SQLException { - return realStatement.getLong(parameterName); - } - - public float getFloat(String parameterName) throws SQLException { - return realStatement.getFloat(parameterName); - } - - public double getDouble(String parameterName) throws SQLException { - return realStatement.getDouble(parameterName); - } - - public byte[] getBytes(String parameterName) throws SQLException { - return realStatement.getBytes(parameterName); - } - - public Date getDate(String parameterName) throws SQLException { - return realStatement.getDate(parameterName); - } - - public Time getTime(String parameterName) throws SQLException { - return realStatement.getTime(parameterName); - } - - public Timestamp getTimestamp(String parameterName) throws SQLException { - return realStatement.getTimestamp(parameterName); - } - - public Object getObject(String parameterName) throws SQLException { - return realStatement.getObject(parameterName); - } - - public BigDecimal getBigDecimal(String parameterName) throws SQLException { - return realStatement.getBigDecimal(parameterName); - } - - public Object getObject(String parameterName, Map> map) - throws SQLException { - return realStatement.getObject(parameterName, map); - } - - public Ref getRef(String parameterName) throws SQLException { - return realStatement.getRef(parameterName); - } - - public Blob getBlob(String parameterName) throws SQLException { - return realStatement.getBlob(parameterName); - } - - public Clob getClob(String parameterName) throws SQLException { - return realStatement.getClob(parameterName); - } - - public Array getArray(String parameterName) throws SQLException { - return realStatement.getArray(parameterName); - } - - public Date getDate(String parameterName, Calendar cal) throws SQLException { - return realStatement.getDate(parameterName, cal); - } - - public Time getTime(String parameterName, Calendar cal) throws SQLException { - return realStatement.getTime(parameterName, cal); - } - - public Timestamp getTimestamp(String parameterName, Calendar cal) - throws SQLException { - return realStatement.getTimestamp(parameterName, cal); - } - - public URL getURL(String parameterName) throws SQLException { - return realStatement.getURL(parameterName); - } - - public RowId getRowId(int parameterIndex) throws SQLException { - return realStatement.getRowId(parameterIndex); - } - - public RowId getRowId(String parameterName) throws SQLException { - return realStatement.getRowId(parameterName); - } - - public void setRowId(String parameterName, RowId x) throws SQLException { - realStatement.setRowId(parameterName, x); - } - - public void setNString(String parameterName, String value) - throws SQLException { - realStatement.setNString(parameterName, value); - } - - public void setNCharacterStream(String parameterName, Reader value, - long length) throws SQLException { - realStatement.setNCharacterStream(parameterName, value, length); - } - - public void setNClob(String parameterName, NClob value) throws SQLException { - realStatement.setNClob(parameterName, value); - } - - public void setClob(String parameterName, Reader reader, long length) - throws SQLException { - realStatement.setClob(parameterName, reader, length); - } - - public void setBlob(String parameterName, InputStream inputStream, - long length) throws SQLException { - realStatement.setBlob(parameterName, inputStream, length); - } - - public void setNClob(String parameterName, Reader reader, long length) - throws SQLException { - realStatement.setNClob(parameterName, reader, length); - } - - public NClob getNClob(int parameterIndex) throws SQLException { - return realStatement.getNClob(parameterIndex); - } - - public NClob getNClob(String parameterName) throws SQLException { - return realStatement.getNClob(parameterName); - } - - public void setSQLXML(String parameterName, SQLXML xmlObject) - throws SQLException { - realStatement.setSQLXML(parameterName, xmlObject); - } - - public SQLXML getSQLXML(int parameterIndex) throws SQLException { - return realStatement.getSQLXML(parameterIndex); - } - - public SQLXML getSQLXML(String parameterName) throws SQLException { - return realStatement.getSQLXML(parameterName); - } - - public String getNString(int parameterIndex) throws SQLException { - return realStatement.getNString(parameterIndex); - } - - public String getNString(String parameterName) throws SQLException { - return realStatement.getNString(parameterName); - } - - public Reader getNCharacterStream(int parameterIndex) throws SQLException { - return realStatement.getNCharacterStream(parameterIndex); - } - - public Reader getNCharacterStream(String parameterName) throws SQLException { - return realStatement.getNCharacterStream(parameterName); - } - - public Reader getCharacterStream(int parameterIndex) throws SQLException { - return realStatement.getCharacterStream(parameterIndex); - } - - public Reader getCharacterStream(String parameterName) throws SQLException { - return realStatement.getCharacterStream(parameterName); - } - - public void setBlob(String parameterName, Blob x) throws SQLException { - realStatement.setBlob(parameterName, x); - } - - public void setClob(String parameterName, Clob x) throws SQLException { - realStatement.setClob(parameterName, x); - } - - public void setAsciiStream(String parameterName, InputStream x, long length) - throws SQLException { - realStatement.setAsciiStream(parameterName, x, length); - } - - public void setBinaryStream(String parameterName, InputStream x, long length) - throws SQLException { - realStatement.setBinaryStream(parameterName, x, length); - } - - public void setCharacterStream(String parameterName, Reader reader, - long length) throws SQLException { - realStatement.setCharacterStream(parameterName, reader, length); - } - - public void setAsciiStream(String parameterName, InputStream x) - throws SQLException { - realStatement.setAsciiStream(parameterName, x); - } - - public void setBinaryStream(String parameterName, InputStream x) - throws SQLException { - realStatement.setBinaryStream(parameterName, x); - } - - public void setCharacterStream(String parameterName, Reader reader) - throws SQLException { - realStatement.setCharacterStream(parameterName, reader); - } - - public void setNCharacterStream(String parameterName, Reader value) - throws SQLException { - realStatement.setNCharacterStream(parameterName, value); - } - - public void setClob(String parameterName, Reader reader) - throws SQLException { - realStatement.setClob(parameterName, reader); - } - - public void setBlob(String parameterName, InputStream inputStream) - throws SQLException { - realStatement.setBlob(parameterName, inputStream); - } - - public void setNClob(String parameterName, Reader reader) - throws SQLException { - realStatement.setNClob(parameterName, reader); - } - - public T getObject(int parameterIndex, Class type) - throws SQLException { - return realStatement.getObject(parameterIndex, type); - } - - public T getObject(String parameterName, Class type) - throws SQLException { - return realStatement.getObject(parameterName, type); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWConnection.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWConnection.java deleted file mode 100755 index d95766a2d..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWConnection.java +++ /dev/null @@ -1,304 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc; - -import java.sql.*; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.Executor; - -public class SWConnection implements java.sql.Connection { - private String connectInfo; - - private final java.sql.Connection realConnection; - - public SWConnection(String url, Properties info, - java.sql.Connection realConnection) { - super(); - this.connectInfo = url + "(" + info.getProperty("user") + ")"; - this.realConnection = realConnection; - } - - public T unwrap(Class iface) throws SQLException { - return realConnection.unwrap(iface); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return realConnection.isWrapperFor(iface); - } - - public Statement createStatement() throws SQLException { - return new SWStatement(this, realConnection.createStatement(), - this.connectInfo); - } - - public PreparedStatement prepareStatement(String sql) throws SQLException { - return new SWPreparedStatement(this, - realConnection.prepareStatement(sql), this.connectInfo, sql); - } - - public CallableStatement prepareCall(String sql) throws SQLException { - return new SWCallableStatement(this, realConnection.prepareCall(sql), - this.connectInfo, sql); - } - - public String nativeSQL(String sql) throws SQLException { - return realConnection.nativeSQL(sql); - } - - public void setAutoCommit(boolean autoCommit) throws SQLException { - realConnection.setAutoCommit(autoCommit); - } - - public boolean getAutoCommit() throws SQLException { - return realConnection.getAutoCommit(); - } - - public void commit() throws SQLException { - ConnectionTracing.execute(realConnection, connectInfo, "commit", "", - new ConnectionTracing.Executable() { - public String exe(java.sql.Connection realConnection, - String sql) throws SQLException { - realConnection.commit(); - return null; - } - }); - } - - public void rollback() throws SQLException { - ConnectionTracing.execute(realConnection, connectInfo, "rollback", "", - new ConnectionTracing.Executable() { - public String exe(java.sql.Connection realConnection, - String sql) throws SQLException { - realConnection.rollback(); - return null; - } - }); - } - - public void close() throws SQLException { - ConnectionTracing.execute(realConnection, connectInfo, "close", "", - new ConnectionTracing.Executable() { - public String exe(java.sql.Connection realConnection, - String sql) throws SQLException { - realConnection.close(); - return null; - } - }); - } - - public boolean isClosed() throws SQLException { - return realConnection.isClosed(); - } - - public DatabaseMetaData getMetaData() throws SQLException { - return realConnection.getMetaData(); - } - - public void setReadOnly(boolean readOnly) throws SQLException { - realConnection.setReadOnly(readOnly); - } - - public boolean isReadOnly() throws SQLException { - return realConnection.isReadOnly(); - } - - public void setCatalog(String catalog) throws SQLException { - realConnection.setCatalog(catalog); - } - - public String getCatalog() throws SQLException { - return realConnection.getCatalog(); - } - - public void setTransactionIsolation(int level) throws SQLException { - realConnection.setTransactionIsolation(level); - } - - public int getTransactionIsolation() throws SQLException { - return realConnection.getTransactionIsolation(); - } - - public SQLWarning getWarnings() throws SQLException { - return realConnection.getWarnings(); - } - - public void clearWarnings() throws SQLException { - realConnection.clearWarnings(); - } - - public Statement createStatement(int resultSetType, int resultSetConcurrency) - throws SQLException { - return new SWStatement(this, realConnection.createStatement( - resultSetType, resultSetConcurrency), this.connectInfo); - } - - public PreparedStatement prepareStatement(String sql, int resultSetType, - int resultSetConcurrency) throws SQLException { - return new SWPreparedStatement(this, realConnection.prepareStatement( - sql, resultSetType, resultSetConcurrency), this.connectInfo, - sql); - } - - public CallableStatement prepareCall(String sql, int resultSetType, - int resultSetConcurrency) throws SQLException { - return new SWCallableStatement(this, realConnection.prepareCall(sql, - resultSetType, resultSetConcurrency), this.connectInfo, sql); - } - - public Map> getTypeMap() throws SQLException { - return realConnection.getTypeMap(); - } - - public void setTypeMap(Map> map) throws SQLException { - realConnection.setTypeMap(map); - } - - public void setHoldability(int holdability) throws SQLException { - realConnection.setHoldability(holdability); - } - - public int getHoldability() throws SQLException { - return realConnection.getHoldability(); - } - - public Savepoint setSavepoint() throws SQLException { - return realConnection.setSavepoint(); - } - - public Savepoint setSavepoint(String name) throws SQLException { - return realConnection.setSavepoint(name); - } - - public void rollback(final Savepoint savepoint) throws SQLException { - ConnectionTracing.execute(realConnection, connectInfo, - "rollback to savepoint", "", new ConnectionTracing.Executable() { - public String exe(java.sql.Connection realConnection, - String sql) throws SQLException { - realConnection.rollback(savepoint); - return null; - } - }); - } - - public void releaseSavepoint(final Savepoint savepoint) throws SQLException { - ConnectionTracing.execute(realConnection, connectInfo, - "releaseSavepoint savepoint", "", new ConnectionTracing.Executable() { - public String exe(java.sql.Connection realConnection, - String sql) throws SQLException { - realConnection.releaseSavepoint(savepoint); - return null; - } - }); - } - - public Statement createStatement(int resultSetType, - int resultSetConcurrency, int resultSetHoldability) - throws SQLException { - return new SWStatement(this, realConnection.createStatement( - resultSetType, resultSetConcurrency, resultSetHoldability), - this.connectInfo); - } - - public PreparedStatement prepareStatement(String sql, int resultSetType, - int resultSetConcurrency, int resultSetHoldability) - throws SQLException { - return new SWPreparedStatement(this, - realConnection.prepareStatement(sql, resultSetType, - resultSetConcurrency, resultSetHoldability), - this.connectInfo, sql); - } - - public CallableStatement prepareCall(String sql, int resultSetType, - int resultSetConcurrency, int resultSetHoldability) - throws SQLException { - return new SWCallableStatement(this, realConnection.prepareCall(sql, - resultSetType, resultSetConcurrency, resultSetHoldability), this.connectInfo, sql); - } - - public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) - throws SQLException { - return new SWPreparedStatement(this, realConnection.prepareStatement( - sql, autoGeneratedKeys), this.connectInfo, sql); - } - - public PreparedStatement prepareStatement(String sql, int[] columnIndexes) - throws SQLException { - return new SWPreparedStatement(this, realConnection.prepareStatement( - sql, columnIndexes), this.connectInfo, sql); - } - - public PreparedStatement prepareStatement(String sql, String[] columnNames) - throws SQLException { - return new SWPreparedStatement(this, realConnection.prepareStatement( - sql, columnNames), this.connectInfo, sql); - } - - public Clob createClob() throws SQLException { - return realConnection.createClob(); - } - - public Blob createBlob() throws SQLException { - return realConnection.createBlob(); - } - - public NClob createNClob() throws SQLException { - return realConnection.createNClob(); - } - - public SQLXML createSQLXML() throws SQLException { - return realConnection.createSQLXML(); - } - - public boolean isValid(int timeout) throws SQLException { - return realConnection.isValid(timeout); - } - - public void setClientInfo(String name, String value) - throws SQLClientInfoException { - realConnection.setClientInfo(name, value); - } - - public void setClientInfo(Properties properties) - throws SQLClientInfoException { - realConnection.setClientInfo(properties); - } - - public String getClientInfo(String name) throws SQLException { - return realConnection.getClientInfo(name); - } - - public Properties getClientInfo() throws SQLException { - return realConnection.getClientInfo(); - } - - public Array createArrayOf(String typeName, Object[] elements) - throws SQLException { - return realConnection.createArrayOf(typeName, elements); - } - - public Struct createStruct(String typeName, Object[] attributes) - throws SQLException { - return realConnection.createStruct(typeName, attributes); - } - - public void setSchema(String schema) throws SQLException { - realConnection.setSchema(schema); - } - - public String getSchema() throws SQLException { - return realConnection.getSchema(); - } - - public void abort(Executor executor) throws SQLException { - realConnection.abort(executor); - } - - public void setNetworkTimeout(Executor executor, int milliseconds) - throws SQLException { - realConnection.setNetworkTimeout(executor, milliseconds); - } - - public int getNetworkTimeout() throws SQLException { - return realConnection.getNetworkTimeout(); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWPreparedStatement.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWPreparedStatement.java deleted file mode 100644 index 12cec2459..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWPreparedStatement.java +++ /dev/null @@ -1,518 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.*; -import java.util.Calendar; - -public class SWPreparedStatement implements PreparedStatement { - private Connection realConnection; - private PreparedStatement realStatement; - private String connectInfo; - private String sql; - - SWPreparedStatement(Connection realConnection, - PreparedStatement realStatement, String connectInfo, - String sql) { - this.realConnection = realConnection; - this.realStatement = realStatement; - this.connectInfo = connectInfo; - this.sql = sql; - } - - public ResultSet executeQuery(String sql) throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "executeQuery", sql, new PreparedStatementTracing.Executable() { - public ResultSet exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.executeQuery(sql); - } - }); - } - - public int executeUpdate(String sql) throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { - public Integer exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql); - } - }); - } - - public void close() throws SQLException { - realStatement.close(); - } - - public int getMaxFieldSize() throws SQLException { - return realStatement.getMaxFieldSize(); - } - - public void setMaxFieldSize(int max) throws SQLException { - realStatement.setMaxFieldSize(max); - } - - public int getMaxRows() throws SQLException { - return realStatement.getMaxRows(); - } - - public void setMaxRows(int max) throws SQLException { - realStatement.setMaxRows(max); - } - - public void setEscapeProcessing(boolean enable) throws SQLException { - realStatement.setEscapeProcessing(enable); - } - - public int getQueryTimeout() throws SQLException { - return realStatement.getQueryTimeout(); - } - - public void setQueryTimeout(int seconds) throws SQLException { - realStatement.setQueryTimeout(seconds); - } - - public void cancel() throws SQLException { - realStatement.cancel(); - } - - public SQLWarning getWarnings() throws SQLException { - return realStatement.getWarnings(); - } - - public void clearWarnings() throws SQLException { - realStatement.clearWarnings(); - } - - public void setCursorName(String name) throws SQLException { - realStatement.setCursorName(name); - } - - public boolean execute(String sql) throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable() { - public Boolean exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql); - } - }); - } - - public ResultSet getResultSet() throws SQLException { - return realStatement.getResultSet(); - } - - public int getUpdateCount() throws SQLException { - return realStatement.getUpdateCount(); - } - - public boolean getMoreResults() throws SQLException { - return realStatement.getMoreResults(); - } - - public void setFetchDirection(int direction) throws SQLException { - realStatement.setFetchDirection(direction); - } - - public int getFetchDirection() throws SQLException { - return realStatement.getFetchDirection(); - } - - public void setFetchSize(int rows) throws SQLException { - realStatement.setFetchSize(rows); - } - - public int getFetchSize() throws SQLException { - return realStatement.getFetchSize(); - } - - public int getResultSetConcurrency() throws SQLException { - return realStatement.getResultSetConcurrency(); - } - - public int getResultSetType() throws SQLException { - return realStatement.getResultSetType(); - } - - public void addBatch(String sql) throws SQLException { - realStatement.addBatch(sql); - } - - public void clearBatch() throws SQLException { - realStatement.clearBatch(); - } - - public int[] executeBatch() throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "executeBatch", "", new PreparedStatementTracing.Executable() { - public int[] exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.executeBatch(); - } - }); - } - - public Connection getConnection() throws SQLException { - return realConnection; - } - - public boolean getMoreResults(int current) throws SQLException { - return realStatement.getMoreResults(current); - } - - public ResultSet getGeneratedKeys() throws SQLException { - return realStatement.getGeneratedKeys(); - } - - public int executeUpdate(String sql, final int autoGeneratedKeys) - throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { - public Integer exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, autoGeneratedKeys); - } - }); - } - - public int executeUpdate(String sql, final int[] columnIndexes) - throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { - public Integer exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, columnIndexes); - } - }); - } - - public int executeUpdate(String sql, final String[] columnNames) - throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { - public Integer exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, columnNames); - } - }); - } - - public boolean execute(String sql, final int autoGeneratedKeys) - throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable() { - public Boolean exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, autoGeneratedKeys); - } - }); - } - - public boolean execute(String sql, final int[] columnIndexes) throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable() { - public Boolean exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, columnIndexes); - } - }); - } - - public boolean execute(String sql, final String[] columnNames) - throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable() { - public Boolean exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, columnNames); - } - }); - } - - public int getResultSetHoldability() throws SQLException { - return realStatement.getResultSetHoldability(); - } - - public boolean isClosed() throws SQLException { - return realStatement.isClosed(); - } - - public void setPoolable(boolean poolable) throws SQLException { - realStatement.setPoolable(poolable); - } - - public boolean isPoolable() throws SQLException { - return realStatement.isPoolable(); - } - - public void closeOnCompletion() throws SQLException { - realStatement.closeOnCompletion(); - } - - public boolean isCloseOnCompletion() throws SQLException { - return realStatement.isCloseOnCompletion(); - } - - public T unwrap(Class iface) throws SQLException { - return realStatement.unwrap(iface); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return realStatement.isWrapperFor(iface); - } - - public ResultSet executeQuery() throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "executeQuery", sql, new PreparedStatementTracing.Executable() { - public ResultSet exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.executeQuery(); - } - }); - } - - public int executeUpdate() throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { - public Integer exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(); - } - }); - } - - public void setNull(int parameterIndex, int sqlType) throws SQLException { - realStatement.setNull(parameterIndex, sqlType); - } - - public void setBoolean(int parameterIndex, boolean x) throws SQLException { - realStatement.setBoolean(parameterIndex, x); - } - - public void setByte(int parameterIndex, byte x) throws SQLException { - realStatement.setByte(parameterIndex, x); - } - - public void setShort(int parameterIndex, short x) throws SQLException { - realStatement.setShort(parameterIndex, x); - } - - public void setInt(int parameterIndex, int x) throws SQLException { - realStatement.setInt(parameterIndex, x); - } - - public void setLong(int parameterIndex, long x) throws SQLException { - realStatement.setLong(parameterIndex, x); - } - - public void setFloat(int parameterIndex, float x) throws SQLException { - realStatement.setFloat(parameterIndex, x); - } - - public void setDouble(int parameterIndex, double x) throws SQLException { - realStatement.setDouble(parameterIndex, x); - } - - public void setBigDecimal(int parameterIndex, BigDecimal x) - throws SQLException { - realStatement.setBigDecimal(parameterIndex, x); - } - - public void setString(int parameterIndex, String x) throws SQLException { - realStatement.setString(parameterIndex, x); - } - - public void setBytes(int parameterIndex, byte[] x) throws SQLException { - realStatement.setBytes(parameterIndex, x); - } - - public void setDate(int parameterIndex, Date x) throws SQLException { - realStatement.setDate(parameterIndex, x); - } - - public void setTime(int parameterIndex, Time x) throws SQLException { - realStatement.setTime(parameterIndex, x); - } - - public void setTimestamp(int parameterIndex, Timestamp x) - throws SQLException { - realStatement.setTimestamp(parameterIndex, x); - } - - public void setAsciiStream(int parameterIndex, InputStream x, int length) - throws SQLException { - realStatement.setAsciiStream(parameterIndex, x, length); - } - - @Deprecated - public void setUnicodeStream(int parameterIndex, InputStream x, int length) - throws SQLException { - realStatement.setUnicodeStream(parameterIndex, x, length); - } - - public void setBinaryStream(int parameterIndex, InputStream x, int length) - throws SQLException { - realStatement.setBinaryStream(parameterIndex, x, length); - } - - public void clearParameters() throws SQLException { - realStatement.clearParameters(); - } - - public void setObject(int parameterIndex, Object x, int targetSqlType) - throws SQLException { - realStatement.setObject(parameterIndex, x, targetSqlType); - } - - public void setObject(int parameterIndex, Object x) throws SQLException { - realStatement.setObject(parameterIndex, x); - } - - public boolean execute() throws SQLException { - return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { - public Boolean exe(PreparedStatement realStatement, String sql) - throws SQLException { - return realStatement.execute(); - } - }); - } - - public void addBatch() throws SQLException { - realStatement.addBatch(); - } - - public void setCharacterStream(int parameterIndex, Reader reader, int length) - throws SQLException { - realStatement.setCharacterStream(parameterIndex, reader, length); - } - - public void setRef(int parameterIndex, Ref x) throws SQLException { - realStatement.setRef(parameterIndex, x); - } - - public void setBlob(int parameterIndex, Blob x) throws SQLException { - realStatement.setBlob(parameterIndex, x); - } - - public void setClob(int parameterIndex, Clob x) throws SQLException { - realStatement.setClob(parameterIndex, x); - } - - public void setArray(int parameterIndex, Array x) throws SQLException { - realStatement.setArray(parameterIndex, x); - } - - public ResultSetMetaData getMetaData() throws SQLException { - return realStatement.getMetaData(); - } - - public void setDate(int parameterIndex, Date x, Calendar cal) - throws SQLException { - realStatement.setDate(parameterIndex, x, cal); - } - - public void setTime(int parameterIndex, Time x, Calendar cal) - throws SQLException { - realStatement.setTime(parameterIndex, x, cal); - } - - public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) - throws SQLException { - realStatement.setTimestamp(parameterIndex, x, cal); - } - - public void setNull(int parameterIndex, int sqlType, String typeName) - throws SQLException { - realStatement.setNull(parameterIndex, sqlType, typeName); - } - - public void setURL(int parameterIndex, URL x) throws SQLException { - realStatement.setURL(parameterIndex, x); - } - - public ParameterMetaData getParameterMetaData() throws SQLException { - return realStatement.getParameterMetaData(); - } - - public void setRowId(int parameterIndex, RowId x) throws SQLException { - realStatement.setRowId(parameterIndex, x); - } - - public void setNString(int parameterIndex, String value) - throws SQLException { - realStatement.setNString(parameterIndex, value); - } - - public void setNCharacterStream(int parameterIndex, Reader value, - long length) throws SQLException { - realStatement.setNCharacterStream(parameterIndex, value, length); - } - - public void setNClob(int parameterIndex, NClob value) throws SQLException { - realStatement.setNClob(parameterIndex, value); - } - - public void setClob(int parameterIndex, Reader reader, long length) - throws SQLException { - realStatement.setClob(parameterIndex, reader, length); - } - - public void setBlob(int parameterIndex, InputStream inputStream, long length) - throws SQLException { - realStatement.setBlob(parameterIndex, inputStream, length); - } - - public void setNClob(int parameterIndex, Reader reader, long length) - throws SQLException { - realStatement.setNClob(parameterIndex, reader, length); - } - - public void setSQLXML(int parameterIndex, SQLXML xmlObject) - throws SQLException { - realStatement.setSQLXML(parameterIndex, xmlObject); - } - - public void setObject(int parameterIndex, Object x, int targetSqlType, - int scaleOrLength) throws SQLException { - realStatement.setObject(parameterIndex, x, targetSqlType, scaleOrLength); - } - - public void setAsciiStream(int parameterIndex, InputStream x, long length) - throws SQLException { - realStatement.setAsciiStream(parameterIndex, x, length); - } - - public void setBinaryStream(int parameterIndex, InputStream x, long length) - throws SQLException { - realStatement.setBinaryStream(parameterIndex, x, length); - } - - public void setCharacterStream(int parameterIndex, Reader reader, - long length) throws SQLException { - realStatement.setCharacterStream(parameterIndex, reader, length); - } - - public void setAsciiStream(int parameterIndex, InputStream x) - throws SQLException { - realStatement.setAsciiStream(parameterIndex, x); - } - - public void setBinaryStream(int parameterIndex, InputStream x) - throws SQLException { - realStatement.setBinaryStream(parameterIndex, x); - } - - public void setCharacterStream(int parameterIndex, Reader reader) - throws SQLException { - realStatement.setCharacterStream(parameterIndex, reader); - } - - public void setNCharacterStream(int parameterIndex, Reader value) - throws SQLException { - realStatement.setNCharacterStream(parameterIndex, value); - } - - public void setClob(int parameterIndex, Reader reader) throws SQLException { - realStatement.setClob(parameterIndex, reader); - } - - public void setBlob(int parameterIndex, InputStream inputStream) - throws SQLException { - realStatement.setBlob(parameterIndex, inputStream); - } - - public void setNClob(int parameterIndex, Reader reader) throws SQLException { - realStatement.setNClob(parameterIndex, reader); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWStatement.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWStatement.java deleted file mode 100644 index 1a3cd2b49..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/SWStatement.java +++ /dev/null @@ -1,251 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.SQLWarning; - - -public class SWStatement implements java.sql.Statement { - private Connection realConnection; - private java.sql.Statement realStatement; - private String connectInfo; - - SWStatement(Connection realConnection, java.sql.Statement realStatement, String connectInfo) { - this.realConnection = realConnection; - this.realStatement = realStatement; - this.connectInfo = connectInfo; - } - - public T unwrap(Class iface) throws SQLException { - return realStatement.unwrap(iface); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - return realStatement.isWrapperFor(iface); - } - - public ResultSet executeQuery(String sql) throws SQLException { - return StatementTracing.execute(realStatement, connectInfo, "executeQuery", sql, new StatementTracing.Executable() { - public ResultSet exe(java.sql.Statement realStatement, String sql) - throws SQLException { - return realStatement.executeQuery(sql); - } - }); - } - - public int executeUpdate(String sql) throws SQLException { - return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable() { - public Integer exe(java.sql.Statement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql); - } - }); - } - - public void close() throws SQLException { - realStatement.close(); - } - - public int getMaxFieldSize() throws SQLException { - return realStatement.getMaxFieldSize(); - } - - public void setMaxFieldSize(int max) throws SQLException { - realStatement.setMaxFieldSize(max); - } - - public int getMaxRows() throws SQLException { - return realStatement.getMaxRows(); - } - - public void setMaxRows(int max) throws SQLException { - realStatement.setMaxRows(max); - } - - public void setEscapeProcessing(boolean enable) throws SQLException { - realStatement.setEscapeProcessing(enable); - } - - public int getQueryTimeout() throws SQLException { - return realStatement.getQueryTimeout(); - } - - public void setQueryTimeout(int seconds) throws SQLException { - realStatement.setQueryTimeout(seconds); - } - - public void cancel() throws SQLException { - realStatement.cancel(); - } - - public SQLWarning getWarnings() throws SQLException { - return realStatement.getWarnings(); - } - - public void clearWarnings() throws SQLException { - realStatement.clearWarnings(); - } - - public void setCursorName(String name) throws SQLException { - realStatement.setCursorName(name); - } - - public boolean execute(String sql) throws SQLException { - return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable() { - public Boolean exe(java.sql.Statement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql); - } - }); - } - - public ResultSet getResultSet() throws SQLException { - return realStatement.getResultSet(); - } - - public int getUpdateCount() throws SQLException { - return realStatement.getUpdateCount(); - } - - public boolean getMoreResults() throws SQLException { - return realStatement.getMoreResults(); - } - - public void setFetchDirection(int direction) throws SQLException { - realStatement.setFetchDirection(direction); - } - - public int getFetchDirection() throws SQLException { - return realStatement.getFetchDirection(); - } - - public void setFetchSize(int rows) throws SQLException { - realStatement.setFetchSize(rows); - } - - public int getFetchSize() throws SQLException { - return realStatement.getFetchSize(); - } - - public int getResultSetConcurrency() throws SQLException { - return realStatement.getResultSetConcurrency(); - } - - public int getResultSetType() throws SQLException { - return realStatement.getResultSetType(); - } - - public void addBatch(String sql) throws SQLException { - realStatement.addBatch(sql); - } - - public void clearBatch() throws SQLException { - realStatement.clearBatch(); - } - - public int[] executeBatch() throws SQLException { - return StatementTracing.execute(realStatement, connectInfo, "executeBatch", "", new StatementTracing.Executable() { - public int[] exe(java.sql.Statement realStatement, String sql) - throws SQLException { - return realStatement.executeBatch(); - } - }); - } - - public Connection getConnection() throws SQLException { - return this.realConnection; - } - - public boolean getMoreResults(int current) throws SQLException { - return realStatement.getMoreResults(current); - } - - public ResultSet getGeneratedKeys() throws SQLException { - return realStatement.getGeneratedKeys(); - } - - public int executeUpdate(String sql, final int autoGeneratedKeys) - throws SQLException { - return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable() { - public Integer exe(java.sql.Statement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, autoGeneratedKeys); - } - }); - } - - public int executeUpdate(String sql, final int[] columnIndexes) - throws SQLException { - return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable() { - public Integer exe(java.sql.Statement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, columnIndexes); - } - }); - } - - public int executeUpdate(String sql, final String[] columnNames) - throws SQLException { - return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable() { - public Integer exe(java.sql.Statement realStatement, String sql) - throws SQLException { - return realStatement.executeUpdate(sql, columnNames); - } - }); - } - - public boolean execute(String sql, final int autoGeneratedKeys) - throws SQLException { - return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable() { - public Boolean exe(java.sql.Statement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, autoGeneratedKeys); - } - }); - } - - public boolean execute(String sql, final int[] columnIndexes) throws SQLException { - return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable() { - public Boolean exe(java.sql.Statement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, columnIndexes); - } - }); - } - - public boolean execute(String sql, final String[] columnNames) - throws SQLException { - return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable() { - public Boolean exe(java.sql.Statement realStatement, String sql) - throws SQLException { - return realStatement.execute(sql, columnNames); - } - }); - } - - public int getResultSetHoldability() throws SQLException { - return realStatement.getResultSetHoldability(); - } - - public boolean isClosed() throws SQLException { - return realStatement.isClosed(); - } - - public void setPoolable(boolean poolable) throws SQLException { - realStatement.setPoolable(poolable); - } - - public boolean isPoolable() throws SQLException { - return realStatement.isPoolable(); - } - - public void closeOnCompletion() throws SQLException { - realStatement.closeOnCompletion(); - } - - public boolean isCloseOnCompletion() throws SQLException { - return realStatement.isCloseOnCompletion(); - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/StatementTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/StatementTracing.java deleted file mode 100644 index 1ee9749de..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/StatementTracing.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc; - -import com.a.eye.skywalking.api.plugin.jdbc.define.JDBCBuriedPointType; -import com.a.eye.skywalking.model.Identification; -import com.a.eye.skywalking.invoke.monitor.RPCClientInvokeMonitor; - -import java.sql.SQLException; - -/** - * 连接级追踪,用于追踪用于Statement的操作追踪 - * - * @author wusheng - */ -public class StatementTracing { - private static RPCClientInvokeMonitor rpcClientInvokeMonitor = new RPCClientInvokeMonitor(); - - public static R execute(java.sql.Statement realStatement, - String connectInfo, String method, String sql, Executable exec) - throws SQLException { - try { - rpcClientInvokeMonitor.beforeInvoke(Identification - .newBuilder() - .viewPoint(connectInfo) - .businessKey( - "statement." - + method - + (sql == null || sql.length() == 0 ? "" - : ":" + sql)).spanType(JDBCBuriedPointType.INSTANCE).build()); - return exec.exe(realStatement, sql); - } catch (SQLException e) { - rpcClientInvokeMonitor.occurException(e); - throw e; - } finally { - rpcClientInvokeMonitor.afterInvoke(); - } - } - - public interface Executable { - public R exe(java.sql.Statement realStatement, String sql) - throws SQLException; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/AbstractDatabasePluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/AbstractDatabasePluginDefine.java deleted file mode 100644 index e0f452d45..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/AbstractDatabasePluginDefine.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc.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.interceptor.ConstructorInterceptPoint; -import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; -import net.bytebuddy.description.method.MethodDescription; -import net.bytebuddy.matcher.ElementMatcher; - -import static net.bytebuddy.matcher.ElementMatchers.named; - -public abstract class AbstractDatabasePluginDefine extends ClassInstanceMethodsEnhancePluginDefine { - @Override - protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { - return null; - } - - @Override - protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { - return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { - @Override - public ElementMatcher getMethodsMatcher() { - return named("connect"); - } - - @Override - public String getMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.jdbc.define.JDBCDriverInterceptor"; - } - }}; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/H2PluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/H2PluginDefine.java deleted file mode 100644 index 14c32bd17..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/H2PluginDefine.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc.define; - -public class H2PluginDefine extends AbstractDatabasePluginDefine { - @Override - protected String enhanceClassName() { - return "org.h2.Driver"; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCBuriedPointType.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCBuriedPointType.java deleted file mode 100644 index a1aa965d2..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCBuriedPointType.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc.define; - -import com.a.eye.skywalking.api.IBuriedPointType; - -public enum JDBCBuriedPointType implements IBuriedPointType { - - INSTANCE; - - @Override - public String getTypeName() { - return "J"; - } - - @Override - public CallType getCallType() { - return CallType.LOCAL; - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCDriverInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCDriverInterceptor.java deleted file mode 100644 index 577e43622..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/JDBCDriverInterceptor.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc.define; - -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.MethodInterceptResult; -import com.a.eye.skywalking.plugin.interceptor.enhance.InstanceMethodInvokeContext; -import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import com.a.eye.skywalking.api.plugin.jdbc.SWConnection; - -import java.sql.Connection; -import java.util.Properties; - -public class JDBCDriverInterceptor implements InstanceMethodsAroundInterceptor { - @Override - public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, - MethodInterceptResult result) { - } - - @Override - public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, - Object ret) { - return new SWConnection((String) interceptorContext.allArguments()[0], - (Properties) interceptorContext.allArguments()[1], (Connection) ret); - } - - @Override - public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, - InstanceMethodInvokeContext interceptorContext) { - - } - -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/MysqlPluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/MysqlPluginDefine.java deleted file mode 100644 index c286ac49f..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/MysqlPluginDefine.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc.define; - -/** - * Created by xin on 16/8/4. - */ -public class MysqlPluginDefine extends AbstractDatabasePluginDefine { - @Override - protected String enhanceClassName() { - return "com.mysql.jdbc.Driver"; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/OraclePluginDefine.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/OraclePluginDefine.java deleted file mode 100644 index 05fb9e3c0..000000000 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/api/plugin/jdbc/define/OraclePluginDefine.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.a.eye.skywalking.api.plugin.jdbc.define; - -/** - * Created by xin on 16/8/4. - */ -public class OraclePluginDefine extends AbstractDatabasePluginDefine { - @Override - protected String enhanceClassName() { - return "oracle.jdbc.OracleDriver"; - } -} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def index 8c34d4f78..7949e2865 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/resources/skywalking-plugin.def @@ -1,3 +1,3 @@ -com.a.eye.skywalking.plugin.jdbc.define.H2PluginDefine -com.a.eye.skywalking.plugin.jdbc.define.MysqlPluginDefine -com.a.eye.skywalking.plugin.jdbc.define.OraclePluginDefine +com.a.eye.skywalking.plugin.jdbc.define.H2Instrumentation +com.a.eye.skywalking.plugin.jdbc.define.MysqlInstrumentation +com.a.eye.skywalking.plugin.jdbc.define.OracleInstrumentation diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/test/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParserTest.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/test/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParserTest.java new file mode 100644 index 000000000..39836172e --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/test/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParserTest.java @@ -0,0 +1,107 @@ +package com.a.eye.skywalking.plugin.jdbc.connectionurl.parser; + +import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +public class URLParserTest { + @Test + public void testParseMysqlJDBCURLWithHost() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost/test"); + assertThat(connectionInfo.getDBType(), is("Mysql")); + assertThat(connectionInfo.getDatabaseName(), is("test")); + assertThat(connectionInfo.getHost(), is("primaryhost")); + assertThat(connectionInfo.getPort(), is(3306)); + } + + @Test + public void testParseMysqlJDBCURLWithHostAndPort() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost:3307/test?profileSQL=true"); + assertThat(connectionInfo.getDBType(), is("Mysql")); + assertThat(connectionInfo.getDatabaseName(), is("test")); + assertThat(connectionInfo.getHost(), is("primaryhost")); + assertThat(connectionInfo.getPort(), is(3307)); + } + + @Test + public void testParseMysqlJDBCURLWithMultiHost() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql//primaryhost:3307,secondaryhost1,secondaryhost2/test?profileSQL=true"); + assertThat(connectionInfo.getDBType(), is("Mysql")); + assertThat(connectionInfo.getDatabaseName(), is("test")); + assertThat(connectionInfo.getHosts(), is("primaryhost:3307,secondaryhost1:3306,secondaryhost2:3306,")); + } + + @Test + public void testParseMysqlJDBCURLWithConnectorJs() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:mysql:replication://master,slave1,slave2,slave3/test"); + assertThat(connectionInfo.getDBType(), is("Mysql")); + assertThat(connectionInfo.getDatabaseName(), is("test")); + assertThat(connectionInfo.getHosts(), is("master:3306,slave1:3306,slave2:3306,slave3:3306,")); + } + + @Test + public void testParseOracleJDBCURLWithHost() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@localhost:orcl"); + assertThat(connectionInfo.getDBType(), is("Oracle")); + assertThat(connectionInfo.getDatabaseName(), is("orcl")); + assertThat(connectionInfo.getHost(), is("localhost")); + assertThat(connectionInfo.getPort(), is(1521)); + } + + @Test + public void testParseOracleJDBCURLWithHostAndPort() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:@localhost:1522:orcl"); + assertThat(connectionInfo.getDBType(), is("Oracle")); + assertThat(connectionInfo.getDatabaseName(), is("orcl")); + assertThat(connectionInfo.getHost(), is("localhost")); + assertThat(connectionInfo.getPort(), is(1522)); + } + + @Test + public void testParseOracleJDBCURLWithUserNameAndPassword() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:oracle:thin:scott/tiger@myhost:1521:orcl"); + assertThat(connectionInfo.getDBType(), is("Oracle")); + assertThat(connectionInfo.getDatabaseName(), is("orcl")); + assertThat(connectionInfo.getHost(), is("myhost")); + assertThat(connectionInfo.getPort(), is(1521)); + } + + @Test + public void testParseH2JDBCURLWithEmbedded() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:file:/data/sample"); + assertThat(connectionInfo.getDBType(), is("H2")); + assertThat(connectionInfo.getDatabaseName(), is("/data/sample")); + assertThat(connectionInfo.getHost(), is("localhost")); + assertThat(connectionInfo.getPort(), is(-1)); + } + + @Test + public void testParseH2JDBCURLWithEmbeddedRunningInWindows() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:file:C:/data/sample"); + assertThat(connectionInfo.getDBType(), is("H2")); + assertThat(connectionInfo.getDatabaseName(), is("C:/data/sample")); + assertThat(connectionInfo.getHost(), is("localhost")); + assertThat(connectionInfo.getPort(), is(-1)); + } + + @Test + public void testParseH2JDBCURLWithMemoryMode() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:mem:test_mem"); + assertThat(connectionInfo.getDBType(), is("H2")); + assertThat(connectionInfo.getDatabaseName(), is("test_mem")); + assertThat(connectionInfo.getHost(), is("localhost")); + assertThat(connectionInfo.getPort(), is(-1)); + } + + @Test + public void testParseH2JDBCURL() { + ConnectionInfo connectionInfo = new URLParser().parser("jdbc:h2:tcp://localhost:8084/~/sample"); + assertThat(connectionInfo.getDBType(), is("H2")); + assertThat(connectionInfo.getDatabaseName(), is("sample")); + assertThat(connectionInfo.getHost(), is("localhost")); + assertThat(connectionInfo.getPort(), is(8084)); + } +} \ No newline at end of file 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 index 661c65087..8c2ddecd4 100644 --- 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 @@ -7,7 +7,9 @@ import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorIn 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_HOST; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_HOSTS; +import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_PORT; /** * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} will record the host and port information that fetch @@ -23,6 +25,7 @@ public class JedisClusterConstructorWithHostAndPortArgInterceptor implements Ins 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()); + context.set(KEY_OF_REDIS_HOST, hostAndPort.getHost()); + context.set(KEY_OF_REDIS_PORT, hostAndPort.getPort()); } } 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 index 1f4ef4650..1dd91e9ff 100644 --- 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 @@ -18,13 +18,11 @@ public class JedisClusterConstructorWithListHostAndPortArgInterceptor implements @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); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, redisConnInfo); } } 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 index 25edc5591..6a337c79d 100644 --- 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 @@ -20,6 +20,7 @@ public class JedisConstructorWithShardInfoArgInterceptor implements InstanceCons 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()); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOST, shardInfo.getHost()); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_PORT, shardInfo.getPort()); } } 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 index c01440ff0..e6d2550f2 100644 --- 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 @@ -14,13 +14,14 @@ public class JedisConstructorWithStringArgInterceptor implements InstanceConstru @Override public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { - String redisConnInfo; - redisConnInfo = (String) interceptorContext.allArguments()[0]; + String host = (String) interceptorContext.allArguments()[0]; + int port = 6379; if (interceptorContext.allArguments().length > 1) { - redisConnInfo += ":" + interceptorContext.allArguments()[1]; + port = (Integer) interceptorContext.allArguments()[1]; } - context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, redisConnInfo); - context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOSTS, interceptorContext.allArguments()[0]); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_CONN_INFO, host + ":" + port); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOST, host); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_PORT, port); } } 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 index 25599a212..5bea6db7e 100644 --- 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 @@ -20,6 +20,7 @@ public class JedisConstructorWithUriArgInterceptor implements InstanceConstructo 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()); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_HOST, uri.getHost()); + context.set(JedisMethodInterceptor.KEY_OF_REDIS_PORT, uri.getPort()); } } 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 index 377f78cae..59adabd6a 100644 --- 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 @@ -5,6 +5,7 @@ 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.api.util.StringUtil; import com.a.eye.skywalking.trace.Span; import com.a.eye.skywalking.trace.tag.Tags; @@ -20,9 +21,26 @@ public class JedisMethodInterceptor extends NoCocurrencyAceessObject { */ protected static final String KEY_OF_REDIS_CONN_INFO = "REDIS_CONNECTION_INFO"; /** - * The key name that redis host in {@link EnhancedClassInstanceContext#context}. + * The key name that multiple redis hosts in {@link EnhancedClassInstanceContext#context}. */ protected static final String KEY_OF_REDIS_HOSTS = "KEY_OF_REDIS_HOSTS"; + /** + * The key name that redis host in {@link EnhancedClassInstanceContext#context}. + * it will be null if the value that fetch from {@link EnhancedClassInstanceContext#context} + * by using {@link #KEY_OF_REDIS_HOSTS} is not null. + */ + protected static final String KEY_OF_REDIS_HOST = "KEY_OF_REDIS_HOST"; + /** + * The key name that redis port in {@link EnhancedClassInstanceContext#context}. + * It can not be null if the value that fetch from {@link EnhancedClassInstanceContext#context} by + * using {@link #KEY_OF_REDIS_HOST} is not null. + */ + protected static final String KEY_OF_REDIS_PORT = "KEY_OF_REDIS_PORT"; + /** + * Redis component + */ + private static final String REDIS_COMPONENT = "Redis"; + @Override public void beforeMethod(final EnhancedClassInstanceContext context, final InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { @@ -30,18 +48,32 @@ public class JedisMethodInterceptor extends NoCocurrencyAceessObject { @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.COMPONENT.set(span, REDIS_COMPONENT); + Tags.DB_TYPE.set(span, REDIS_COMPONENT); + tagPeer(span, context); Tags.SPAN_LAYER.asDB(span); + if (interceptorContext.allArguments().length > 0 && interceptorContext.allArguments()[0] instanceof String) { - span.setTag("operation_key", (String) interceptorContext.allArguments()[0]); + Tags.DB_STATEMENT.set(span, interceptorContext.methodName() + " " + interceptorContext.allArguments()[0]); } } }); } + /** + * set peer host information for the current active span. + */ + private void tagPeer(Span span, EnhancedClassInstanceContext context) { + String redisHosts = (String) context.get(KEY_OF_REDIS_HOSTS); + if (!StringUtil.isEmpty(redisHosts)) { + Tags.PEERS.set(span, (String) context.get(KEY_OF_REDIS_HOSTS)); + } else { + Tags.PEER_HOST.set(span, (String) context.get(KEY_OF_REDIS_HOST)); + Tags.PEER_PORT.set(span, (Integer) context.get(KEY_OF_REDIS_PORT)); + } + } + @Override public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, Object ret) { this.whenExist(context, new Runnable() { diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java index 214f9b537..5a1693763 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java @@ -16,7 +16,8 @@ public class ConsumerFetchRequestURLInterceptor implements InstanceMethodsAround private static final String CONTEXT_NAME_OF_REQUEST_URL = "REQUEST_URL"; /** - * Fetch the request url from the first param of all constructor, and put request url into {@link EnhancedClassInstanceContext#context}. + * Fetch the request url from the first param of all constructor, and put request + * url into {@link EnhancedClassInstanceContext#context}. * * @param context instance context, a class instance only has one {@link EnhancedClassInstanceContext} instance. * @param interceptorContext method context, includes class name, method name, etc. diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java index a0d269888..ce2b845fc 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java @@ -13,20 +13,21 @@ import com.weibo.api.motan.rpc.Response; import com.weibo.api.motan.rpc.URL; /** - * {@link ConsumerInvokeInterceptor} create span by fetch request url from {@link EnhancedClassInstanceContext#context} and - * transport serialized context data to provider side through {@link Request#setAttachment(String, String)}. + * {@link ConsumerInvokeInterceptor} create span by fetch request url from + * {@link EnhancedClassInstanceContext#context} and transport serialized context + * data to provider side through {@link Request#setAttachment(String, String)}. * * @author zhangxin */ public class ConsumerInvokeInterceptor implements InstanceMethodsAroundInterceptor { /** - * Context name of request url in {@link EnhancedClassInstanceContext#context} + * Context name of request url in {@link EnhancedClassInstanceContext#context}. */ private static final String CONTEXT_NAME_OF_REQUEST_URL = "REQUEST_URL"; /** - * Attachment key of the serialized context data + * Attachment key of the serialized context data. */ private static final String ATTACHMENT_KEY_OF_CONTEXT_DATA = "contextData"; @@ -81,13 +82,11 @@ public class ConsumerInvokeInterceptor implements InstanceMethodsAroundIntercept /** * Generate operation name. * - * @return operation name + * @return operation name. */ private static String generateOperationName(URL serviceURI, Request request) { - StringBuilder viewPoint = new StringBuilder(serviceURI.getPath()); - viewPoint.append("." + request.getMethodName()); - viewPoint.append("(" + request.getParamtersDesc() + ")"); - return viewPoint.toString(); + return new StringBuilder(serviceURI.getPath()).append(".").append(request.getMethodName()).append("(") + .append(request.getParamtersDesc()).append(")").toString(); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java index 0413cb985..72f53665b 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java @@ -34,6 +34,10 @@ public class ProviderInterceptor implements InstanceConstructorInterceptor, Inst * The key name that the serialized context data stored in {@link Request#getAttachments()} */ private static final String ATTACHMENT_KEY_OF_CONTEXT_DATA = "contextData"; + /** + * Motan component + */ + private static final String MOTAN_COMPONENT = "Motan"; @Override public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) { @@ -47,7 +51,7 @@ public class ProviderInterceptor implements InstanceConstructorInterceptor, Inst if (url != null) { com.weibo.api.motan.rpc.Request request = (com.weibo.api.motan.rpc.Request) interceptorContext.allArguments()[0]; Span span = ContextManager.INSTANCE.createSpan(generateViewPoint(url, request)); - Tags.COMPONENT.set(span, "Motan"); + Tags.COMPONENT.set(span, MOTAN_COMPONENT); Tags.URL.set(span, url.getIdentity()); Tags.PEER_PORT.set(span, url.getPort()); Tags.PEER_HOST.set(span, url.getHost()); diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java index cf90c0f1a..adef99556 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java @@ -14,14 +14,25 @@ import static net.bytebuddy.matcher.ElementMatchers.named; /** * {@link ConsumerInstrumentation} presents that skywalking use {@link ConsumerInvokeInterceptor} - * to intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} and use {@link ConsumerFetchRequestURLInterceptor} - * to intercept{@link ConsumerFetchRequestURLInterceptor} + * to intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} and use + * {@link ConsumerFetchRequestURLInterceptor} to intercept{@link ConsumerFetchRequestURLInterceptor}. + * + * @author zhangxin */ public class ConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + /** + * Enhance class. + */ private static final String ENHANCE_CLASS = "com.weibo.api.motan.cluster.support.ClusterSpi"; + /** + * Class that intercept for fetch request url. + */ private static final String FETCH_REQUEST_URL_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerFetchRequestURLInterceptor"; - private static final String INVOKE_INTECEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor"; + /** + * Class that intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)}. + */ + private static final String INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor"; @Override protected String enhanceClassName() { @@ -53,7 +64,7 @@ public class ConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDe @Override public String getMethodsInterceptor() { - return INVOKE_INTECEPT_CLASS; + return INVOKE_INTERCEPT_CLASS; } }}; } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java index 29ee2f2b5..5a629023b 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java @@ -12,23 +12,25 @@ import static net.bytebuddy.matcher.ElementMatchers.any; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link ProviderInstrumentation} presents that skywalking will use {@link com.a.eye.skywalking.plugin.motan.ProviderInterceptor} - * to intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)} + * {@link ProviderInstrumentation} presents that skywalking will use + * {@link com.a.eye.skywalking.plugin.motan.ProviderInterceptor} to intercept + * all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and + * {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}. * * @author zhangxin */ public class ProviderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { /** - * Enhance class + * Enhance class. */ private static final String ENHANCE_CLASS = "com.weibo.api.motan.rpc.AbstractProvider"; /** - * Class that intercept all constructor of ${@link com.weibo.api.motan.rpc.AbstractProvider} + * Class that intercept all constructor of ${@link com.weibo.api.motan.rpc.AbstractProvider}. */ private static final String CONSTRUCTOR_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ProviderInterceptor"; /** - * Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)} + * Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}. */ private static final String PROVIDER_INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ProviderInterceptor"; diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java index ef9421ea6..b690b3168 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptor.java @@ -14,12 +14,18 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** - * {@link TomcatInterceptor} fetch the serialized context data by use {@link HttpServletRequest#getHeader(String)}. + * {@link TomcatInterceptor} fetch the serialized context data by using {@link HttpServletRequest#getHeader(String)}. * The {@link com.a.eye.skywalking.trace.TraceSegment#primaryRef} of current trace segment will reference to the trace segment id * of the previous level if the serialized context is not null. */ public class TomcatInterceptor implements InstanceMethodsAroundInterceptor { + /** + * Header name that the serialized context data stored in {@link HttpServletRequest#getHeader(String)}. + */ public static final String HEADER_NAME_OF_CONTEXT_DATA = "SKYWALKING_CONTEXT_DATA"; + /** + * Tomcat component. + */ public static final String TOMCAT_COMPONENT = "Tomcat"; /** @@ -37,6 +43,7 @@ public class TomcatInterceptor implements InstanceMethodsAroundInterceptor { Span span = ContextManager.INSTANCE.createSpan(request.getRequestURI()); Tags.COMPONENT.set(span, TOMCAT_COMPONENT); + Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER); Tags.URL.set(span, request.getRequestURL().toString()); Tags.SPAN_LAYER.asHttp(span); @@ -52,8 +59,12 @@ public class TomcatInterceptor implements InstanceMethodsAroundInterceptor { Span span = ContextManager.INSTANCE.activeSpan(); Tags.STATUS_CODE.set(span, response.getStatus()); - ContextManager.INSTANCE.stopSpan(); + if (response.getStatus() != 200) { + Tags.ERROR.set(span, true); + } + + ContextManager.INSTANCE.stopSpan(); return ret; } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java index c512d84ff..36c120ac5 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/main/java/com/a/eye/skywalking/plugin/tomcat78x/define/TomcatInstrumentation.java @@ -14,15 +14,21 @@ import org.apache.catalina.connector.Response; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link TomcatInstrumentation} presents that skywalking use class {@link TomcatInterceptor} to + * {@link TomcatInstrumentation} presents that skywalking using class {@link TomcatInterceptor} to * intercept {@link org.apache.catalina.core.StandardEngineValve#invoke(Request, Response)}. * * @author zhangxin */ public class TomcatInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + /** + * Enhance class. + */ private static final String ENHANCE_CLASS = "org.apache.catalina.core.StandardEngineValve"; + /** + * Intercept class. + */ private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.tomcat78x.TomcatInterceptor"; @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java index fbe643dda..61f8501d8 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/tomcat-7.x-8.x-plugin/src/test/java/com/a/eye/skywalking/plugin/tomcat78x/TomcatInterceptorTest.java @@ -77,7 +77,7 @@ public class TomcatInterceptorTest { @Test public void testWithSerializedContextData() { - when(request.getHeader(TomcatInterceptor.HEADER_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1"); + when(request.getHeader(TomcatInterceptor.HEADER_NAME_OF_CONTEXT_DATA)).thenReturn("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1"); tomcatInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); tomcatInterceptor.afterMethod(classInstanceContext, methodInvokeContext, null); @@ -114,7 +114,8 @@ public class TomcatInterceptorTest { } private void assertSpanLog(LogData logData) { - assertThat(logData.getFields().size(), is(3)); + assertThat(logData.getFields().size(), is(4)); + assertThat(logData.getFields().get("event"), CoreMatchers.is("error")); assertThat(logData.getFields().get("error.kind"), CoreMatchers.is(RuntimeException.class.getName())); assertNull(logData.getFields().get("message")); } @@ -129,6 +130,7 @@ public class TomcatInterceptorTest { assertThat(Tags.COMPONENT.get(span), is("Tomcat")); assertThat(Tags.URL.get(span), is("http://localhost:8080/test/testRequestURL")); assertThat(Tags.STATUS_CODE.get(span), is(200)); + assertThat(Tags.SPAN_KIND.get(span), is(Tags.SPAN_KIND_SERVER)); assertTrue(Tags.SPAN_LAYER.isHttp(span)); } From b543fac77804de2350cbeec49dc46278f5e854e0 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Fri, 24 Feb 2017 15:05:48 +0800 Subject: [PATCH 06/12] Fix compile issue. --- .../src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java index 517a4bfcb..f2b07877a 100644 --- a/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java +++ b/skywalking-commons/skywalking-trace/src/test/java/com/a/eye/skywalking/trace/SpanTestCase.java @@ -48,7 +48,7 @@ public class SpanTestCase { Tags.DB_STATEMENT.set(span1, "select * from users"); Map tags = span1.getTags(); - Assert.assertEquals(8, tags.size()); + Assert.assertEquals(7, tags.size()); Assert.assertTrue(Tags.SPAN_LAYER.isHttp(span1)); Assert.assertEquals("127.0.0.1", Tags.PEER_HOST.get(span1)); Assert.assertTrue(Tags.ERROR.get(span1)); From 9654b01c3022bf8a740a6bb013f21e7db8f0cdd9 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Fri, 24 Feb 2017 16:30:53 +0800 Subject: [PATCH 07/12] Fix compile issue. --- .../v4/HttpClientExecuteInterceptor.java | 84 ++ .../AbstractHttpClientInstrumentation.java | 53 + ...DefaultRequestDirectorInstrumentation.java | 53 + .../v4/define/HttpClientInstrumentation.java | 28 + .../InternalHttpClientInstrumentation.java | 47 + .../MinimalHttpClientInstrumentation.java | 48 + .../plugin/jdbc/CallableStatementTracing.java | 51 + .../plugin/jdbc/ConnectionInfo.java | 63 + .../plugin/jdbc/ConnectionTracing.java | 51 + .../plugin/jdbc/PreparedStatementTracing.java | 50 + .../plugin/jdbc/SWCallableStatement.java | 1039 +++++++++++++++++ .../skywalking/plugin/jdbc/SWConnection.java | 318 +++++ .../plugin/jdbc/SWPreparedStatement.java | 518 ++++++++ .../skywalking/plugin/jdbc/SWStatement.java | 251 ++++ .../plugin/jdbc/StatementTracing.java | 50 + .../parser/AbstractConnectionURLParser.java | 65 ++ .../parser/ConnectionURLParser.java | 14 + .../connectionurl/parser/H2URLParser.java | 118 ++ .../connectionurl/parser/MysqlURLParser.java | 72 ++ .../connectionurl/parser/OracleURLParser.java | 62 + .../jdbc/connectionurl/parser/URLParser.java | 23 + .../AbstractDatabaseInstrumentation.java | 53 + .../plugin/jdbc/define/H2Instrumentation.java | 19 + .../jdbc/define/JDBCDriverInterceptor.java | 38 + .../jdbc/define/MysqlInstrumentation.java | 13 + .../jdbc/define/OracleInstrumentation.java | 14 + 26 files changed, 3195 insertions(+) create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/HttpClientInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/CallableStatementTracing.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/ConnectionInfo.java create mode 100755 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/ConnectionTracing.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/PreparedStatementTracing.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWCallableStatement.java create mode 100755 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWConnection.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWPreparedStatement.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWStatement.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/StatementTracing.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/AbstractConnectionURLParser.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/H2URLParser.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/MysqlURLParser.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/OracleURLParser.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParser.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabaseInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/H2Instrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/JDBCDriverInterceptor.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/MysqlInstrumentation.java create mode 100644 skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/OracleInstrumentation.java diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java new file mode 100644 index 000000000..335065b19 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java @@ -0,0 +1,84 @@ +package com.a.eye.skywalking.plugin.httpClient.v4; + + +import com.a.eye.skywalking.api.context.ContextCarrier; +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.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +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; + +import org.apache.http.Header; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; + +/** + * {@link HttpClientExecuteInterceptor} create span and set the serialized context + * data to {@link HttpRequest#setHeader(Header)} by using {@link #HEADER_NAME_OF_CONTEXT_DATA} for the header key. + * + * @author zhangxin + */ +public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterceptor { + public static final String HEADER_NAME_OF_CONTEXT_DATA = "SKYWALKING_CONTEXT_DATA"; + + @Override + public void beforeMethod(EnhancedClassInstanceContext context, + InstanceMethodInvokeContext interceptorContext, MethodInterceptResult result) { + Object[] allArguments = interceptorContext.allArguments(); + if (allArguments[0] == null || allArguments[1] == null) { + // illegal args, can't trace. ignore. + return; + } + HttpHost httpHost = (HttpHost) allArguments[0]; + HttpRequest httpRequest = (HttpRequest) allArguments[1]; + + Span span = ContextManager.INSTANCE.createSpan(httpRequest.getRequestLine().getUri()); + Tags.PEER_PORT.set(span, httpHost.getPort()); + Tags.PEER_HOST.set(span, httpHost.getHostName()); + Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT); + Tags.URL.set(span, generateURL(httpHost, httpRequest)); + Tags.SPAN_LAYER.asHttp(span); + + ContextCarrier contextCarrier = new ContextCarrier(); + ContextManager.INSTANCE.inject(contextCarrier); + httpRequest.setHeader(HEADER_NAME_OF_CONTEXT_DATA, contextCarrier.serialize()); + } + + /** + * Generate request URL by using {@link HttpRequest} and {@link HttpHost} + * + * @return request URL + */ + private String generateURL(HttpHost httpHost, HttpRequest httpRequest) { + return httpHost.getSchemeName() + "://" + httpHost.getHostName() + ":" + httpHost.getPort() + httpRequest.getRequestLine().getUri(); + } + + @Override + public Object afterMethod(EnhancedClassInstanceContext context, + InstanceMethodInvokeContext interceptorContext, Object ret) { + Object[] allArguments = interceptorContext.allArguments(); + if (allArguments[0] == null || allArguments[1] == null) { + return ret; + } + + HttpResponse response = (HttpResponse) ret; + int statusCode = response.getStatusLine().getStatusCode(); + Span span = ContextManager.INSTANCE.activeSpan(); + if (statusCode != 200) { + Tags.ERROR.set(span, true); + } + + Tags.STATUS_CODE.set(span, statusCode); + 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/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java new file mode 100644 index 000000000..5a2a8eb23 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java @@ -0,0 +1,53 @@ +package com.a.eye.skywalking.plugin.httpClient.v4.define; + + +import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.protocol.HttpContext; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link AbstractHttpClientInstrumentation} presents that skywalking will intercept + * {@link org.apache.http.impl.client.AbstractHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} + * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. + * + * @author zhangxin + */ +public class AbstractHttpClientInstrumentation extends HttpClientInstrumentation { + + /** + * enhance class. + */ + private static final String ENHANCE_CLASS = "org.apache.http.impl.client.AbstractHttpClient"; + + @Override + public String enhanceClassName() { + return ENHANCE_CLASS; + } + + /** + * version 4.2, intercept method: execute, intercept
+ * public final HttpResponse execute(HttpHost target, HttpRequest request, + * HttpContext context)
+ */ + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("doExecute"); + } + + @Override + public String getMethodsInterceptor() { + return getInstanceMethodsInterceptor(); + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java new file mode 100644 index 000000000..d0fb67722 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java @@ -0,0 +1,53 @@ +package com.a.eye.skywalking.plugin.httpClient.v4.define; + + +import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.protocol.HttpContext; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link AbstractHttpClientInstrumentation} presents that skywalking will intercept + * {@link org.apache.http.impl.client.DefaultRequestDirector#execute(HttpHost, HttpRequest, HttpContext)} + * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. + * + * @author zhangxin + */ +public class DefaultRequestDirectorInstrumentation extends HttpClientInstrumentation { + + /** + * Enhance class. + */ + private static final String enhanceClass = "org.apache.http.impl.client.DefaultRequestDirector"; + + /** + * DefaultRequestDirector is default implement.
+ * usually use in version 4.0-4.2
+ * since 4.3, this class is Deprecated. + */ + @Override + public String enhanceClassName() { + return enhanceClass; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("execute"); + } + + @Override + public String getMethodsInterceptor() { + return getInstanceMethodsInterceptor(); + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/HttpClientInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/HttpClientInstrumentation.java new file mode 100644 index 000000000..8d7214427 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/HttpClientInstrumentation.java @@ -0,0 +1,28 @@ +package com.a.eye.skywalking.plugin.httpClient.v4.define; + + +import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; + +/** + * {@link HttpClientInstrumentation} present that skywalking will intercept {@link HttpClientInstrumentation#enhanceClassName()} + * by using {@link com.a.eye.skywalking.plugin.httpClient.v4.HttpClientExecuteInterceptor} + * + * @author zhangxin + */ +public abstract class HttpClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + /** + * Intercept class. + */ + private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.httpClient.v4.HttpClientExecuteInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + protected String getInstanceMethodsInterceptor() { + return INTERCEPT_CLASS; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java new file mode 100644 index 000000000..b0ea0c262 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java @@ -0,0 +1,47 @@ +package com.a.eye.skywalking.plugin.httpClient.v4.define; + + +import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.protocol.HttpContext; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link AbstractHttpClientInstrumentation} presents that skywalking will intercept {@link org.apache.http.impl.client.InternalHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} + * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. + * + * @author zhangxin + */ +public class InternalHttpClientInstrumentation extends HttpClientInstrumentation { + + /** + * Enhance class. + */ + private static final String ENHANCE_CLASS = "org.apache.http.impl.client.InternalHttpClient"; + + @Override + public String enhanceClassName() { + return ENHANCE_CLASS; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("doExecute"); + } + + @Override + public String getMethodsInterceptor() { + return getInstanceMethodsInterceptor(); + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java new file mode 100644 index 000000000..95b98d867 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java @@ -0,0 +1,48 @@ +package com.a.eye.skywalking.plugin.httpClient.v4.define; + + +import com.a.eye.skywalking.api.plugin.interceptor.InstanceMethodsInterceptPoint; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.protocol.HttpContext; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * {@link AbstractHttpClientInstrumentation} presents that skywalking will + * intercept {@link org.apache.http.impl.client.MinimalHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} + * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. + * + * @author zhangxin + */ +public class MinimalHttpClientInstrumentation extends HttpClientInstrumentation { + + /** + * Enhance class. + */ + private static final String ENHANCE_CLASS = "org.apache.http.impl.client.MinimalHttpClient"; + + @Override + public String enhanceClassName() { + return ENHANCE_CLASS; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("doExecute"); + } + + @Override + public String getMethodsInterceptor() { + return getInstanceMethodsInterceptor(); + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/CallableStatementTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/CallableStatementTracing.java new file mode 100644 index 000000000..c295c3676 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/CallableStatementTracing.java @@ -0,0 +1,51 @@ +package com.a.eye.skywalking.plugin.jdbc; + + +import com.a.eye.skywalking.api.context.ContextManager; +import com.a.eye.skywalking.api.util.StringUtil; +import com.a.eye.skywalking.trace.Span; +import com.a.eye.skywalking.trace.tag.Tags; + +import java.sql.SQLException; + +/** + * {@link CallableStatementTracing} create span with the {@link Span#operationName} start with + * "JDBC/CallableStatement/"and set {@link ConnectionInfo#dbType} to the {@link Tags#COMPONENT}. + * + * Notice: {@link Tags#PEERS} may be is null if database connection url don't contain multiple hosts. + * + * @author zhangxin + */ +public class CallableStatementTracing { + + public static R execute(java.sql.CallableStatement realStatement, + ConnectionInfo connectInfo, String method, String sql, Executable exec) + throws SQLException { + try { + Span span = ContextManager.INSTANCE.createSpan("JDBC/CallableStatement/" + method); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, sql); + Tags.COMPONENT.set(span, connectInfo.getDBType()); + if (!StringUtil.isEmpty(connectInfo.getHosts())) { + Tags.PEERS.set(span, connectInfo.getHosts()); + } else { + Tags.PEER_PORT.set(span, connectInfo.getPort()); + Tags.PEER_HOST.set(span, connectInfo.getHost()); + } + return exec.exe(realStatement, sql); + } catch (SQLException e) { + Span span = ContextManager.INSTANCE.activeSpan(); + Tags.ERROR.set(span, true); + span.log(e); + throw e; + } finally { + ContextManager.INSTANCE.stopSpan(); + } + } + + public interface Executable { + R exe(java.sql.CallableStatement realConnection, String sql) + throws SQLException; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/ConnectionInfo.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/ConnectionInfo.java new file mode 100644 index 000000000..3cf0a3d28 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/ConnectionInfo.java @@ -0,0 +1,63 @@ +package com.a.eye.skywalking.plugin.jdbc; + +/** + * {@link ConnectionInfo} stored the jdbc connection info, the connection info contains db type, host, port, database name. + * The {@link #hosts} be null if {@link #host} is not null. + * + * @author zhangxin + */ +public class ConnectionInfo { + /** + * DB type, such as mysql, oracle, h2. + */ + private final String dbType; + /** + * Database host name. + */ + private String host; + /** + * Database port. + */ + private int port; + /** + * Operation database name. + */ + private final String databaseName; + /** + * Database hosts. + */ + private String hosts; + + public ConnectionInfo(String dbType, String host, int port, String databaseName) { + this.dbType = dbType; + this.host = host; + this.port = port; + this.databaseName = databaseName; + } + + public ConnectionInfo(String dbType, String hosts, String databaseName) { + this.dbType = dbType; + this.hosts = hosts; + this.databaseName = databaseName; + } + + public String getDBType() { + return dbType; + } + + public String getHost() { + return host; + } + + public int getPort() { + return port; + } + + public String getDatabaseName() { + return databaseName; + } + + public String getHosts() { + return hosts; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/ConnectionTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/ConnectionTracing.java new file mode 100755 index 000000000..35d7417e4 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/ConnectionTracing.java @@ -0,0 +1,51 @@ +package com.a.eye.skywalking.plugin.jdbc; + + +import com.a.eye.skywalking.api.context.ContextManager; +import com.a.eye.skywalking.api.util.StringUtil; +import com.a.eye.skywalking.trace.Span; +import com.a.eye.skywalking.trace.tag.Tags; + +import java.sql.SQLException; + +/** + * {@link ConnectionTracing} create span with the {@link Span#operationName} start with + * "JDBC/Connection/"and set {@link ConnectionInfo#dbType} to the {@link Tags#COMPONENT}. + * + * Notice: {@link Tags#PEERS} may be is null if database connection url don't contain multiple hosts. + * + * @author zhangxin + */ +public class ConnectionTracing { + + public static R execute(java.sql.Connection realConnection, + ConnectionInfo connectInfo, String method, String sql, Executable exec) + throws SQLException { + try { + Span span = ContextManager.INSTANCE.createSpan("JDBC/Connection/" + method); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, sql); + Tags.COMPONENT.set(span, connectInfo.getDBType()); + if (!StringUtil.isEmpty(connectInfo.getHosts())) { + Tags.PEERS.set(span, connectInfo.getHosts()); + } else { + Tags.PEER_PORT.set(span, connectInfo.getPort()); + Tags.PEER_HOST.set(span, connectInfo.getHost()); + } + return exec.exe(realConnection, sql); + } catch (SQLException e) { + Span span = ContextManager.INSTANCE.activeSpan(); + Tags.ERROR.set(span, true); + span.log(e); + throw e; + } finally { + ContextManager.INSTANCE.stopSpan(); + } + } + + public interface Executable { + R exe(java.sql.Connection realConnection, String sql) + throws SQLException; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/PreparedStatementTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/PreparedStatementTracing.java new file mode 100644 index 000000000..ed181b94a --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/PreparedStatementTracing.java @@ -0,0 +1,50 @@ +package com.a.eye.skywalking.plugin.jdbc; + +import com.a.eye.skywalking.api.context.ContextManager; +import com.a.eye.skywalking.api.util.StringUtil; +import com.a.eye.skywalking.trace.Span; +import com.a.eye.skywalking.trace.tag.Tags; + +import java.sql.SQLException; + +/** + * {@link PreparedStatementTracing} create span with the {@link Span#operationName} start with + * "JDBC/PreparedStatement/"and set {@link ConnectionInfo#dbType} to the {@link Tags#COMPONENT}. + * + * Notice: {@link Tags#PEERS} may be is null if database connection url don't contain multiple hosts. + * + * @author zhangxin + */ +public class PreparedStatementTracing { + + public static R execute(java.sql.PreparedStatement realStatement, + ConnectionInfo connectInfo, String method, String sql, Executable exec) + throws SQLException { + try { + Span span = ContextManager.INSTANCE.createSpan("JDBC/PreparedStatement/" + method); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, sql); + Tags.COMPONENT.set(span, connectInfo.getDBType()); + if (!StringUtil.isEmpty(connectInfo.getHosts())) { + Tags.PEERS.set(span, connectInfo.getHosts()); + } else { + Tags.PEER_PORT.set(span, connectInfo.getPort()); + Tags.PEER_HOST.set(span, connectInfo.getHost()); + } + return exec.exe(realStatement, sql); + } catch (SQLException e) { + Span span = ContextManager.INSTANCE.activeSpan(); + Tags.ERROR.set(span, true); + span.log(e); + throw e; + } finally { + ContextManager.INSTANCE.stopSpan(); + } + } + + public interface Executable { + R exe(java.sql.PreparedStatement realConnection, String sql) + throws SQLException; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWCallableStatement.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWCallableStatement.java new file mode 100644 index 000000000..6b9fa5a6f --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWCallableStatement.java @@ -0,0 +1,1039 @@ +package com.a.eye.skywalking.plugin.jdbc; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.*; +import java.util.Calendar; +import java.util.Map; + +public class SWCallableStatement implements CallableStatement { + private Connection realConnection; + private CallableStatement realStatement; + private ConnectionInfo connectInfo; + private String sql; + + SWCallableStatement(Connection realConnection, + CallableStatement realStatement, ConnectionInfo connectInfo, + String sql) { + this.realConnection = realConnection; + this.realStatement = realStatement; + this.connectInfo = connectInfo; + this.sql = sql; + } + + public ResultSet executeQuery() throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "executeQuery", sql, new CallableStatementTracing.Executable() { + public ResultSet exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.executeQuery(); + } + }); + } + + public int executeUpdate() throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "executeUpdate", sql, new CallableStatementTracing.Executable() { + public Integer exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(); + } + }); + } + + public void setNull(int parameterIndex, int sqlType) throws SQLException { + realStatement.setNull(parameterIndex, sqlType); + } + + public void setBoolean(int parameterIndex, boolean x) throws SQLException { + realStatement.setBoolean(parameterIndex, x); + } + + public void setByte(int parameterIndex, byte x) throws SQLException { + realStatement.setByte(parameterIndex, x); + } + + public void setShort(int parameterIndex, short x) throws SQLException { + realStatement.setShort(parameterIndex, x); + } + + public void setInt(int parameterIndex, int x) throws SQLException { + realStatement.setInt(parameterIndex, x); + } + + public void setLong(int parameterIndex, long x) throws SQLException { + realStatement.setLong(parameterIndex, x); + } + + public void setFloat(int parameterIndex, float x) throws SQLException { + realStatement.setFloat(parameterIndex, x); + } + + public void setDouble(int parameterIndex, double x) throws SQLException { + realStatement.setDouble(parameterIndex, x); + } + + public void setBigDecimal(int parameterIndex, BigDecimal x) + throws SQLException { + realStatement.setBigDecimal(parameterIndex, x); + } + + public void setString(int parameterIndex, String x) throws SQLException { + realStatement.setString(parameterIndex, x); + } + + public void setBytes(int parameterIndex, byte[] x) throws SQLException { + realStatement.setBytes(parameterIndex, x); + } + + public void setDate(int parameterIndex, Date x) throws SQLException { + realStatement.setDate(parameterIndex, x); + } + + public void setTime(int parameterIndex, Time x) throws SQLException { + realStatement.setTime(parameterIndex, x); + } + + public void setTimestamp(int parameterIndex, Timestamp x) + throws SQLException { + realStatement.setTimestamp(parameterIndex, x); + } + + public void setAsciiStream(int parameterIndex, InputStream x, int length) + throws SQLException { + realStatement.setAsciiStream(parameterIndex, x, length); + } + + @Deprecated + public void setUnicodeStream(int parameterIndex, InputStream x, int length) + throws SQLException { + realStatement.setUnicodeStream(parameterIndex, x, length); + } + + public void setBinaryStream(int parameterIndex, InputStream x, int length) + throws SQLException { + realStatement.setBinaryStream(parameterIndex, x, length); + } + + public void clearParameters() throws SQLException { + realStatement.clearParameters(); + } + + public void setObject(int parameterIndex, Object x, int targetSqlType) + throws SQLException { + realStatement.setObject(parameterIndex, x, targetSqlType); + } + + public void setObject(int parameterIndex, Object x) throws SQLException { + realStatement.setObject(parameterIndex, x); + } + + public boolean execute() throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "execute", sql, new CallableStatementTracing.Executable() { + public Boolean exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.execute(); + } + }); + } + + public void addBatch() throws SQLException { + realStatement.addBatch(); + } + + public void setCharacterStream(int parameterIndex, Reader reader, int length) + throws SQLException { + realStatement.setCharacterStream(parameterIndex, reader, length); + } + + public void setRef(int parameterIndex, Ref x) throws SQLException { + realStatement.setRef(parameterIndex, x); + } + + public void setBlob(int parameterIndex, Blob x) throws SQLException { + realStatement.setBlob(parameterIndex, x); + } + + public void setClob(int parameterIndex, Clob x) throws SQLException { + realStatement.setClob(parameterIndex, x); + } + + public void setArray(int parameterIndex, Array x) throws SQLException { + realStatement.setArray(parameterIndex, x); + } + + public ResultSetMetaData getMetaData() throws SQLException { + return realStatement.getMetaData(); + } + + public void setDate(int parameterIndex, Date x, Calendar cal) + throws SQLException { + realStatement.setDate(parameterIndex, x, cal); + } + + public void setTime(int parameterIndex, Time x, Calendar cal) + throws SQLException { + realStatement.setTime(parameterIndex, x, cal); + } + + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) + throws SQLException { + realStatement.setTimestamp(parameterIndex, x, cal); + } + + public void setNull(int parameterIndex, int sqlType, String typeName) + throws SQLException { + realStatement.setNull(parameterIndex, sqlType, typeName); + } + + public void setURL(int parameterIndex, URL x) throws SQLException { + realStatement.setURL(parameterIndex, x); + } + + public ParameterMetaData getParameterMetaData() throws SQLException { + return realStatement.getParameterMetaData(); + } + + public void setRowId(int parameterIndex, RowId x) throws SQLException { + realStatement.setRowId(parameterIndex, x); + } + + public void setNString(int parameterIndex, String value) + throws SQLException { + realStatement.setNString(parameterIndex, value); + } + + public void setNCharacterStream(int parameterIndex, Reader value, + long length) throws SQLException { + realStatement.setNCharacterStream(parameterIndex, value, length); + } + + public void setNClob(int parameterIndex, NClob value) throws SQLException { + realStatement.setNClob(parameterIndex, value); + } + + public void setClob(int parameterIndex, Reader reader, long length) + throws SQLException { + realStatement.setClob(parameterIndex, reader, length); + } + + public void setBlob(int parameterIndex, InputStream inputStream, long length) + throws SQLException { + realStatement.setBlob(parameterIndex, inputStream, length); + } + + public void setNClob(int parameterIndex, Reader reader, long length) + throws SQLException { + realStatement.setNClob(parameterIndex, reader, length); + } + + public void setSQLXML(int parameterIndex, SQLXML xmlObject) + throws SQLException { + realStatement.setSQLXML(parameterIndex, xmlObject); + } + + public void setObject(int parameterIndex, Object x, int targetSqlType, + int scaleOrLength) throws SQLException { + realStatement + .setObject(parameterIndex, x, targetSqlType, scaleOrLength); + } + + public void setAsciiStream(int parameterIndex, InputStream x, long length) + throws SQLException { + realStatement.setAsciiStream(parameterIndex, x, length); + } + + public void setBinaryStream(int parameterIndex, InputStream x, long length) + throws SQLException { + realStatement.setBinaryStream(parameterIndex, x, length); + } + + public void setCharacterStream(int parameterIndex, Reader reader, + long length) throws SQLException { + realStatement.setCharacterStream(parameterIndex, reader, length); + } + + public void setAsciiStream(int parameterIndex, InputStream x) + throws SQLException { + realStatement.setAsciiStream(parameterIndex, x); + } + + public void setBinaryStream(int parameterIndex, InputStream x) + throws SQLException { + realStatement.setBinaryStream(parameterIndex, x); + } + + public void setCharacterStream(int parameterIndex, Reader reader) + throws SQLException { + realStatement.setCharacterStream(parameterIndex, reader); + } + + public void setNCharacterStream(int parameterIndex, Reader value) + throws SQLException { + realStatement.setNCharacterStream(parameterIndex, value); + } + + public void setClob(int parameterIndex, Reader reader) throws SQLException { + realStatement.setClob(parameterIndex, reader); + } + + public void setBlob(int parameterIndex, InputStream inputStream) + throws SQLException { + realStatement.setBlob(parameterIndex, inputStream); + } + + public void setNClob(int parameterIndex, Reader reader) throws SQLException { + realStatement.setNClob(parameterIndex, reader); + } + + public ResultSet executeQuery(String sql) throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "executeQuery", sql, new CallableStatementTracing.Executable() { + public ResultSet exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.executeQuery(sql); + } + }); + } + + public int executeUpdate(String sql) throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "executeUpdate", sql, new CallableStatementTracing.Executable() { + public Integer exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql); + } + }); + } + + public void close() throws SQLException { + realStatement.close(); + } + + public int getMaxFieldSize() throws SQLException { + return realStatement.getMaxFieldSize(); + } + + public void setMaxFieldSize(int max) throws SQLException { + realStatement.setMaxFieldSize(max); + } + + public int getMaxRows() throws SQLException { + return realStatement.getMaxRows(); + } + + public void setMaxRows(int max) throws SQLException { + realStatement.setMaxRows(max); + } + + public void setEscapeProcessing(boolean enable) throws SQLException { + realStatement.setEscapeProcessing(enable); + } + + public int getQueryTimeout() throws SQLException { + return realStatement.getQueryTimeout(); + } + + public void setQueryTimeout(int seconds) throws SQLException { + realStatement.setQueryTimeout(seconds); + } + + public void cancel() throws SQLException { + realStatement.cancel(); + } + + public SQLWarning getWarnings() throws SQLException { + return realStatement.getWarnings(); + } + + public void clearWarnings() throws SQLException { + realStatement.clearWarnings(); + } + + public void setCursorName(String name) throws SQLException { + realStatement.setCursorName(name); + } + + public boolean execute(String sql) throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "execute", sql, new CallableStatementTracing.Executable() { + public Boolean exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql); + } + }); + } + + public ResultSet getResultSet() throws SQLException { + return realStatement.getResultSet(); + } + + public int getUpdateCount() throws SQLException { + return realStatement.getUpdateCount(); + } + + public boolean getMoreResults() throws SQLException { + return realStatement.getMoreResults(); + } + + public void setFetchDirection(int direction) throws SQLException { + realStatement.setFetchDirection(direction); + } + + public int getFetchDirection() throws SQLException { + return realStatement.getFetchDirection(); + } + + public void setFetchSize(int rows) throws SQLException { + realStatement.setFetchSize(rows); + } + + public int getFetchSize() throws SQLException { + return realStatement.getFetchSize(); + } + + public int getResultSetConcurrency() throws SQLException { + return realStatement.getResultSetConcurrency(); + } + + public int getResultSetType() throws SQLException { + return realStatement.getResultSetType(); + } + + public void addBatch(String sql) throws SQLException { + realStatement.addBatch(); + } + + public void clearBatch() throws SQLException { + realStatement.clearBatch(); + } + + public int[] executeBatch() throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "executeBatch", "", new CallableStatementTracing.Executable() { + public int[] exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.executeBatch(); + } + }); + } + + public Connection getConnection() throws SQLException { + return this.realConnection; + } + + public boolean getMoreResults(int current) throws SQLException { + return realStatement.getMoreResults(current); + } + + public ResultSet getGeneratedKeys() throws SQLException { + return realStatement.getGeneratedKeys(); + } + + public int executeUpdate(String sql, final int autoGeneratedKeys) + throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "executeUpdate", sql, new CallableStatementTracing.Executable() { + public Integer exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql, autoGeneratedKeys); + } + }); + } + + public int executeUpdate(String sql, final int[] columnIndexes) + throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "executeUpdate", sql, new CallableStatementTracing.Executable() { + public Integer exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql, columnIndexes); + } + }); + } + + public int executeUpdate(String sql, final String[] columnNames) + throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "executeUpdate", sql, new CallableStatementTracing.Executable() { + public Integer exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql, columnNames); + } + }); + } + + public boolean execute(String sql, final int autoGeneratedKeys) + throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "execute", sql, new CallableStatementTracing.Executable() { + public Boolean exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql, autoGeneratedKeys); + } + }); + } + + public boolean execute(String sql, final int[] columnIndexes) throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "execute", sql, new CallableStatementTracing.Executable() { + public Boolean exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql, columnIndexes); + } + }); + } + + public boolean execute(String sql, final String[] columnNames) + throws SQLException { + return CallableStatementTracing.execute(realStatement, connectInfo, + "execute", sql, new CallableStatementTracing.Executable() { + public Boolean exe( + CallableStatement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql, columnNames); + } + }); + } + + public int getResultSetHoldability() throws SQLException { + return realStatement.getResultSetHoldability(); + } + + public boolean isClosed() throws SQLException { + return realStatement.isClosed(); + } + + public void setPoolable(boolean poolable) throws SQLException { + realStatement.setPoolable(poolable); + } + + public boolean isPoolable() throws SQLException { + return realStatement.isPoolable(); + } + + public void closeOnCompletion() throws SQLException { + realStatement.closeOnCompletion(); + } + + public boolean isCloseOnCompletion() throws SQLException { + return realStatement.isCloseOnCompletion(); + } + + public T unwrap(Class iface) throws SQLException { + return realStatement.unwrap(iface); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + return realStatement.isWrapperFor(iface); + } + + public void registerOutParameter(int parameterIndex, int sqlType) + throws SQLException { + realStatement.registerOutParameter(parameterIndex, sqlType); + } + + public void registerOutParameter(int parameterIndex, int sqlType, int scale) + throws SQLException { + realStatement.registerOutParameter(parameterIndex, sqlType, scale); + } + + public boolean wasNull() throws SQLException { + return realStatement.wasNull(); + } + + public String getString(int parameterIndex) throws SQLException { + return realStatement.getString(parameterIndex); + } + + public boolean getBoolean(int parameterIndex) throws SQLException { + return realStatement.getBoolean(parameterIndex); + } + + public byte getByte(int parameterIndex) throws SQLException { + return realStatement.getByte(parameterIndex); + } + + public short getShort(int parameterIndex) throws SQLException { + return realStatement.getShort(parameterIndex); + } + + public int getInt(int parameterIndex) throws SQLException { + return realStatement.getInt(parameterIndex); + } + + public long getLong(int parameterIndex) throws SQLException { + return realStatement.getLong(parameterIndex); + } + + public float getFloat(int parameterIndex) throws SQLException { + return realStatement.getFloat(parameterIndex); + } + + public double getDouble(int parameterIndex) throws SQLException { + return realStatement.getDouble(parameterIndex); + } + + @Deprecated + public BigDecimal getBigDecimal(int parameterIndex, int scale) + throws SQLException { + return realStatement.getBigDecimal(parameterIndex, scale); + } + + public byte[] getBytes(int parameterIndex) throws SQLException { + return realStatement.getBytes(parameterIndex); + } + + public Date getDate(int parameterIndex) throws SQLException { + return realStatement.getDate(parameterIndex); + } + + public Time getTime(int parameterIndex) throws SQLException { + return realStatement.getTime(parameterIndex); + } + + public Timestamp getTimestamp(int parameterIndex) throws SQLException { + return realStatement.getTimestamp(parameterIndex); + } + + public Object getObject(int parameterIndex) throws SQLException { + return realStatement.getObject(parameterIndex); + } + + public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { + return realStatement.getBigDecimal(parameterIndex); + } + + public Object getObject(int parameterIndex, Map> map) + throws SQLException { + return realStatement.getObject(parameterIndex, map); + } + + public Ref getRef(int parameterIndex) throws SQLException { + return realStatement.getRef(parameterIndex); + } + + public Blob getBlob(int parameterIndex) throws SQLException { + return realStatement.getBlob(parameterIndex); + } + + public Clob getClob(int parameterIndex) throws SQLException { + return realStatement.getClob(parameterIndex); + } + + public Array getArray(int parameterIndex) throws SQLException { + return realStatement.getArray(parameterIndex); + } + + public Date getDate(int parameterIndex, Calendar cal) throws SQLException { + return realStatement.getDate(parameterIndex, cal); + } + + public Time getTime(int parameterIndex, Calendar cal) throws SQLException { + return realStatement.getTime(parameterIndex, cal); + } + + public Timestamp getTimestamp(int parameterIndex, Calendar cal) + throws SQLException { + return realStatement.getTimestamp(parameterIndex, cal); + } + + public void registerOutParameter(int parameterIndex, int sqlType, + String typeName) throws SQLException { + realStatement.registerOutParameter(parameterIndex, sqlType, typeName); + } + + public void registerOutParameter(String parameterName, int sqlType) + throws SQLException { + realStatement.registerOutParameter(parameterName, sqlType); + } + + public void registerOutParameter(String parameterName, int sqlType, + int scale) throws SQLException { + realStatement.registerOutParameter(parameterName, sqlType, scale); + } + + public void registerOutParameter(String parameterName, int sqlType, + String typeName) throws SQLException { + realStatement.registerOutParameter(parameterName, sqlType, typeName); + } + + public URL getURL(int parameterIndex) throws SQLException { + return realStatement.getURL(parameterIndex); + } + + public void setURL(String parameterName, URL val) throws SQLException { + realStatement.setURL(parameterName, val); + } + + public void setNull(String parameterName, int sqlType) throws SQLException { + realStatement.setNull(parameterName, sqlType); + } + + public void setBoolean(String parameterName, boolean x) throws SQLException { + realStatement.setBoolean(parameterName, x); + } + + public void setByte(String parameterName, byte x) throws SQLException { + realStatement.setByte(parameterName, x); + } + + public void setShort(String parameterName, short x) throws SQLException { + realStatement.setShort(parameterName, x); + } + + public void setInt(String parameterName, int x) throws SQLException { + realStatement.setInt(parameterName, x); + } + + public void setLong(String parameterName, long x) throws SQLException { + realStatement.setLong(parameterName, x); + } + + public void setFloat(String parameterName, float x) throws SQLException { + realStatement.setFloat(parameterName, x); + } + + public void setDouble(String parameterName, double x) throws SQLException { + realStatement.setDouble(parameterName, x); + } + + public void setBigDecimal(String parameterName, BigDecimal x) + throws SQLException { + realStatement.setBigDecimal(parameterName, x); + } + + public void setString(String parameterName, String x) throws SQLException { + realStatement.setString(parameterName, x); + } + + public void setBytes(String parameterName, byte[] x) throws SQLException { + realStatement.setBytes(parameterName, x); + } + + public void setDate(String parameterName, Date x) throws SQLException { + realStatement.setDate(parameterName, x); + } + + public void setTime(String parameterName, Time x) throws SQLException { + realStatement.setTime(parameterName, x); + } + + public void setTimestamp(String parameterName, Timestamp x) + throws SQLException { + realStatement.setTimestamp(parameterName, x); + } + + public void setAsciiStream(String parameterName, InputStream x, int length) + throws SQLException { + realStatement.setAsciiStream(parameterName, x, length); + } + + public void setBinaryStream(String parameterName, InputStream x, int length) + throws SQLException { + realStatement.setBinaryStream(parameterName, x, length); + } + + public void setObject(String parameterName, Object x, int targetSqlType, + int scale) throws SQLException { + realStatement.setObject(parameterName, x, targetSqlType, scale); + } + + public void setObject(String parameterName, Object x, int targetSqlType) + throws SQLException { + realStatement.setObject(parameterName, x, targetSqlType); + } + + public void setObject(String parameterName, Object x) throws SQLException { + realStatement.setObject(parameterName, x); + } + + public void setCharacterStream(String parameterName, Reader reader, + int length) throws SQLException { + realStatement.setCharacterStream(parameterName, reader, length); + } + + public void setDate(String parameterName, Date x, Calendar cal) + throws SQLException { + realStatement.setDate(parameterName, x, cal); + } + + public void setTime(String parameterName, Time x, Calendar cal) + throws SQLException { + realStatement.setTime(parameterName, x, cal); + } + + public void setTimestamp(String parameterName, Timestamp x, Calendar cal) + throws SQLException { + realStatement.setTimestamp(parameterName, x, cal); + } + + public void setNull(String parameterName, int sqlType, String typeName) + throws SQLException { + realStatement.setNull(parameterName, sqlType, typeName); + } + + public String getString(String parameterName) throws SQLException { + return realStatement.getString(parameterName); + } + + public boolean getBoolean(String parameterName) throws SQLException { + return realStatement.getBoolean(parameterName); + } + + public byte getByte(String parameterName) throws SQLException { + return realStatement.getByte(parameterName); + } + + public short getShort(String parameterName) throws SQLException { + return realStatement.getShort(parameterName); + } + + public int getInt(String parameterName) throws SQLException { + return realStatement.getInt(parameterName); + } + + public long getLong(String parameterName) throws SQLException { + return realStatement.getLong(parameterName); + } + + public float getFloat(String parameterName) throws SQLException { + return realStatement.getFloat(parameterName); + } + + public double getDouble(String parameterName) throws SQLException { + return realStatement.getDouble(parameterName); + } + + public byte[] getBytes(String parameterName) throws SQLException { + return realStatement.getBytes(parameterName); + } + + public Date getDate(String parameterName) throws SQLException { + return realStatement.getDate(parameterName); + } + + public Time getTime(String parameterName) throws SQLException { + return realStatement.getTime(parameterName); + } + + public Timestamp getTimestamp(String parameterName) throws SQLException { + return realStatement.getTimestamp(parameterName); + } + + public Object getObject(String parameterName) throws SQLException { + return realStatement.getObject(parameterName); + } + + public BigDecimal getBigDecimal(String parameterName) throws SQLException { + return realStatement.getBigDecimal(parameterName); + } + + public Object getObject(String parameterName, Map> map) + throws SQLException { + return realStatement.getObject(parameterName, map); + } + + public Ref getRef(String parameterName) throws SQLException { + return realStatement.getRef(parameterName); + } + + public Blob getBlob(String parameterName) throws SQLException { + return realStatement.getBlob(parameterName); + } + + public Clob getClob(String parameterName) throws SQLException { + return realStatement.getClob(parameterName); + } + + public Array getArray(String parameterName) throws SQLException { + return realStatement.getArray(parameterName); + } + + public Date getDate(String parameterName, Calendar cal) throws SQLException { + return realStatement.getDate(parameterName, cal); + } + + public Time getTime(String parameterName, Calendar cal) throws SQLException { + return realStatement.getTime(parameterName, cal); + } + + public Timestamp getTimestamp(String parameterName, Calendar cal) + throws SQLException { + return realStatement.getTimestamp(parameterName, cal); + } + + public URL getURL(String parameterName) throws SQLException { + return realStatement.getURL(parameterName); + } + + public RowId getRowId(int parameterIndex) throws SQLException { + return realStatement.getRowId(parameterIndex); + } + + public RowId getRowId(String parameterName) throws SQLException { + return realStatement.getRowId(parameterName); + } + + public void setRowId(String parameterName, RowId x) throws SQLException { + realStatement.setRowId(parameterName, x); + } + + public void setNString(String parameterName, String value) + throws SQLException { + realStatement.setNString(parameterName, value); + } + + public void setNCharacterStream(String parameterName, Reader value, + long length) throws SQLException { + realStatement.setNCharacterStream(parameterName, value, length); + } + + public void setNClob(String parameterName, NClob value) throws SQLException { + realStatement.setNClob(parameterName, value); + } + + public void setClob(String parameterName, Reader reader, long length) + throws SQLException { + realStatement.setClob(parameterName, reader, length); + } + + public void setBlob(String parameterName, InputStream inputStream, + long length) throws SQLException { + realStatement.setBlob(parameterName, inputStream, length); + } + + public void setNClob(String parameterName, Reader reader, long length) + throws SQLException { + realStatement.setNClob(parameterName, reader, length); + } + + public NClob getNClob(int parameterIndex) throws SQLException { + return realStatement.getNClob(parameterIndex); + } + + public NClob getNClob(String parameterName) throws SQLException { + return realStatement.getNClob(parameterName); + } + + public void setSQLXML(String parameterName, SQLXML xmlObject) + throws SQLException { + realStatement.setSQLXML(parameterName, xmlObject); + } + + public SQLXML getSQLXML(int parameterIndex) throws SQLException { + return realStatement.getSQLXML(parameterIndex); + } + + public SQLXML getSQLXML(String parameterName) throws SQLException { + return realStatement.getSQLXML(parameterName); + } + + public String getNString(int parameterIndex) throws SQLException { + return realStatement.getNString(parameterIndex); + } + + public String getNString(String parameterName) throws SQLException { + return realStatement.getNString(parameterName); + } + + public Reader getNCharacterStream(int parameterIndex) throws SQLException { + return realStatement.getNCharacterStream(parameterIndex); + } + + public Reader getNCharacterStream(String parameterName) throws SQLException { + return realStatement.getNCharacterStream(parameterName); + } + + public Reader getCharacterStream(int parameterIndex) throws SQLException { + return realStatement.getCharacterStream(parameterIndex); + } + + public Reader getCharacterStream(String parameterName) throws SQLException { + return realStatement.getCharacterStream(parameterName); + } + + public void setBlob(String parameterName, Blob x) throws SQLException { + realStatement.setBlob(parameterName, x); + } + + public void setClob(String parameterName, Clob x) throws SQLException { + realStatement.setClob(parameterName, x); + } + + public void setAsciiStream(String parameterName, InputStream x, long length) + throws SQLException { + realStatement.setAsciiStream(parameterName, x, length); + } + + public void setBinaryStream(String parameterName, InputStream x, long length) + throws SQLException { + realStatement.setBinaryStream(parameterName, x, length); + } + + public void setCharacterStream(String parameterName, Reader reader, + long length) throws SQLException { + realStatement.setCharacterStream(parameterName, reader, length); + } + + public void setAsciiStream(String parameterName, InputStream x) + throws SQLException { + realStatement.setAsciiStream(parameterName, x); + } + + public void setBinaryStream(String parameterName, InputStream x) + throws SQLException { + realStatement.setBinaryStream(parameterName, x); + } + + public void setCharacterStream(String parameterName, Reader reader) + throws SQLException { + realStatement.setCharacterStream(parameterName, reader); + } + + public void setNCharacterStream(String parameterName, Reader value) + throws SQLException { + realStatement.setNCharacterStream(parameterName, value); + } + + public void setClob(String parameterName, Reader reader) + throws SQLException { + realStatement.setClob(parameterName, reader); + } + + public void setBlob(String parameterName, InputStream inputStream) + throws SQLException { + realStatement.setBlob(parameterName, inputStream); + } + + public void setNClob(String parameterName, Reader reader) + throws SQLException { + realStatement.setNClob(parameterName, reader); + } + + public T getObject(int parameterIndex, Class type) + throws SQLException { + return realStatement.getObject(parameterIndex, type); + } + + public T getObject(String parameterName, Class type) + throws SQLException { + return realStatement.getObject(parameterName, type); + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWConnection.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWConnection.java new file mode 100755 index 000000000..919927cd7 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWConnection.java @@ -0,0 +1,318 @@ +package com.a.eye.skywalking.plugin.jdbc; + +import com.a.eye.skywalking.plugin.jdbc.connectionurl.parser.URLParser; + +import java.sql.Array; +import java.sql.Blob; +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.NClob; +import java.sql.PreparedStatement; +import java.sql.SQLClientInfoException; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Savepoint; +import java.sql.Statement; +import java.sql.Struct; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.Executor; + +public class SWConnection implements Connection { + private ConnectionInfo connectInfo; + private final Connection realConnection; + + public SWConnection(String url, Properties info, Connection realConnection) { + super(); + this.connectInfo = URLParser.parser(url); + this.realConnection = realConnection; + } + + public T unwrap(Class iface) throws SQLException { + return realConnection.unwrap(iface); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + return realConnection.isWrapperFor(iface); + } + + public Statement createStatement() throws SQLException { + return new SWStatement(this, realConnection.createStatement(), + this.connectInfo); + } + + public PreparedStatement prepareStatement(String sql) throws SQLException { + return new SWPreparedStatement(this, + realConnection.prepareStatement(sql), this.connectInfo, sql); + } + + public CallableStatement prepareCall(String sql) throws SQLException { + return new SWCallableStatement(this, realConnection.prepareCall(sql), + this.connectInfo, sql); + } + + public String nativeSQL(String sql) throws SQLException { + return realConnection.nativeSQL(sql); + } + + public void setAutoCommit(boolean autoCommit) throws SQLException { + realConnection.setAutoCommit(autoCommit); + } + + public boolean getAutoCommit() throws SQLException { + return realConnection.getAutoCommit(); + } + + public void commit() throws SQLException { + ConnectionTracing.execute(realConnection, connectInfo, "commit", "", + new ConnectionTracing.Executable() { + public String exe(java.sql.Connection realConnection, + String sql) throws SQLException { + realConnection.commit(); + return null; + } + }); + } + + public void rollback() throws SQLException { + ConnectionTracing.execute(realConnection, connectInfo, "rollback", "", + new ConnectionTracing.Executable() { + public String exe(java.sql.Connection realConnection, + String sql) throws SQLException { + realConnection.rollback(); + return null; + } + }); + } + + public void close() throws SQLException { + ConnectionTracing.execute(realConnection, connectInfo, "close", "", + new ConnectionTracing.Executable() { + public String exe(java.sql.Connection realConnection, + String sql) throws SQLException { + realConnection.close(); + return null; + } + }); + } + + public boolean isClosed() throws SQLException { + return realConnection.isClosed(); + } + + public DatabaseMetaData getMetaData() throws SQLException { + return realConnection.getMetaData(); + } + + public void setReadOnly(boolean readOnly) throws SQLException { + realConnection.setReadOnly(readOnly); + } + + public boolean isReadOnly() throws SQLException { + return realConnection.isReadOnly(); + } + + public void setCatalog(String catalog) throws SQLException { + realConnection.setCatalog(catalog); + } + + public String getCatalog() throws SQLException { + return realConnection.getCatalog(); + } + + public void setTransactionIsolation(int level) throws SQLException { + realConnection.setTransactionIsolation(level); + } + + public int getTransactionIsolation() throws SQLException { + return realConnection.getTransactionIsolation(); + } + + public SQLWarning getWarnings() throws SQLException { + return realConnection.getWarnings(); + } + + public void clearWarnings() throws SQLException { + realConnection.clearWarnings(); + } + + public Statement createStatement(int resultSetType, int resultSetConcurrency) + throws SQLException { + return new SWStatement(this, realConnection.createStatement( + resultSetType, resultSetConcurrency), this.connectInfo); + } + + public PreparedStatement prepareStatement(String sql, int resultSetType, + int resultSetConcurrency) throws SQLException { + return new SWPreparedStatement(this, realConnection.prepareStatement( + sql, resultSetType, resultSetConcurrency), this.connectInfo, + sql); + } + + public CallableStatement prepareCall(String sql, int resultSetType, + int resultSetConcurrency) throws SQLException { + return new SWCallableStatement(this, realConnection.prepareCall(sql, + resultSetType, resultSetConcurrency), this.connectInfo, sql); + } + + public Map> getTypeMap() throws SQLException { + return realConnection.getTypeMap(); + } + + public void setTypeMap(Map> map) throws SQLException { + realConnection.setTypeMap(map); + } + + public void setHoldability(int holdability) throws SQLException { + realConnection.setHoldability(holdability); + } + + public int getHoldability() throws SQLException { + return realConnection.getHoldability(); + } + + public Savepoint setSavepoint() throws SQLException { + return realConnection.setSavepoint(); + } + + public Savepoint setSavepoint(String name) throws SQLException { + return realConnection.setSavepoint(name); + } + + public void rollback(final Savepoint savepoint) throws SQLException { + ConnectionTracing.execute(realConnection, connectInfo, + "rollback to savepoint", "", new ConnectionTracing.Executable() { + public String exe(java.sql.Connection realConnection, + String sql) throws SQLException { + realConnection.rollback(savepoint); + return null; + } + }); + } + + public void releaseSavepoint(final Savepoint savepoint) throws SQLException { + ConnectionTracing.execute(realConnection, connectInfo, + "releaseSavepoint savepoint", "", new ConnectionTracing.Executable() { + public String exe(java.sql.Connection realConnection, + String sql) throws SQLException { + realConnection.releaseSavepoint(savepoint); + return null; + } + }); + } + + public Statement createStatement(int resultSetType, + int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return new SWStatement(this, realConnection.createStatement( + resultSetType, resultSetConcurrency, resultSetHoldability), + this.connectInfo); + } + + public PreparedStatement prepareStatement(String sql, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return new SWPreparedStatement(this, + realConnection.prepareStatement(sql, resultSetType, + resultSetConcurrency, resultSetHoldability), + this.connectInfo, sql); + } + + public CallableStatement prepareCall(String sql, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return new SWCallableStatement(this, realConnection.prepareCall(sql, + resultSetType, resultSetConcurrency, resultSetHoldability), this.connectInfo, sql); + } + + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) + throws SQLException { + return new SWPreparedStatement(this, realConnection.prepareStatement( + sql, autoGeneratedKeys), this.connectInfo, sql); + } + + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) + throws SQLException { + return new SWPreparedStatement(this, realConnection.prepareStatement( + sql, columnIndexes), this.connectInfo, sql); + } + + public PreparedStatement prepareStatement(String sql, String[] columnNames) + throws SQLException { + return new SWPreparedStatement(this, realConnection.prepareStatement( + sql, columnNames), this.connectInfo, sql); + } + + public Clob createClob() throws SQLException { + return realConnection.createClob(); + } + + public Blob createBlob() throws SQLException { + return realConnection.createBlob(); + } + + public NClob createNClob() throws SQLException { + return realConnection.createNClob(); + } + + public SQLXML createSQLXML() throws SQLException { + return realConnection.createSQLXML(); + } + + public boolean isValid(int timeout) throws SQLException { + return realConnection.isValid(timeout); + } + + public void setClientInfo(String name, String value) + throws SQLClientInfoException { + realConnection.setClientInfo(name, value); + } + + public void setClientInfo(Properties properties) + throws SQLClientInfoException { + realConnection.setClientInfo(properties); + } + + public String getClientInfo(String name) throws SQLException { + return realConnection.getClientInfo(name); + } + + public Properties getClientInfo() throws SQLException { + return realConnection.getClientInfo(); + } + + public Array createArrayOf(String typeName, Object[] elements) + throws SQLException { + return realConnection.createArrayOf(typeName, elements); + } + + public Struct createStruct(String typeName, Object[] attributes) + throws SQLException { + return realConnection.createStruct(typeName, attributes); + } + + public void setSchema(String schema) throws SQLException { + realConnection.setSchema(schema); + } + + public String getSchema() throws SQLException { + return realConnection.getSchema(); + } + + public void abort(Executor executor) throws SQLException { + realConnection.abort(executor); + } + + public void setNetworkTimeout(Executor executor, int milliseconds) + throws SQLException { + realConnection.setNetworkTimeout(executor, milliseconds); + } + + public int getNetworkTimeout() throws SQLException { + return realConnection.getNetworkTimeout(); + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWPreparedStatement.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWPreparedStatement.java new file mode 100644 index 000000000..57186d0ce --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWPreparedStatement.java @@ -0,0 +1,518 @@ +package com.a.eye.skywalking.plugin.jdbc; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.*; +import java.util.Calendar; + +public class SWPreparedStatement implements PreparedStatement { + private Connection realConnection; + private PreparedStatement realStatement; + private ConnectionInfo connectInfo; + private String sql; + + SWPreparedStatement(Connection realConnection, + PreparedStatement realStatement, ConnectionInfo connectInfo, + String sql) { + this.realConnection = realConnection; + this.realStatement = realStatement; + this.connectInfo = connectInfo; + this.sql = sql; + } + + public ResultSet executeQuery(String sql) throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "executeQuery", sql, new PreparedStatementTracing.Executable() { + public ResultSet exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.executeQuery(sql); + } + }); + } + + public int executeUpdate(String sql) throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { + public Integer exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql); + } + }); + } + + public void close() throws SQLException { + realStatement.close(); + } + + public int getMaxFieldSize() throws SQLException { + return realStatement.getMaxFieldSize(); + } + + public void setMaxFieldSize(int max) throws SQLException { + realStatement.setMaxFieldSize(max); + } + + public int getMaxRows() throws SQLException { + return realStatement.getMaxRows(); + } + + public void setMaxRows(int max) throws SQLException { + realStatement.setMaxRows(max); + } + + public void setEscapeProcessing(boolean enable) throws SQLException { + realStatement.setEscapeProcessing(enable); + } + + public int getQueryTimeout() throws SQLException { + return realStatement.getQueryTimeout(); + } + + public void setQueryTimeout(int seconds) throws SQLException { + realStatement.setQueryTimeout(seconds); + } + + public void cancel() throws SQLException { + realStatement.cancel(); + } + + public SQLWarning getWarnings() throws SQLException { + return realStatement.getWarnings(); + } + + public void clearWarnings() throws SQLException { + realStatement.clearWarnings(); + } + + public void setCursorName(String name) throws SQLException { + realStatement.setCursorName(name); + } + + public boolean execute(String sql) throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable() { + public Boolean exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql); + } + }); + } + + public ResultSet getResultSet() throws SQLException { + return realStatement.getResultSet(); + } + + public int getUpdateCount() throws SQLException { + return realStatement.getUpdateCount(); + } + + public boolean getMoreResults() throws SQLException { + return realStatement.getMoreResults(); + } + + public void setFetchDirection(int direction) throws SQLException { + realStatement.setFetchDirection(direction); + } + + public int getFetchDirection() throws SQLException { + return realStatement.getFetchDirection(); + } + + public void setFetchSize(int rows) throws SQLException { + realStatement.setFetchSize(rows); + } + + public int getFetchSize() throws SQLException { + return realStatement.getFetchSize(); + } + + public int getResultSetConcurrency() throws SQLException { + return realStatement.getResultSetConcurrency(); + } + + public int getResultSetType() throws SQLException { + return realStatement.getResultSetType(); + } + + public void addBatch(String sql) throws SQLException { + realStatement.addBatch(sql); + } + + public void clearBatch() throws SQLException { + realStatement.clearBatch(); + } + + public int[] executeBatch() throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "executeBatch", "", new PreparedStatementTracing.Executable() { + public int[] exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.executeBatch(); + } + }); + } + + public Connection getConnection() throws SQLException { + return realConnection; + } + + public boolean getMoreResults(int current) throws SQLException { + return realStatement.getMoreResults(current); + } + + public ResultSet getGeneratedKeys() throws SQLException { + return realStatement.getGeneratedKeys(); + } + + public int executeUpdate(String sql, final int autoGeneratedKeys) + throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { + public Integer exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql, autoGeneratedKeys); + } + }); + } + + public int executeUpdate(String sql, final int[] columnIndexes) + throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { + public Integer exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql, columnIndexes); + } + }); + } + + public int executeUpdate(String sql, final String[] columnNames) + throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { + public Integer exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql, columnNames); + } + }); + } + + public boolean execute(String sql, final int autoGeneratedKeys) + throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable() { + public Boolean exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql, autoGeneratedKeys); + } + }); + } + + public boolean execute(String sql, final int[] columnIndexes) throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable() { + public Boolean exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql, columnIndexes); + } + }); + } + + public boolean execute(String sql, final String[] columnNames) + throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "execute", sql, new PreparedStatementTracing.Executable() { + public Boolean exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql, columnNames); + } + }); + } + + public int getResultSetHoldability() throws SQLException { + return realStatement.getResultSetHoldability(); + } + + public boolean isClosed() throws SQLException { + return realStatement.isClosed(); + } + + public void setPoolable(boolean poolable) throws SQLException { + realStatement.setPoolable(poolable); + } + + public boolean isPoolable() throws SQLException { + return realStatement.isPoolable(); + } + + public void closeOnCompletion() throws SQLException { + realStatement.closeOnCompletion(); + } + + public boolean isCloseOnCompletion() throws SQLException { + return realStatement.isCloseOnCompletion(); + } + + public T unwrap(Class iface) throws SQLException { + return realStatement.unwrap(iface); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + return realStatement.isWrapperFor(iface); + } + + public ResultSet executeQuery() throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "executeQuery", sql, new PreparedStatementTracing.Executable() { + public ResultSet exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.executeQuery(); + } + }); + } + + public int executeUpdate() throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { + public Integer exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(); + } + }); + } + + public void setNull(int parameterIndex, int sqlType) throws SQLException { + realStatement.setNull(parameterIndex, sqlType); + } + + public void setBoolean(int parameterIndex, boolean x) throws SQLException { + realStatement.setBoolean(parameterIndex, x); + } + + public void setByte(int parameterIndex, byte x) throws SQLException { + realStatement.setByte(parameterIndex, x); + } + + public void setShort(int parameterIndex, short x) throws SQLException { + realStatement.setShort(parameterIndex, x); + } + + public void setInt(int parameterIndex, int x) throws SQLException { + realStatement.setInt(parameterIndex, x); + } + + public void setLong(int parameterIndex, long x) throws SQLException { + realStatement.setLong(parameterIndex, x); + } + + public void setFloat(int parameterIndex, float x) throws SQLException { + realStatement.setFloat(parameterIndex, x); + } + + public void setDouble(int parameterIndex, double x) throws SQLException { + realStatement.setDouble(parameterIndex, x); + } + + public void setBigDecimal(int parameterIndex, BigDecimal x) + throws SQLException { + realStatement.setBigDecimal(parameterIndex, x); + } + + public void setString(int parameterIndex, String x) throws SQLException { + realStatement.setString(parameterIndex, x); + } + + public void setBytes(int parameterIndex, byte[] x) throws SQLException { + realStatement.setBytes(parameterIndex, x); + } + + public void setDate(int parameterIndex, Date x) throws SQLException { + realStatement.setDate(parameterIndex, x); + } + + public void setTime(int parameterIndex, Time x) throws SQLException { + realStatement.setTime(parameterIndex, x); + } + + public void setTimestamp(int parameterIndex, Timestamp x) + throws SQLException { + realStatement.setTimestamp(parameterIndex, x); + } + + public void setAsciiStream(int parameterIndex, InputStream x, int length) + throws SQLException { + realStatement.setAsciiStream(parameterIndex, x, length); + } + + @Deprecated + public void setUnicodeStream(int parameterIndex, InputStream x, int length) + throws SQLException { + realStatement.setUnicodeStream(parameterIndex, x, length); + } + + public void setBinaryStream(int parameterIndex, InputStream x, int length) + throws SQLException { + realStatement.setBinaryStream(parameterIndex, x, length); + } + + public void clearParameters() throws SQLException { + realStatement.clearParameters(); + } + + public void setObject(int parameterIndex, Object x, int targetSqlType) + throws SQLException { + realStatement.setObject(parameterIndex, x, targetSqlType); + } + + public void setObject(int parameterIndex, Object x) throws SQLException { + realStatement.setObject(parameterIndex, x); + } + + public boolean execute() throws SQLException { + return PreparedStatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new PreparedStatementTracing.Executable() { + public Boolean exe(PreparedStatement realStatement, String sql) + throws SQLException { + return realStatement.execute(); + } + }); + } + + public void addBatch() throws SQLException { + realStatement.addBatch(); + } + + public void setCharacterStream(int parameterIndex, Reader reader, int length) + throws SQLException { + realStatement.setCharacterStream(parameterIndex, reader, length); + } + + public void setRef(int parameterIndex, Ref x) throws SQLException { + realStatement.setRef(parameterIndex, x); + } + + public void setBlob(int parameterIndex, Blob x) throws SQLException { + realStatement.setBlob(parameterIndex, x); + } + + public void setClob(int parameterIndex, Clob x) throws SQLException { + realStatement.setClob(parameterIndex, x); + } + + public void setArray(int parameterIndex, Array x) throws SQLException { + realStatement.setArray(parameterIndex, x); + } + + public ResultSetMetaData getMetaData() throws SQLException { + return realStatement.getMetaData(); + } + + public void setDate(int parameterIndex, Date x, Calendar cal) + throws SQLException { + realStatement.setDate(parameterIndex, x, cal); + } + + public void setTime(int parameterIndex, Time x, Calendar cal) + throws SQLException { + realStatement.setTime(parameterIndex, x, cal); + } + + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) + throws SQLException { + realStatement.setTimestamp(parameterIndex, x, cal); + } + + public void setNull(int parameterIndex, int sqlType, String typeName) + throws SQLException { + realStatement.setNull(parameterIndex, sqlType, typeName); + } + + public void setURL(int parameterIndex, URL x) throws SQLException { + realStatement.setURL(parameterIndex, x); + } + + public ParameterMetaData getParameterMetaData() throws SQLException { + return realStatement.getParameterMetaData(); + } + + public void setRowId(int parameterIndex, RowId x) throws SQLException { + realStatement.setRowId(parameterIndex, x); + } + + public void setNString(int parameterIndex, String value) + throws SQLException { + realStatement.setNString(parameterIndex, value); + } + + public void setNCharacterStream(int parameterIndex, Reader value, + long length) throws SQLException { + realStatement.setNCharacterStream(parameterIndex, value, length); + } + + public void setNClob(int parameterIndex, NClob value) throws SQLException { + realStatement.setNClob(parameterIndex, value); + } + + public void setClob(int parameterIndex, Reader reader, long length) + throws SQLException { + realStatement.setClob(parameterIndex, reader, length); + } + + public void setBlob(int parameterIndex, InputStream inputStream, long length) + throws SQLException { + realStatement.setBlob(parameterIndex, inputStream, length); + } + + public void setNClob(int parameterIndex, Reader reader, long length) + throws SQLException { + realStatement.setNClob(parameterIndex, reader, length); + } + + public void setSQLXML(int parameterIndex, SQLXML xmlObject) + throws SQLException { + realStatement.setSQLXML(parameterIndex, xmlObject); + } + + public void setObject(int parameterIndex, Object x, int targetSqlType, + int scaleOrLength) throws SQLException { + realStatement.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + } + + public void setAsciiStream(int parameterIndex, InputStream x, long length) + throws SQLException { + realStatement.setAsciiStream(parameterIndex, x, length); + } + + public void setBinaryStream(int parameterIndex, InputStream x, long length) + throws SQLException { + realStatement.setBinaryStream(parameterIndex, x, length); + } + + public void setCharacterStream(int parameterIndex, Reader reader, + long length) throws SQLException { + realStatement.setCharacterStream(parameterIndex, reader, length); + } + + public void setAsciiStream(int parameterIndex, InputStream x) + throws SQLException { + realStatement.setAsciiStream(parameterIndex, x); + } + + public void setBinaryStream(int parameterIndex, InputStream x) + throws SQLException { + realStatement.setBinaryStream(parameterIndex, x); + } + + public void setCharacterStream(int parameterIndex, Reader reader) + throws SQLException { + realStatement.setCharacterStream(parameterIndex, reader); + } + + public void setNCharacterStream(int parameterIndex, Reader value) + throws SQLException { + realStatement.setNCharacterStream(parameterIndex, value); + } + + public void setClob(int parameterIndex, Reader reader) throws SQLException { + realStatement.setClob(parameterIndex, reader); + } + + public void setBlob(int parameterIndex, InputStream inputStream) + throws SQLException { + realStatement.setBlob(parameterIndex, inputStream); + } + + public void setNClob(int parameterIndex, Reader reader) throws SQLException { + realStatement.setNClob(parameterIndex, reader); + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWStatement.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWStatement.java new file mode 100644 index 000000000..2d212b7a5 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/SWStatement.java @@ -0,0 +1,251 @@ +package com.a.eye.skywalking.plugin.jdbc; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLWarning; + + +public class SWStatement implements java.sql.Statement { + private Connection realConnection; + private java.sql.Statement realStatement; + private ConnectionInfo connectInfo; + + SWStatement(Connection realConnection, java.sql.Statement realStatement, ConnectionInfo connectInfo) { + this.realConnection = realConnection; + this.realStatement = realStatement; + this.connectInfo = connectInfo; + } + + public T unwrap(Class iface) throws SQLException { + return realStatement.unwrap(iface); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + return realStatement.isWrapperFor(iface); + } + + public ResultSet executeQuery(String sql) throws SQLException { + return StatementTracing.execute(realStatement, connectInfo, "executeQuery", sql, new StatementTracing.Executable() { + public ResultSet exe(java.sql.Statement realStatement, String sql) + throws SQLException { + return realStatement.executeQuery(sql); + } + }); + } + + public int executeUpdate(String sql) throws SQLException { + return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable() { + public Integer exe(java.sql.Statement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql); + } + }); + } + + public void close() throws SQLException { + realStatement.close(); + } + + public int getMaxFieldSize() throws SQLException { + return realStatement.getMaxFieldSize(); + } + + public void setMaxFieldSize(int max) throws SQLException { + realStatement.setMaxFieldSize(max); + } + + public int getMaxRows() throws SQLException { + return realStatement.getMaxRows(); + } + + public void setMaxRows(int max) throws SQLException { + realStatement.setMaxRows(max); + } + + public void setEscapeProcessing(boolean enable) throws SQLException { + realStatement.setEscapeProcessing(enable); + } + + public int getQueryTimeout() throws SQLException { + return realStatement.getQueryTimeout(); + } + + public void setQueryTimeout(int seconds) throws SQLException { + realStatement.setQueryTimeout(seconds); + } + + public void cancel() throws SQLException { + realStatement.cancel(); + } + + public SQLWarning getWarnings() throws SQLException { + return realStatement.getWarnings(); + } + + public void clearWarnings() throws SQLException { + realStatement.clearWarnings(); + } + + public void setCursorName(String name) throws SQLException { + realStatement.setCursorName(name); + } + + public boolean execute(String sql) throws SQLException { + return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable() { + public Boolean exe(java.sql.Statement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql); + } + }); + } + + public ResultSet getResultSet() throws SQLException { + return realStatement.getResultSet(); + } + + public int getUpdateCount() throws SQLException { + return realStatement.getUpdateCount(); + } + + public boolean getMoreResults() throws SQLException { + return realStatement.getMoreResults(); + } + + public void setFetchDirection(int direction) throws SQLException { + realStatement.setFetchDirection(direction); + } + + public int getFetchDirection() throws SQLException { + return realStatement.getFetchDirection(); + } + + public void setFetchSize(int rows) throws SQLException { + realStatement.setFetchSize(rows); + } + + public int getFetchSize() throws SQLException { + return realStatement.getFetchSize(); + } + + public int getResultSetConcurrency() throws SQLException { + return realStatement.getResultSetConcurrency(); + } + + public int getResultSetType() throws SQLException { + return realStatement.getResultSetType(); + } + + public void addBatch(String sql) throws SQLException { + realStatement.addBatch(sql); + } + + public void clearBatch() throws SQLException { + realStatement.clearBatch(); + } + + public int[] executeBatch() throws SQLException { + return StatementTracing.execute(realStatement, connectInfo, "executeBatch", "", new StatementTracing.Executable() { + public int[] exe(java.sql.Statement realStatement, String sql) + throws SQLException { + return realStatement.executeBatch(); + } + }); + } + + public Connection getConnection() throws SQLException { + return this.realConnection; + } + + public boolean getMoreResults(int current) throws SQLException { + return realStatement.getMoreResults(current); + } + + public ResultSet getGeneratedKeys() throws SQLException { + return realStatement.getGeneratedKeys(); + } + + public int executeUpdate(String sql, final int autoGeneratedKeys) + throws SQLException { + return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable() { + public Integer exe(java.sql.Statement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql, autoGeneratedKeys); + } + }); + } + + public int executeUpdate(String sql, final int[] columnIndexes) + throws SQLException { + return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable() { + public Integer exe(java.sql.Statement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql, columnIndexes); + } + }); + } + + public int executeUpdate(String sql, final String[] columnNames) + throws SQLException { + return StatementTracing.execute(realStatement, connectInfo, "executeUpdate", sql, new StatementTracing.Executable() { + public Integer exe(java.sql.Statement realStatement, String sql) + throws SQLException { + return realStatement.executeUpdate(sql, columnNames); + } + }); + } + + public boolean execute(String sql, final int autoGeneratedKeys) + throws SQLException { + return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable() { + public Boolean exe(java.sql.Statement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql, autoGeneratedKeys); + } + }); + } + + public boolean execute(String sql, final int[] columnIndexes) throws SQLException { + return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable() { + public Boolean exe(java.sql.Statement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql, columnIndexes); + } + }); + } + + public boolean execute(String sql, final String[] columnNames) + throws SQLException { + return StatementTracing.execute(realStatement, connectInfo, "execute", sql, new StatementTracing.Executable() { + public Boolean exe(java.sql.Statement realStatement, String sql) + throws SQLException { + return realStatement.execute(sql, columnNames); + } + }); + } + + public int getResultSetHoldability() throws SQLException { + return realStatement.getResultSetHoldability(); + } + + public boolean isClosed() throws SQLException { + return realStatement.isClosed(); + } + + public void setPoolable(boolean poolable) throws SQLException { + realStatement.setPoolable(poolable); + } + + public boolean isPoolable() throws SQLException { + return realStatement.isPoolable(); + } + + public void closeOnCompletion() throws SQLException { + realStatement.closeOnCompletion(); + } + + public boolean isCloseOnCompletion() throws SQLException { + return realStatement.isCloseOnCompletion(); + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/StatementTracing.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/StatementTracing.java new file mode 100644 index 000000000..4e4e4f316 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/StatementTracing.java @@ -0,0 +1,50 @@ +package com.a.eye.skywalking.plugin.jdbc; + + +import com.a.eye.skywalking.api.context.ContextManager; +import com.a.eye.skywalking.api.util.StringUtil; +import com.a.eye.skywalking.trace.Span; +import com.a.eye.skywalking.trace.tag.Tags; + +import java.sql.SQLException; + +/** + * {@link StatementTracing} create span with the {@link Span#operationName} start with + * "JDBC/Statement/"and set {@link ConnectionInfo#dbType} to the {@link Tags#COMPONENT}. + * + * Notice: {@link Tags#PEERS} may be is null if database connection url don't contain multiple hosts. + * + * @author zhangxin + */ +public class StatementTracing { + public static R execute(java.sql.Statement realStatement, + ConnectionInfo connectInfo, String method, String sql, Executable exec) + throws SQLException { + try { + Span span = ContextManager.INSTANCE.createSpan("JDBC/Statement/" + method); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, sql); + Tags.COMPONENT.set(span, connectInfo.getDBType()); + if (!StringUtil.isEmpty(connectInfo.getHosts())) { + Tags.PEERS.set(span, connectInfo.getHosts()); + } else { + Tags.PEER_PORT.set(span, connectInfo.getPort()); + Tags.PEER_HOST.set(span, connectInfo.getHost()); + } + return exec.exe(realStatement, sql); + } catch (SQLException e) { + Span span = ContextManager.INSTANCE.activeSpan(); + Tags.ERROR.set(span, true); + span.log(e); + throw e; + } finally { + ContextManager.INSTANCE.stopSpan(); + } + } + + public interface Executable { + R exe(java.sql.Statement realStatement, String sql) + throws SQLException; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/AbstractConnectionURLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/AbstractConnectionURLParser.java new file mode 100644 index 000000000..1ed4fa846 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/AbstractConnectionURLParser.java @@ -0,0 +1,65 @@ +package com.a.eye.skywalking.plugin.jdbc.connectionurl.parser; + +/** + * {@link AbstractConnectionURLParser} is abstract class that the class that parse jdbc url. + * + * @author zhangxin + */ +public abstract class AbstractConnectionURLParser implements ConnectionURLParser { + + /** + * Connection url + */ + protected String url; + + public AbstractConnectionURLParser(String url) { + this.url = url; + } + + /** + * Fetch the index range that database host and port from connection url. + * + * @return index range that database hosts. + */ + protected abstract int[] fetchDatabaseHostsIndexRange(); + + /** + * Fetch the index range that database name from connection url. + * + * @return index range that database name. + */ + protected abstract int[] fetchDatabaseNameIndexRange(); + + /** + * Fetch database host(s) from connection url. + * + * @return database host(s). + */ + protected String fetchDatabaseHostsFromURL() { + int[] indexRange = fetchDatabaseHostsIndexRange(); + return url.substring(indexRange[0], indexRange[1]); + } + + /** + * Fetch database name from connection url. + * + * @return database name. + */ + protected String fetchDatabaseNameFromURL() { + int[] indexRange = fetchDatabaseNameIndexRange(); + return url.substring(indexRange[0], indexRange[1]); + } + + /** + * Fetch database name from connection url. + * + * @return database name. + */ + protected String fetchDatabaseNameFromURL(int[] indexRange) { + return url.substring(indexRange[0], indexRange[1]); + } + + public String getConnectionURL() { + return this.url; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java new file mode 100644 index 000000000..0576492ed --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java @@ -0,0 +1,14 @@ +package com.a.eye.skywalking.plugin.jdbc.connectionurl.parser; + +import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; + + +public interface ConnectionURLParser { + /** + * The class that extend {@link ConnectionURLParser} spilt + * the database name , the database host(s) from connection url. + * + * @return connection info. + */ + ConnectionInfo parse(); +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/H2URLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/H2URLParser.java new file mode 100644 index 000000000..81b992501 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/H2URLParser.java @@ -0,0 +1,118 @@ +package com.a.eye.skywalking.plugin.jdbc.connectionurl.parser; + +import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; + +/** + * {@link H2URLParser} presents that skywalking how to parse the connection url of H2 database. + * {@link ConnectionInfo#host} will return localhost and {@link ConnectionInfo#port} will return + * -1 if H2 running with memory mode or file mode, or it will return the host and the port. + * + * {@link H2URLParser} check the connection url if contains "file" or "mem". if yes. the database + * name substring the connection url from the index after "file" index or the "mem" index to the + * index of first charset ";". + * + * The {@link ConnectionInfo#host} be set the string between charset "//" and the first charset "/" after + * the charset "//", and {@link ConnectionInfo#databaseName} be set the string between the last index of "/" and + * the first charset ";". + * + * @author zhangxin + */ +public class H2URLParser extends AbstractConnectionURLParser { + + private static final String LOCALHOST = "localhost"; + /** + * Default port that H2 running with mix mode. + */ + private static final int DEFAULT_PORT = 8084; + /** + * Flag that H2 running with file mode. + */ + private static final String FILE_MODE_FLAG = "file"; + /** + * Flag that H2 running with memory mode. + */ + private static final String MEMORY_MODE_FLAG = "mem"; + /** + * H2 data type. + */ + private static final String H2_DB_TYPE = "H2"; + + public H2URLParser(String url) { + super(url); + } + + @Override + protected int[] fetchDatabaseHostsIndexRange() { + int hostLabelStartIndex = url.indexOf("//"); + int hostLabelEndIndex = url.indexOf("/", hostLabelStartIndex + 2); + return new int[]{hostLabelStartIndex + 2, hostLabelEndIndex}; + } + + @Override + protected int[] fetchDatabaseNameIndexRange() { + int databaseStartTag = url.lastIndexOf("/"); + int databaseEndTag = url.indexOf(";"); + if (databaseEndTag == -1) { + databaseEndTag = url.length(); + } + return new int[]{databaseStartTag + 1, databaseEndTag}; + } + + @Override + public ConnectionInfo parse() { + int[] databaseNameRangeIndex = fetchDatabaseNameRangeIndexFromURLForH2FileMode(); + if (databaseNameRangeIndex != null) { + return new ConnectionInfo(H2_DB_TYPE, LOCALHOST, -1, fetchDatabaseNameFromURL(databaseNameRangeIndex)); + } + + databaseNameRangeIndex = fetchDatabaseNameRangeIndexFromURLForH2MemMode(); + if (databaseNameRangeIndex != null) { + return new ConnectionInfo(H2_DB_TYPE, LOCALHOST, -1, fetchDatabaseNameFromURL(databaseNameRangeIndex)); + } + + String[] hostAndPort = fetchDatabaseHostsFromURL().split(":"); + if (hostAndPort.length == 1) { + return new ConnectionInfo(H2_DB_TYPE, hostAndPort[0], DEFAULT_PORT, fetchDatabaseNameFromURL()); + } else { + return new ConnectionInfo(H2_DB_TYPE, hostAndPort[0], Integer.valueOf(hostAndPort[1]), fetchDatabaseNameFromURL()); + } + } + + /** + * Fetch range index that the database name from connection url if H2 database running with file mode. + * + * @return range index that the database name. + */ + private int[] fetchDatabaseNameRangeIndexFromURLForH2FileMode() { + int fileLabelIndex = url.indexOf(FILE_MODE_FLAG); + int parameterLabelIndex = url.indexOf(";", fileLabelIndex); + if (parameterLabelIndex == -1) { + parameterLabelIndex = url.length(); + } + + if (fileLabelIndex != -1) { + return new int[]{fileLabelIndex + FILE_MODE_FLAG.length() + 1, parameterLabelIndex}; + } else { + return null; + } + } + + /** + * Fetch range index that the database name from connection url if H2 database running with memory mode. + * + * @return range index that the database name. + */ + private int[] fetchDatabaseNameRangeIndexFromURLForH2MemMode() { + int fileLabelIndex = url.indexOf(MEMORY_MODE_FLAG); + int parameterLabelIndex = url.indexOf(";", fileLabelIndex); + if (parameterLabelIndex == -1) { + parameterLabelIndex = url.length(); + } + + if (fileLabelIndex != -1) { + return new int[]{fileLabelIndex + MEMORY_MODE_FLAG.length() + 1, parameterLabelIndex}; + } else { + return null; + } + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/MysqlURLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/MysqlURLParser.java new file mode 100644 index 000000000..604d115ef --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/MysqlURLParser.java @@ -0,0 +1,72 @@ +package com.a.eye.skywalking.plugin.jdbc.connectionurl.parser; + +import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; + +/** + * {@link MysqlURLParser} presents that how to parse mysql connection url. + * + * The {@link ConnectionInfo#host} be set the string between charset "//" and the first + * charset "/" after the charset "//", and {@link ConnectionInfo#databaseName} be set the + * string between the last index of "/" and the first charset "?". but one more thing, the + * {@link ConnectionInfo#hosts} be set if the host container multiple host. + * + * @author zhangxin + */ +public class MysqlURLParser extends AbstractConnectionURLParser { + + /** + * Mysql default port. + */ + private static final int DEFAULT_PORT = 3306; + /** + * Mysql db type. + */ + private static final String MYSQL_DB_TYPE = "Mysql"; + + public MysqlURLParser(String url) { + super(url); + } + + @Override + protected int[] fetchDatabaseHostsIndexRange() { + int hostLabelStartIndex = url.indexOf("//"); + int hostLabelEndIndex = url.indexOf("/", hostLabelStartIndex + 2); + return new int[]{hostLabelStartIndex + 2, hostLabelEndIndex}; + } + + @Override + protected int[] fetchDatabaseNameIndexRange() { + int databaseStartTag = url.lastIndexOf("/"); + int databaseEndTag = url.indexOf("?", databaseStartTag); + if (databaseEndTag == -1) { + databaseEndTag = url.length(); + } + return new int[]{databaseStartTag + 1, databaseEndTag}; + } + + @Override + public ConnectionInfo parse() { + int[] hostRangeIndex = fetchDatabaseHostsIndexRange(); + String hosts = url.substring(hostRangeIndex[0], hostRangeIndex[1]); + String[] hostSegment = hosts.split(","); + if (hostSegment.length > 1) { + StringBuilder sb = new StringBuilder(); + for (String host : hostSegment) { + if (host.split(":").length == 1) { + sb.append(host + ":" + DEFAULT_PORT + ","); + } else { + sb.append(host + ","); + } + } + return new ConnectionInfo(MYSQL_DB_TYPE, sb.toString(), fetchDatabaseNameFromURL()); + } else { + String[] hostAndPort = hostSegment[0].split(":"); + if (hostAndPort.length != 1) { + return new ConnectionInfo(MYSQL_DB_TYPE, hostAndPort[0], Integer.valueOf(hostAndPort[1]), fetchDatabaseNameFromURL()); + } else { + return new ConnectionInfo(MYSQL_DB_TYPE, hostAndPort[0], DEFAULT_PORT, fetchDatabaseNameFromURL()); + } + } + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/OracleURLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/OracleURLParser.java new file mode 100644 index 000000000..eecd7c242 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/OracleURLParser.java @@ -0,0 +1,62 @@ +package com.a.eye.skywalking.plugin.jdbc.connectionurl.parser; + +import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; + +/** + * {@link OracleURLParser} presents that how to parse oracle connection url. + * + * The {@link ConnectionInfo#host} be set the string between charset "@" and the last + * charset ":" after the charset "@", and {@link ConnectionInfo#databaseName} be set the + * string that after the last index of ":". + * + * Note: {@link OracleURLParser} can parse the commons connection url. the commons + * connection url is of the form: jdbc:oracle::@,the other + * the form of connection url cannot be parsed success. + * + * @author zhangxin + */ +public class OracleURLParser extends AbstractConnectionURLParser { + + /** + * Oracle db type. + */ + private static final String ORACLE_DB_TYPE = "Oracle"; + /** + * Oracle default port + */ + private static final int DEFAULT_PORT = 1521; + + public OracleURLParser(String url) { + super(url); + } + + @Override + protected int[] fetchDatabaseHostsIndexRange() { + int hostLabelStartIndex = url.indexOf("@"); + int hostLabelEndIndex = url.lastIndexOf(":"); + return new int[]{hostLabelStartIndex + 1, hostLabelEndIndex}; + } + + @Override + protected int[] fetchDatabaseNameIndexRange() { + return new int[0]; + } + + @Override + public ConnectionInfo parse() { + int[] hostRangeIndex = fetchDatabaseHostsIndexRange(); + String host = fetchDatabaseHostsFromURL(); + String[] hostSegment = splitDatabaseAddress(host); + String databaseName = url.substring(hostRangeIndex[1] + 1); + if (hostSegment.length == 1) { + return new ConnectionInfo(ORACLE_DB_TYPE, host, DEFAULT_PORT, databaseName); + } else { + return new ConnectionInfo(ORACLE_DB_TYPE, hostSegment[0], Integer.valueOf(hostSegment[1]), databaseName); + } + } + + private String[] splitDatabaseAddress(String address) { + String[] hostSegment = address.split(":"); + return hostSegment; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParser.java new file mode 100644 index 000000000..c6912a8f6 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParser.java @@ -0,0 +1,23 @@ +package com.a.eye.skywalking.plugin.jdbc.connectionurl.parser; + +import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; + +/** + * {@link URLParser#parser(String)} support parse the connection url, such as Mysql, Oracle, H2 Database. + * But there are some url cannot be parsed, such as Oracle connection url with multiple host. + * + * @author zhangxin + */ +public class URLParser { + public static ConnectionInfo parser(String url) { + ConnectionURLParser parser = null; + if (url.startsWith("jdbc:mysql")) { + parser = new MysqlURLParser(url); + } else if (url.startsWith("jdbc:oracle")) { + parser = new OracleURLParser(url); + } else if (url.startsWith("jdbc:h2")) { + parser = new H2URLParser(url); + } + return parser.parse(); + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabaseInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabaseInstrumentation.java new file mode 100644 index 000000000..e9d9e4a9b --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabaseInstrumentation.java @@ -0,0 +1,53 @@ +package com.a.eye.skywalking.plugin.jdbc.define; + +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.jdbc.SWConnection; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; + +import java.util.Properties; + +import static net.bytebuddy.matcher.ElementMatchers.named; + +/** + * JDBC plugin using {@link JDBCDriverInterceptor} to intercept all the class that extend {@link java.sql.Driver#connect(String, Properties)}, + * and change the return object to {@link com.a.eye.skywalking.plugin.jdbc.SWConnection}, All the method of {@link com.a.eye.skywalking.plugin.jdbc.SWConnection} + * is delete to the real JDBC Driver Connection object. + * It will return {@link com.a.eye.skywalking.plugin.jdbc.SWStatement} when {@link java.sql.Driver} to create {@link java.sql.Statement}, return + * {@link com.a.eye.skywalking.plugin.jdbc.SWPreparedStatement} when {@link java.sql.Driver} to create {@link java.sql.PreparedStatement} and return + * {@link com.a.eye.skywalking.plugin.jdbc.SWCallableStatement} when {@link java.sql.Driver} to create {@link java.sql.CallableStatement}. + * of course, {@link com.a.eye.skywalking.plugin.jdbc.SWStatement}, {@link com.a.eye.skywalking.plugin.jdbc.SWPreparedStatement} and + * {@link com.a.eye.skywalking.plugin.jdbc.SWCallableStatement} are same as {@link SWConnection}. + * + * @author zhangxin + */ +public abstract class AbstractDatabaseInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + /** + * Intercept class + */ + private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jdbc.define.JDBCDriverInterceptor"; + + @Override + protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return null; + } + + @Override + protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[]{new InstanceMethodsInterceptPoint() { + @Override + public ElementMatcher getMethodsMatcher() { + return named("connect"); + } + + @Override + public String getMethodsInterceptor() { + return INTERCEPT_CLASS; + } + }}; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/H2Instrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/H2Instrumentation.java new file mode 100644 index 000000000..6b44b91fd --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/H2Instrumentation.java @@ -0,0 +1,19 @@ +package com.a.eye.skywalking.plugin.jdbc.define; + +/** + * {@link H2Instrumentation} presents that skywalking will intercept {@link org.h2.Driver}. + * + * @author zhangxin + */ +public class H2Instrumentation extends AbstractDatabaseInstrumentation { + + /** + * Class of intercept H2 driver + */ + private static final String CLASS_OF_INTERCEPT_H2_DRIVER = "org.h2.Driver"; + + @Override + protected String enhanceClassName() { + return CLASS_OF_INTERCEPT_H2_DRIVER; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/JDBCDriverInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/JDBCDriverInterceptor.java new file mode 100644 index 000000000..f5439c7b4 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/JDBCDriverInterceptor.java @@ -0,0 +1,38 @@ +package com.a.eye.skywalking.plugin.jdbc.define; + +import com.a.eye.skywalking.api.plugin.interceptor.EnhancedClassInstanceContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodInvokeContext; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; +import com.a.eye.skywalking.plugin.jdbc.SWConnection; + +import java.sql.Connection; +import java.util.Properties; + +/** + * {@link JDBCDriverInterceptor} will return {@link SWConnection} when {@link java.sql.Driver#connect(String, Properties)}, + * instead of the instance that extend {@link Connection}. + * + * @author zhangxin + */ +public class JDBCDriverInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, + MethodInterceptResult result) { + // do nothing + } + + @Override + public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, + Object ret) { + return new SWConnection((String) interceptorContext.allArguments()[0], + (Properties) interceptorContext.allArguments()[1], (Connection) ret); + } + + @Override + public void handleMethodException(Throwable t, EnhancedClassInstanceContext context, + InstanceMethodInvokeContext interceptorContext) { + // do nothing. + } + +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/MysqlInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/MysqlInstrumentation.java new file mode 100644 index 000000000..568088510 --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/MysqlInstrumentation.java @@ -0,0 +1,13 @@ +package com.a.eye.skywalking.plugin.jdbc.define; + +/** + * {@link MysqlInstrumentation} presents that skywalking will intercept {@link com.mysql.jdbc.Driver}. + * + * @author zhangxin + */ +public class MysqlInstrumentation extends AbstractDatabaseInstrumentation { + @Override + protected String enhanceClassName() { + return "com.mysql.jdbc.Driver"; + } +} diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/OracleInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/OracleInstrumentation.java new file mode 100644 index 000000000..221f114ec --- /dev/null +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/OracleInstrumentation.java @@ -0,0 +1,14 @@ +package com.a.eye.skywalking.plugin.jdbc.define; + +/** + * {@link OracleInstrumentation} presents that skywalking will intercept the class oracle.jdbc.OracleDriver + * . + * + * @author zhangxin + */ +public class OracleInstrumentation extends AbstractDatabaseInstrumentation { + @Override + protected String enhanceClassName() { + return "oracle.jdbc.OracleDriver"; + } +} From b66c14d02b99591f41f88a11829e31b9be8b6091 Mon Sep 17 00:00:00 2001 From: wusheng Date: Sat, 25 Feb 2017 10:59:33 +0800 Subject: [PATCH 08/12] Alter dependency.version --- skywalking-sniffer/skywalking-api/pom.xml | 2 +- skywalking-sniffer/skywalking-sdk-plugin/pom.xml | 2 +- skywalking-sniffer/skywalking-toolkit-activation/pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/skywalking-sniffer/skywalking-api/pom.xml b/skywalking-sniffer/skywalking-api/pom.xml index 5d898ca26..eff87bd7e 100644 --- a/skywalking-sniffer/skywalking-api/pom.xml +++ b/skywalking-sniffer/skywalking-api/pom.xml @@ -29,7 +29,7 @@ com.a.eye skywalking-trace - 3.0-2017 + ${project.version} com.lmax diff --git a/skywalking-sniffer/skywalking-sdk-plugin/pom.xml b/skywalking-sniffer/skywalking-sdk-plugin/pom.xml index ee2399093..9c682eb7a 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/pom.xml +++ b/skywalking-sniffer/skywalking-sdk-plugin/pom.xml @@ -31,7 +31,7 @@ com.a.eye skywalking-api - 3.0-2017 + ${project.version} diff --git a/skywalking-sniffer/skywalking-toolkit-activation/pom.xml b/skywalking-sniffer/skywalking-toolkit-activation/pom.xml index 29b42a0d9..26ebce22f 100644 --- a/skywalking-sniffer/skywalking-toolkit-activation/pom.xml +++ b/skywalking-sniffer/skywalking-toolkit-activation/pom.xml @@ -23,7 +23,7 @@ com.a.eye skywalking-api - 3.0-2017 + ${project.version} From ec8571901996b33a8f2b8ea9c7710ae44604c2f9 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Sat, 25 Feb 2017 17:37:50 +0800 Subject: [PATCH 09/12] update the comment to improve the comment readable --- .../plugin/dubbo/DubboInstrumentation.java | 10 +-- .../plugin/dubbo/DubboInterceptor.java | 71 ++++++++----------- .../plugin/dubbox/BugFixActive.java | 4 +- .../skywalking/plugin/dubbox/SWBaseBean.java | 14 ++-- .../src/main/resources/skywalking-plugin.def | 2 +- .../plugin/dubbo/DubboInterceptorTest.java | 2 +- .../dubbo/RequestParamForTestBelow283.java | 6 +- .../v4/HttpClientExecuteInterceptor.java | 7 +- .../AbstractHttpClientInstrumentation.java | 5 +- ...DefaultRequestDirectorInstrumentation.java | 2 +- .../v4/define/HttpClientInstrumentation.java | 5 +- .../InternalHttpClientInstrumentation.java | 5 +- .../MinimalHttpClientInstrumentation.java | 7 +- ...nURLParser.java => AbstractURLParser.java} | 15 +--- .../parser/ConnectionURLParser.java | 3 +- .../connectionurl/parser/H2URLParser.java | 8 +-- .../connectionurl/parser/MysqlURLParser.java | 18 ++--- .../connectionurl/parser/OracleURLParser.java | 14 ++-- .../jdbc/connectionurl/parser/URLParser.java | 11 ++- .../AbstractDatabaseInstrumentation.java | 12 +--- .../plugin/jdbc/define/H2Instrumentation.java | 5 +- .../jdbc/define/JDBCDriverInterceptor.java | 4 +- .../jdbc/define/MysqlInstrumentation.java | 2 +- .../jdbc/define/OracleInstrumentation.java | 2 +- ...structorWithHostAndPortArgInterceptor.java | 5 +- ...ctorWithListHostAndPortArgInterceptor.java | 4 +- ...onstructorWithShardInfoArgInterceptor.java | 4 +- ...isConstructorWithStringArgInterceptor.java | 4 +- ...JedisConstructorWithUriArgInterceptor.java | 4 +- .../define/JedisClusterInstrumentation.java | 22 +----- .../jedis/v2/define/JedisInstrumentation.java | 26 ++----- .../plugin/motan/ProviderInterceptor.java | 4 +- ...java => MotanConsumerInstrumentation.java} | 19 ++--- ...java => MotanProviderInstrumentation.java} | 4 +- .../src/main/resources/skywalking-plugin.def | 4 +- .../skywalking-sdk-plugin/pom.xml | 4 +- 36 files changed, 117 insertions(+), 221 deletions(-) rename skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/{AbstractConnectionURLParser.java => AbstractURLParser.java} (78%) rename skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/{ConsumerInstrumentation.java => MotanConsumerInstrumentation.java} (81%) rename skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/{ProviderInstrumentation.java => MotanProviderInstrumentation.java} (93%) diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java index 330b2cc63..402b45d93 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInstrumentation.java @@ -12,20 +12,14 @@ import net.bytebuddy.matcher.ElementMatcher; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link DubboInstrumentation} presents that skywalking use class {@link DubboInterceptor} to - * intercept {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}. + * {@link DubboInstrumentation} presents that skywalking intercepts {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)} + * by using {@link DubboInterceptor}. * * @author zhangxin */ public class DubboInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - /** - * Enhance class. - */ private static final String ENHANCE_CLASS = "com.alibaba.dubbo.monitor.support.MonitorFilter"; - /** - * Intercept class. - */ private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.dubbo.DubboInterceptor"; @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java index 1ec77436d..eea854141 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptor.java @@ -18,10 +18,10 @@ import com.alibaba.dubbo.rpc.RpcContext; /** * {@link DubboInterceptor} define how to enhance class {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}. - * the context data will transport to the provider side by {@link RpcContext#attachments}.but all the version of dubbo framework below 2.8.3 + * the trace context transport to the provider side by {@link RpcContext#attachments}.but all the version of dubbo framework below 2.8.3 * don't support {@link RpcContext#attachments}, we support another way to support it. it is that all request parameters of dubbo service - * need to extend {@link SWBaseBean}, and {@link DubboInterceptor} will inject the serialized context data to the {@link SWBaseBean} bean and - * extract the serialized context data from {@link SWBaseBean}, or the context data will not transport to the provider side. + * need to extend {@link SWBaseBean}, and {@link DubboInterceptor} will inject the trace context data to the {@link SWBaseBean} bean and + * extract the trace context data from {@link SWBaseBean}, or the trace context data will not transport to the provider side. * * @author zhangxin */ @@ -32,12 +32,12 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { /** *

Consumer:

- * The serialized context data will inject the first param that extend {@link SWBaseBean} of dubbo service + * The serialized trace context data will inject the first param that extend {@link SWBaseBean} of dubbo service * if the method {@link BugFixActive#active()} be called. or the serialized context data will inject to the * {@link RpcContext#attachments} for transport to provider side. * *

Provider:

- * The serialized context data will extract from the first param that extend {@link SWBaseBean} of dubbo service + * The serialized trace context data will extract from the first param that extend {@link SWBaseBean} of dubbo service * if the method {@link BugFixActive#active()} be called. or it will extract from {@link RpcContext#attachments}. * current trace segment will ref if the serialize context data is not null. */ @@ -63,44 +63,32 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { ContextCarrier contextCarrier = new ContextCarrier(); ContextManager.INSTANCE.inject(contextCarrier); if (!BugFixActive.isActive()) { - // context.setAttachment("contextData", contextDataStr); - // context的setAttachment方法在重试机制的时候并不会覆盖原有的Attachment - // 参见Dubbo源代码:“com.alibaba.dubbo.rpc.RpcInvocation” - // public void setAttachmentIfAbsent(String key, String value) { - // if (attachments == null) { - // attachments = new HashMap(); - // } - // if (! attachments.containsKey(key)) { - // attachments.put(key, value); - // } - // } - // 在Rest模式中attachment会被抹除,不会传入到服务端 - // Rest模式会将attachment存放到header里面,具体见com.alibaba.dubbo.rpc.protocol.rest.RpcContextFilter //invocation.getAttachments().put("contextData", contextDataStr); + //@see https://github.com/alibaba/dubbo/blob/dubbo-2.5.3/dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java#L154-L161 rpcContext.getAttachments().put(ATTACHMENT_NAME_OF_CONTEXT_DATA, contextCarrier.serialize()); } else { - fix283SendNoAttachmentIssue(invocation, contextCarrier.serialize()); + fix283SendNoAttachmentIssue(invocation, contextCarrier); } } else { Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER); - String contextDataStr; + ContextCarrier contextCarrier; if (!BugFixActive.isActive()) { - contextDataStr = rpcContext.getAttachment(ATTACHMENT_NAME_OF_CONTEXT_DATA); + contextCarrier = new ContextCarrier().deserialize(rpcContext.getAttachment(ATTACHMENT_NAME_OF_CONTEXT_DATA)); } else { - contextDataStr = fix283RecvNoAttachmentIssue(invocation); + contextCarrier = fix283RecvNoAttachmentIssue(invocation); } - if (contextDataStr != null && contextDataStr.length() > 0) { - ContextManager.INSTANCE.extract(new ContextCarrier().deserialize(contextDataStr)); + if (contextCarrier != null) { + ContextManager.INSTANCE.extract(contextCarrier); } } } /** - * {@link DubboInterceptor#afterMethod(EnhancedClassInstanceContext, InstanceMethodInvokeContext, Object)} be executed after - * {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}, and it will check {@link Result#getException()} if is null. - * current active span will log the exception and set true to the value of error tag if the {@link Result#getException()} is not null. + * Execute after {@link com.alibaba.dubbo.monitor.support.MonitorFilter#invoke(Invoker, Invocation)}, + * when dubbo instrumentation is active。Check {@link Result#getException()} , if not NULL, + * log the exception and set tag error=true. */ @Override public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext, @@ -121,7 +109,7 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { } /** - * Active span will log the exception and set current span value of error tag. + * Log the throwable, which occurs in Dubbo RPC service. */ private void dealException(Throwable throwable) { Span span = ContextManager.INSTANCE.activeSpan(); @@ -130,12 +118,11 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { } /** - * Generate operation name. - * the operation name should be like this com.a.eye.skywalking.plugin.test.Test.test(String). + * Format operation name. e.g. com.a.eye.skywalking.plugin.test.Test.test(String) * * @return operation name. */ - private static String generateOperationName(URL requestURL, Invocation invocation) { + private String generateOperationName(URL requestURL, Invocation invocation) { StringBuilder operationName = new StringBuilder(); operationName.append(requestURL.getPath()); operationName.append("." + invocation.getMethodName() + "("); @@ -153,12 +140,12 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { } /** - * Generate request url. - * The request url may be like this dubbo://127.0.0.1:20880/com.a.eye.skywalking.plugin.test.Test.test(String). + * Format request url. + * e.g. dubbo://127.0.0.1:20880/com.a.eye.skywalking.plugin.test.Test.test(String). * * @return request url. */ - private static String generateRequestURL(URL url, Invocation invocation) { + private String generateRequestURL(URL url, Invocation invocation) { StringBuilder requestURL = new StringBuilder(); requestURL.append(url.getProtocol() + "://"); requestURL.append(url.getHost()); @@ -168,28 +155,28 @@ public class DubboInterceptor implements InstanceMethodsAroundInterceptor { } /** - * Set the serialized context data to the first request param that extend {@link SWBaseBean} of dubbo service. + * Set the trace context. * - * @param contextDataStr serialized context data. + * @param contextCarrier {@link ContextCarrier}. */ - private static void fix283SendNoAttachmentIssue(Invocation invocation, String contextDataStr) { + private void fix283SendNoAttachmentIssue(Invocation invocation, ContextCarrier contextCarrier) { for (Object parameter : invocation.getArguments()) { if (parameter instanceof SWBaseBean) { - ((SWBaseBean) parameter).setContextData(contextDataStr); + ((SWBaseBean) parameter).setTraceContext(contextCarrier.serialize()); return; } } } /** - * Fetch the serialize context data from the first request param that extend {@link SWBaseBean} of dubbo service. + * Fetch the trace context by using {@link Invocation#getArguments()}. * - * @return serialized context data. + * @return trace context data. */ - private static String fix283RecvNoAttachmentIssue(Invocation invocation) { + private ContextCarrier fix283RecvNoAttachmentIssue(Invocation invocation) { for (Object parameter : invocation.getArguments()) { if (parameter instanceof SWBaseBean) { - return ((SWBaseBean) parameter).getContextData(); + return new ContextCarrier().deserialize(((SWBaseBean) parameter).getTraceContext()); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java index e09f536b2..937f80279 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/BugFixActive.java @@ -5,7 +5,7 @@ package com.a.eye.skywalking.plugin.dubbox; * The version 2.8.3 of dubbox don't support attachment. so skywalking provided another way * to support the function that transport the serialized context data. The way is that * all parameters of dubbo service need to extend {@link SWBaseBean}, {@link com.a.eye.skywalking.plugin.dubbo.DubboInterceptor} - * fetch the serialized context data by using {@link SWBaseBean#getContextData()}. + * fetch the serialized context data by using {@link SWBaseBean#getTraceContext()}. * * @author zhangxin */ @@ -14,7 +14,7 @@ public final class BugFixActive { private static boolean active = false; /** - * This method should be call first if the dubbo version is below 2.8.3. + * Set active status, before startup dubbo services. */ public static void active() { BugFixActive.active = true; diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java index eaf6f71fe..6fe4bd57e 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/java/com/a/eye/skywalking/plugin/dubbox/SWBaseBean.java @@ -4,21 +4,21 @@ import java.io.Serializable; /** * All the request parameter of dubbox service need to extend {@link SWBaseBean} to transport - * the serialized context data to the provider side if the version of dubbox is below 2.8.3. + * the serialized trace context to the provider side if the version of dubbox is below 2.8.3. * * @author zhangxin */ public class SWBaseBean implements Serializable { /** - * Serialized context data. + * Serialized trace context. */ - private String contextData; + private String traceContext; - public String getContextData() { - return contextData; + public String getTraceContext() { + return traceContext; } - public void setContextData(String contextData) { - this.contextData = contextData; + public void setTraceContext(String traceContext) { + this.traceContext = traceContext; } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/resources/skywalking-plugin.def index 15f3c8eeb..3833d6e87 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/resources/skywalking-plugin.def +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/main/resources/skywalking-plugin.def @@ -1 +1 @@ -com.a.eye.skywalking.plugin.dubbo.DubboPluginDefine +com.a.eye.skywalking.plugin.dubbo.DubboInstrumentation diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java index 7e6cfb214..d964fb79a 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/DubboInterceptorTest.java @@ -156,7 +156,7 @@ public class DubboInterceptorTest { when(rpcContext.isConsumerSide()).thenReturn(false); when(BugFixActive.isActive()).thenReturn(true); - testParam.setContextData("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1"); + testParam.setTraceContext("302017.1487666919810.624424584.17332.1.1|1|REMOTE_APP|127.0.0.1"); dubboInterceptor.beforeMethod(classInstanceContext, methodInvokeContext, methodInterceptResult); diff --git a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java index 7c3783b82..3a0173903 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/dubbo-plugin/src/test/java/com/a/eye/skywalking/plugin/dubbo/RequestParamForTestBelow283.java @@ -12,13 +12,13 @@ import static org.junit.Assert.assertThat; public class RequestParamForTestBelow283 extends SWBaseBean { /** - * This method assert that {@link SWBaseBean#getContextData()} if it's not null and context data + * This method assert that {@link SWBaseBean#getTraceContext()} if it's not null and context data * will end with the expect span id. * * @param expectSpanId expect span id */ public void assertSelf(String expectSpanId, String expectHost) { - assertNotNull(getContextData()); - assertThat(getContextData(), endsWith(expectSpanId + "|" + expectHost)); + assertNotNull(getTraceContext()); + assertThat(getTraceContext(), endsWith(expectSpanId + "|" + expectHost)); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java index 335065b19..860be92f4 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/HttpClientExecuteInterceptor.java @@ -14,10 +14,11 @@ import org.apache.http.Header; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; +import org.apache.http.StatusLine; /** - * {@link HttpClientExecuteInterceptor} create span and set the serialized context - * data to {@link HttpRequest#setHeader(Header)} by using {@link #HEADER_NAME_OF_CONTEXT_DATA} for the header key. + * {@link HttpClientExecuteInterceptor} transport the trace context by call {@link HttpRequest#setHeader(Header)}, + * The current span tag the {@link Tags#ERROR} if {@link StatusLine#getStatusCode()} is not equals 200. * * @author zhangxin */ @@ -48,7 +49,7 @@ public class HttpClientExecuteInterceptor implements InstanceMethodsAroundInterc } /** - * Generate request URL by using {@link HttpRequest} and {@link HttpHost} + * Format request URL. * * @return request URL */ diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java index 5a2a8eb23..2734ca906 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/AbstractHttpClientInstrumentation.java @@ -13,7 +13,7 @@ import org.apache.http.protocol.HttpContext; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link AbstractHttpClientInstrumentation} presents that skywalking will intercept + * {@link AbstractHttpClientInstrumentation} presents that skywalking intercepts * {@link org.apache.http.impl.client.AbstractHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. * @@ -21,9 +21,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named; */ public class AbstractHttpClientInstrumentation extends HttpClientInstrumentation { - /** - * enhance class. - */ private static final String ENHANCE_CLASS = "org.apache.http.impl.client.AbstractHttpClient"; @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java index d0fb67722..4670f0b09 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/DefaultRequestDirectorInstrumentation.java @@ -13,7 +13,7 @@ import org.apache.http.protocol.HttpContext; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link AbstractHttpClientInstrumentation} presents that skywalking will intercept + * {@link AbstractHttpClientInstrumentation} presents that skywalking intercepts * {@link org.apache.http.impl.client.DefaultRequestDirector#execute(HttpHost, HttpRequest, HttpContext)} * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. * diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/HttpClientInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/HttpClientInstrumentation.java index 8d7214427..3649e8c1b 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/HttpClientInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/HttpClientInstrumentation.java @@ -5,16 +5,13 @@ import com.a.eye.skywalking.api.plugin.interceptor.ConstructorInterceptPoint; import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; /** - * {@link HttpClientInstrumentation} present that skywalking will intercept {@link HttpClientInstrumentation#enhanceClassName()} + * {@link HttpClientInstrumentation} present that skywalking intercepts {@link HttpClientInstrumentation#enhanceClassName()} * by using {@link com.a.eye.skywalking.plugin.httpClient.v4.HttpClientExecuteInterceptor} * * @author zhangxin */ public abstract class HttpClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - /** - * Intercept class. - */ private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.httpClient.v4.HttpClientExecuteInterceptor"; @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java index b0ea0c262..8afbc35ac 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/InternalHttpClientInstrumentation.java @@ -13,16 +13,13 @@ import org.apache.http.protocol.HttpContext; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link AbstractHttpClientInstrumentation} presents that skywalking will intercept {@link org.apache.http.impl.client.InternalHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} + * {@link AbstractHttpClientInstrumentation} presents that skywalking intercepts {@link org.apache.http.impl.client.InternalHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. * * @author zhangxin */ public class InternalHttpClientInstrumentation extends HttpClientInstrumentation { - /** - * Enhance class. - */ private static final String ENHANCE_CLASS = "org.apache.http.impl.client.InternalHttpClient"; @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java index 95b98d867..dca1b29cf 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/com/a/eye/skywalking/plugin/httpClient/v4/define/MinimalHttpClientInstrumentation.java @@ -13,17 +13,14 @@ import org.apache.http.protocol.HttpContext; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link AbstractHttpClientInstrumentation} presents that skywalking will - * intercept {@link org.apache.http.impl.client.MinimalHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} + * {@link AbstractHttpClientInstrumentation} presents that skywalking + * intercepts {@link org.apache.http.impl.client.MinimalHttpClient#doExecute(HttpHost, HttpRequest, HttpContext)} * by using {@link HttpClientInstrumentation#INTERCEPT_CLASS}. * * @author zhangxin */ public class MinimalHttpClientInstrumentation extends HttpClientInstrumentation { - /** - * Enhance class. - */ private static final String ENHANCE_CLASS = "org.apache.http.impl.client.MinimalHttpClient"; @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/AbstractConnectionURLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/AbstractURLParser.java similarity index 78% rename from skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/AbstractConnectionURLParser.java rename to skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/AbstractURLParser.java index 1ed4fa846..37afca5c4 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/AbstractConnectionURLParser.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/AbstractURLParser.java @@ -1,18 +1,10 @@ package com.a.eye.skywalking.plugin.jdbc.connectionurl.parser; -/** - * {@link AbstractConnectionURLParser} is abstract class that the class that parse jdbc url. - * - * @author zhangxin - */ -public abstract class AbstractConnectionURLParser implements ConnectionURLParser { +public abstract class AbstractURLParser implements ConnectionURLParser { - /** - * Connection url - */ protected String url; - public AbstractConnectionURLParser(String url) { + public AbstractURLParser(String url) { this.url = url; } @@ -59,7 +51,4 @@ public abstract class AbstractConnectionURLParser implements ConnectionURLParser return url.substring(indexRange[0], indexRange[1]); } - public String getConnectionURL() { - return this.url; - } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java index 0576492ed..78be61a3f 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/ConnectionURLParser.java @@ -5,8 +5,7 @@ import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; public interface ConnectionURLParser { /** - * The class that extend {@link ConnectionURLParser} spilt - * the database name , the database host(s) from connection url. + * {@link ConnectionURLParser} parses database name and the database host(s) from connection url. * * @return connection info. */ diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/H2URLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/H2URLParser.java index 81b992501..55b1ae115 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/H2URLParser.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/H2URLParser.java @@ -17,12 +17,9 @@ import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; * * @author zhangxin */ -public class H2URLParser extends AbstractConnectionURLParser { +public class H2URLParser extends AbstractURLParser { private static final String LOCALHOST = "localhost"; - /** - * Default port that H2 running with mix mode. - */ private static final int DEFAULT_PORT = 8084; /** * Flag that H2 running with file mode. @@ -32,9 +29,6 @@ public class H2URLParser extends AbstractConnectionURLParser { * Flag that H2 running with memory mode. */ private static final String MEMORY_MODE_FLAG = "mem"; - /** - * H2 data type. - */ private static final String H2_DB_TYPE = "H2"; public H2URLParser(String url) { diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/MysqlURLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/MysqlURLParser.java index 604d115ef..d03336374 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/MysqlURLParser.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/MysqlURLParser.java @@ -3,7 +3,7 @@ package com.a.eye.skywalking.plugin.jdbc.connectionurl.parser; import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; /** - * {@link MysqlURLParser} presents that how to parse mysql connection url. + * {@link MysqlURLParser} parse connection url of mysql. * * The {@link ConnectionInfo#host} be set the string between charset "//" and the first * charset "/" after the charset "//", and {@link ConnectionInfo#databaseName} be set the @@ -12,16 +12,10 @@ import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; * * @author zhangxin */ -public class MysqlURLParser extends AbstractConnectionURLParser { +public class MysqlURLParser extends AbstractURLParser { - /** - * Mysql default port. - */ private static final int DEFAULT_PORT = 3306; - /** - * Mysql db type. - */ - private static final String MYSQL_DB_TYPE = "Mysql"; + private static final String DB_TYPE = "Mysql"; public MysqlURLParser(String url) { super(url); @@ -58,13 +52,13 @@ public class MysqlURLParser extends AbstractConnectionURLParser { sb.append(host + ","); } } - return new ConnectionInfo(MYSQL_DB_TYPE, sb.toString(), fetchDatabaseNameFromURL()); + return new ConnectionInfo(DB_TYPE, sb.toString(), fetchDatabaseNameFromURL()); } else { String[] hostAndPort = hostSegment[0].split(":"); if (hostAndPort.length != 1) { - return new ConnectionInfo(MYSQL_DB_TYPE, hostAndPort[0], Integer.valueOf(hostAndPort[1]), fetchDatabaseNameFromURL()); + return new ConnectionInfo(DB_TYPE, hostAndPort[0], Integer.valueOf(hostAndPort[1]), fetchDatabaseNameFromURL()); } else { - return new ConnectionInfo(MYSQL_DB_TYPE, hostAndPort[0], DEFAULT_PORT, fetchDatabaseNameFromURL()); + return new ConnectionInfo(DB_TYPE, hostAndPort[0], DEFAULT_PORT, fetchDatabaseNameFromURL()); } } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/OracleURLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/OracleURLParser.java index eecd7c242..658a975e0 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/OracleURLParser.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/OracleURLParser.java @@ -15,15 +15,9 @@ import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; * * @author zhangxin */ -public class OracleURLParser extends AbstractConnectionURLParser { +public class OracleURLParser extends AbstractURLParser { - /** - * Oracle db type. - */ - private static final String ORACLE_DB_TYPE = "Oracle"; - /** - * Oracle default port - */ + private static final String DB_TYPE = "Oracle"; private static final int DEFAULT_PORT = 1521; public OracleURLParser(String url) { @@ -49,9 +43,9 @@ public class OracleURLParser extends AbstractConnectionURLParser { String[] hostSegment = splitDatabaseAddress(host); String databaseName = url.substring(hostRangeIndex[1] + 1); if (hostSegment.length == 1) { - return new ConnectionInfo(ORACLE_DB_TYPE, host, DEFAULT_PORT, databaseName); + return new ConnectionInfo(DB_TYPE, host, DEFAULT_PORT, databaseName); } else { - return new ConnectionInfo(ORACLE_DB_TYPE, hostSegment[0], Integer.valueOf(hostSegment[1]), databaseName); + return new ConnectionInfo(DB_TYPE, hostSegment[0], Integer.valueOf(hostSegment[1]), databaseName); } } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParser.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParser.java index c6912a8f6..c93fef6c4 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParser.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/connectionurl/parser/URLParser.java @@ -9,13 +9,18 @@ import com.a.eye.skywalking.plugin.jdbc.ConnectionInfo; * @author zhangxin */ public class URLParser { + + private static final String MYSQL_JDBC_URL_PREFIX = "jdbc:mysql"; + private static final String ORACLE_JDBC_URL_PREFIX = "jdbc:oracle"; + private static final String H2_JDBC_URL_PREFIX = "jdbc:h2"; + public static ConnectionInfo parser(String url) { ConnectionURLParser parser = null; - if (url.startsWith("jdbc:mysql")) { + if (url.startsWith(MYSQL_JDBC_URL_PREFIX)) { parser = new MysqlURLParser(url); - } else if (url.startsWith("jdbc:oracle")) { + } else if (url.startsWith(ORACLE_JDBC_URL_PREFIX)) { parser = new OracleURLParser(url); - } else if (url.startsWith("jdbc:h2")) { + } else if (url.startsWith(H2_JDBC_URL_PREFIX)) { parser = new H2URLParser(url); } return parser.parse(); diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabaseInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabaseInstrumentation.java index e9d9e4a9b..6ca54fe34 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabaseInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/AbstractDatabaseInstrumentation.java @@ -13,22 +13,14 @@ import java.util.Properties; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * JDBC plugin using {@link JDBCDriverInterceptor} to intercept all the class that extend {@link java.sql.Driver#connect(String, Properties)}, + * JDBC plugin using {@link JDBCDriverInterceptor} to intercept all the class that it has extend {@link java.sql.Driver#connect(String, Properties)}, * and change the return object to {@link com.a.eye.skywalking.plugin.jdbc.SWConnection}, All the method of {@link com.a.eye.skywalking.plugin.jdbc.SWConnection} - * is delete to the real JDBC Driver Connection object. - * It will return {@link com.a.eye.skywalking.plugin.jdbc.SWStatement} when {@link java.sql.Driver} to create {@link java.sql.Statement}, return - * {@link com.a.eye.skywalking.plugin.jdbc.SWPreparedStatement} when {@link java.sql.Driver} to create {@link java.sql.PreparedStatement} and return - * {@link com.a.eye.skywalking.plugin.jdbc.SWCallableStatement} when {@link java.sql.Driver} to create {@link java.sql.CallableStatement}. - * of course, {@link com.a.eye.skywalking.plugin.jdbc.SWStatement}, {@link com.a.eye.skywalking.plugin.jdbc.SWPreparedStatement} and - * {@link com.a.eye.skywalking.plugin.jdbc.SWCallableStatement} are same as {@link SWConnection}. + * is delegate to the real JDBC Driver Connection object. * * @author zhangxin */ public abstract class AbstractDatabaseInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - /** - * Intercept class - */ private static final String INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jdbc.define.JDBCDriverInterceptor"; @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/H2Instrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/H2Instrumentation.java index 6b44b91fd..2e521b0cc 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/H2Instrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/H2Instrumentation.java @@ -1,15 +1,12 @@ package com.a.eye.skywalking.plugin.jdbc.define; /** - * {@link H2Instrumentation} presents that skywalking will intercept {@link org.h2.Driver}. + * {@link H2Instrumentation} presents that skywalking intercepts {@link org.h2.Driver}. * * @author zhangxin */ public class H2Instrumentation extends AbstractDatabaseInstrumentation { - /** - * Class of intercept H2 driver - */ private static final String CLASS_OF_INTERCEPT_H2_DRIVER = "org.h2.Driver"; @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/JDBCDriverInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/JDBCDriverInterceptor.java index f5439c7b4..41f4c09c1 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/JDBCDriverInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/JDBCDriverInterceptor.java @@ -10,8 +10,8 @@ import java.sql.Connection; import java.util.Properties; /** - * {@link JDBCDriverInterceptor} will return {@link SWConnection} when {@link java.sql.Driver#connect(String, Properties)}, - * instead of the instance that extend {@link Connection}. + * {@link JDBCDriverInterceptor} return {@link SWConnection} when {@link java.sql.Driver} to create connection, + * instead of the {@link Connection} instance. * * @author zhangxin */ diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/MysqlInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/MysqlInstrumentation.java index 568088510..b1d4aca8f 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/MysqlInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/MysqlInstrumentation.java @@ -1,7 +1,7 @@ package com.a.eye.skywalking.plugin.jdbc.define; /** - * {@link MysqlInstrumentation} presents that skywalking will intercept {@link com.mysql.jdbc.Driver}. + * {@link MysqlInstrumentation} presents that skywalking intercepts {@link com.mysql.jdbc.Driver}. * * @author zhangxin */ diff --git a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/OracleInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/OracleInstrumentation.java index 221f114ec..c19bca7ba 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/OracleInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/jdbc-plugin/src/main/java/com/a/eye/skywalking/plugin/jdbc/define/OracleInstrumentation.java @@ -1,7 +1,7 @@ package com.a.eye.skywalking.plugin.jdbc.define; /** - * {@link OracleInstrumentation} presents that skywalking will intercept the class oracle.jdbc.OracleDriver + * {@link OracleInstrumentation} presents that skywalking intercepts the class oracle.jdbc.OracleDriver * . * * @author zhangxin 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 index 8c2ddecd4..c3e9ea38e 100644 --- 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 @@ -8,12 +8,11 @@ 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_HOST; -import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_HOSTS; import static com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor.KEY_OF_REDIS_PORT; /** - * {@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 ;. + * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} record the host and port information from {@link EnhancedClassInstanceContext#context}, + * and each host and port will spilt ;. * * @author zhangxin */ 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 index 1dd91e9ff..aa27d2867 100644 --- 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 @@ -9,8 +9,8 @@ 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 ;. + * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} record the host and port information that fetch + * from {@link EnhancedClassInstanceContext#context}, and each host and port will spilt ;. * * @author zhangxin */ 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 index 6a337c79d..34a9f2ecf 100644 --- 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 @@ -7,8 +7,8 @@ import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorIn import redis.clients.jedis.JedisShardInfo; /** - * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} will record the host and port information that fetch - * from {@link JedisShardInfo} argument into {@link EnhancedClassInstanceContext#context}. + * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} will record the host + * and port information from {@link EnhancedClassInstanceContext#context}. * * @author zhangxin */ 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 index e6d2550f2..d7f28d4b8 100644 --- 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 @@ -5,8 +5,8 @@ import com.a.eye.skywalking.api.plugin.interceptor.enhance.ConstructorInvokeCont 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}. + * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} record the host + * and port information from {@link EnhancedClassInstanceContext#context}. * * @author zhangxin */ 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 index 5bea6db7e..2640949a6 100644 --- 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 @@ -7,8 +7,8 @@ import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceConstructorIn import java.net.URI; /** - * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} will record the host and port information that fetch - * from {@link URI} argument into {@link EnhancedClassInstanceContext#context}. + * {@link JedisClusterConstructorWithHostAndPortArgInterceptor} record the host and port information that fetch + * from {@link EnhancedClassInstanceContext#context}. * * @author zhangxin */ 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 index b31c7f487..e60231f9d 100644 --- 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 @@ -18,35 +18,19 @@ 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 JedisClusterInstrumentation} presents that skywalking intercepts all constructors and methods 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} + * and the other constructor intercept by class {@link JedisClusterConstructorWithListHostAndPortArgInterceptor}. + * {@link JedisMethodInterceptor} 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"; 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 index ee9def3c2..af0401b1d 100644 --- 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 @@ -4,8 +4,8 @@ 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.JedisConstructorWithUriArgInterceptor; import com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor; import net.bytebuddy.description.method.MethodDescription; @@ -20,36 +20,20 @@ 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 JedisInstrumentation} presents that skywalking intercept all constructors and methods 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}. + * ,{@link JedisConstructorWithUriArgInterceptor} intercepts the constructors with uri argument and + * the other constructor intercept by class {@link JedisConstructorWithShardInfoArgInterceptor}. + * {@link JedisMethodInterceptor} 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 diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java index 72f53665b..e3a7e6a42 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java @@ -26,12 +26,12 @@ import com.weibo.api.motan.rpc.URL; public class ProviderInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor { /** - * The key name of request url that stored in {@link EnhancedClassInstanceContext#context} + * The */ private static final String KEY_NAME_OF_REQUEST_URL = "REQUEST_URL"; /** - * The key name that the serialized context data stored in {@link Request#getAttachments()} + * The {@link Request#getAttachments()} key. It maps to the serialized {@link ContextCarrier}. */ private static final String ATTACHMENT_KEY_OF_CONTEXT_DATA = "contextData"; /** diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanConsumerInstrumentation.java similarity index 81% rename from skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java rename to skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanConsumerInstrumentation.java index adef99556..d545f4e94 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ConsumerInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanConsumerInstrumentation.java @@ -6,6 +6,7 @@ import com.a.eye.skywalking.api.plugin.interceptor.enhance.ClassInstanceMethodsE import com.a.eye.skywalking.plugin.motan.ConsumerFetchRequestURLInterceptor; import com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor; import com.weibo.api.motan.rpc.Request; +import com.weibo.api.motan.rpc.URL; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -13,25 +14,19 @@ import net.bytebuddy.matcher.ElementMatcher; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link ConsumerInstrumentation} presents that skywalking use {@link ConsumerInvokeInterceptor} - * to intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} and use + * {@link MotanConsumerInstrumentation} presents that skywalking intercept + * {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} by using {@link ConsumerInvokeInterceptor} and + * intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#setUrl(URL)} by using * {@link ConsumerFetchRequestURLInterceptor} to intercept{@link ConsumerFetchRequestURLInterceptor}. * * @author zhangxin */ -public class ConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { +public class MotanConsumerInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { - /** - * Enhance class. - */ private static final String ENHANCE_CLASS = "com.weibo.api.motan.cluster.support.ClusterSpi"; - /** - * Class that intercept for fetch request url. - */ + private static final String FETCH_REQUEST_URL_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerFetchRequestURLInterceptor"; - /** - * Class that intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)}. - */ + private static final String INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor"; @Override diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanProviderInstrumentation.java similarity index 93% rename from skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java rename to skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanProviderInstrumentation.java index 5a629023b..5e47bbb99 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/ProviderInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanProviderInstrumentation.java @@ -12,14 +12,14 @@ import static net.bytebuddy.matcher.ElementMatchers.any; import static net.bytebuddy.matcher.ElementMatchers.named; /** - * {@link ProviderInstrumentation} presents that skywalking will use + * {@link MotanProviderInstrumentation} presents that skywalking will use * {@link com.a.eye.skywalking.plugin.motan.ProviderInterceptor} to intercept * all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and * {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}. * * @author zhangxin */ -public class ProviderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { +public class MotanProviderInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { /** * Enhance class. diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def index f223bc720..1098cb7c2 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/resources/skywalking-plugin.def @@ -1,2 +1,2 @@ -com.a.eye.skywalking.plugin.motan.define.ConsumerInstrumentation -com.a.eye.skywalking.plugin.motan.define.ProviderInstrumentation +com.a.eye.skywalking.plugin.motan.define.MotanConsumerInstrumentation +com.a.eye.skywalking.plugin.motan.define.MotanProviderInstrumentation diff --git a/skywalking-sniffer/skywalking-sdk-plugin/pom.xml b/skywalking-sniffer/skywalking-sdk-plugin/pom.xml index e1a61be3c..1ec3033ac 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/pom.xml +++ b/skywalking-sniffer/skywalking-sdk-plugin/pom.xml @@ -31,12 +31,12 @@ com.a.eye skywalking-api - 3.0-2017 + ${project.version} com.a.eye skywalking-sniffer-mock - 3.0-2017 + ${project.version} test From eacc014eec6d99a0b646979a19a3099731d0042e Mon Sep 17 00:00:00 2001 From: zhangxin Date: Sat, 25 Feb 2017 17:58:57 +0800 Subject: [PATCH 10/12] update the comment to improve the comment readable --- .../plugin/jedis/v2/JedisMethodInterceptor.java | 9 ++++----- .../plugin/jedis/v2/define/JedisInstrumentation.java | 3 ++- ... => MotanConsumerFetchRequestURLInterceptor.java} | 4 ++-- ...ptor.java => MotanConsumerInvokeInterceptor.java} | 4 ++-- ...nterceptor.java => MotanProviderInterceptor.java} | 4 ++-- .../motan/define/MotanConsumerInstrumentation.java | 12 ++++++------ .../motan/define/MotanProviderInstrumentation.java | 7 ++++--- 7 files changed, 22 insertions(+), 21 deletions(-) rename skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/{ConsumerFetchRequestURLInterceptor.java => MotanConsumerFetchRequestURLInterceptor.java} (87%) rename skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/{ConsumerInvokeInterceptor.java => MotanConsumerInvokeInterceptor.java} (95%) rename skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/{ProviderInterceptor.java => MotanProviderInterceptor.java} (94%) 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 index 59adabd6a..33cc50744 100644 --- 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 @@ -10,8 +10,9 @@ 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. + * {@link JedisMethodInterceptor} intercept all method of {@link redis.clients.jedis.Jedis} + * or {@link redis.clients.jedis.JedisCluster}. {@link JedisMethodInterceptor} record + * the redis host, operation name and the key of the operation. * * @author zhangxin */ @@ -36,9 +37,7 @@ public class JedisMethodInterceptor extends NoCocurrencyAceessObject { * using {@link #KEY_OF_REDIS_HOST} is not null. */ protected static final String KEY_OF_REDIS_PORT = "KEY_OF_REDIS_PORT"; - /** - * Redis component - */ + private static final String REDIS_COMPONENT = "Redis"; 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 index af0401b1d..788bedc93 100644 --- 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 @@ -35,6 +35,7 @@ public class JedisInstrumentation extends ClassInstanceMethodsEnhancePluginDefin private static final String CONSTRUCTOR_WITH_STRING_ARG_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorWithStringArgInterceptor"; private static final String CONSTRUCTOR_WITH_SHARD_INFO_ARG_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorWithShardInfoArgInterceptor"; private static final String CONSTRUCTOR_WITH_URI_ARG_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.jedis.v2.JedisConstructorWithUriArgInterceptor"; + private static final String JEDIS_METHOD_INTERCET_CLASS = "com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor"; @Override public String enhanceClassName() { @@ -94,7 +95,7 @@ public class JedisInstrumentation extends ClassInstanceMethodsEnhancePluginDefin @Override public String getMethodsInterceptor() { - return "com.a.eye.skywalking.plugin.jedis.v2.JedisMethodInterceptor"; + return JEDIS_METHOD_INTERCET_CLASS; } }}; } diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerFetchRequestURLInterceptor.java similarity index 87% rename from skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java rename to skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerFetchRequestURLInterceptor.java index 5a1693763..a1d1b3a5d 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerFetchRequestURLInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerFetchRequestURLInterceptor.java @@ -6,12 +6,12 @@ import com.a.eye.skywalking.api.plugin.interceptor.enhance.InstanceMethodsAround import com.a.eye.skywalking.api.plugin.interceptor.enhance.MethodInterceptResult; /** - * {@link ConsumerFetchRequestURLInterceptor} record {@link com.weibo.api.motan.rpc.URL} to {@link EnhancedClassInstanceContext#context} + * {@link MotanConsumerFetchRequestURLInterceptor} record {@link com.weibo.api.motan.rpc.URL} to {@link EnhancedClassInstanceContext#context} * for the operation name that create span need. * * @author zhangxin */ -public class ConsumerFetchRequestURLInterceptor implements InstanceMethodsAroundInterceptor { +public class MotanConsumerFetchRequestURLInterceptor implements InstanceMethodsAroundInterceptor { private static final String CONTEXT_NAME_OF_REQUEST_URL = "REQUEST_URL"; diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerInvokeInterceptor.java similarity index 95% rename from skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java rename to skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerInvokeInterceptor.java index ce2b845fc..c24b056e2 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ConsumerInvokeInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanConsumerInvokeInterceptor.java @@ -13,13 +13,13 @@ import com.weibo.api.motan.rpc.Response; import com.weibo.api.motan.rpc.URL; /** - * {@link ConsumerInvokeInterceptor} create span by fetch request url from + * {@link MotanConsumerInvokeInterceptor} create span by fetch request url from * {@link EnhancedClassInstanceContext#context} and transport serialized context * data to provider side through {@link Request#setAttachment(String, String)}. * * @author zhangxin */ -public class ConsumerInvokeInterceptor implements InstanceMethodsAroundInterceptor { +public class MotanConsumerInvokeInterceptor implements InstanceMethodsAroundInterceptor { /** * Context name of request url in {@link EnhancedClassInstanceContext#context}. diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptor.java similarity index 94% rename from skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java rename to skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptor.java index e3a7e6a42..bbc66f3a7 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/ProviderInterceptor.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/MotanProviderInterceptor.java @@ -18,12 +18,12 @@ import com.weibo.api.motan.rpc.URL; * Current trace segment will ref the trace segment from previous level if the serialized context data that fetch * from {@link Request#getAttachments()} is not null. * - * {@link ProviderInterceptor} intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} for record + * {@link MotanProviderInterceptor} intercept all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} for record * the request url from consumer side. * * @author zhangxin */ -public class ProviderInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor { +public class MotanProviderInterceptor implements InstanceConstructorInterceptor, InstanceMethodsAroundInterceptor { /** * The diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanConsumerInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanConsumerInstrumentation.java index d545f4e94..b2b0d248b 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanConsumerInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanConsumerInstrumentation.java @@ -3,8 +3,8 @@ package com.a.eye.skywalking.plugin.motan.define; 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.motan.ConsumerFetchRequestURLInterceptor; -import com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor; +import com.a.eye.skywalking.plugin.motan.MotanConsumerFetchRequestURLInterceptor; +import com.a.eye.skywalking.plugin.motan.MotanConsumerInvokeInterceptor; import com.weibo.api.motan.rpc.Request; import com.weibo.api.motan.rpc.URL; @@ -15,9 +15,9 @@ import static net.bytebuddy.matcher.ElementMatchers.named; /** * {@link MotanConsumerInstrumentation} presents that skywalking intercept - * {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} by using {@link ConsumerInvokeInterceptor} and + * {@link com.weibo.api.motan.cluster.support.ClusterSpi#call(Request)} by using {@link MotanConsumerInvokeInterceptor} and * intercept {@link com.weibo.api.motan.cluster.support.ClusterSpi#setUrl(URL)} by using - * {@link ConsumerFetchRequestURLInterceptor} to intercept{@link ConsumerFetchRequestURLInterceptor}. + * {@link MotanConsumerFetchRequestURLInterceptor} to intercept{@link MotanConsumerFetchRequestURLInterceptor}. * * @author zhangxin */ @@ -25,9 +25,9 @@ public class MotanConsumerInstrumentation extends ClassInstanceMethodsEnhancePlu private static final String ENHANCE_CLASS = "com.weibo.api.motan.cluster.support.ClusterSpi"; - private static final String FETCH_REQUEST_URL_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerFetchRequestURLInterceptor"; + private static final String FETCH_REQUEST_URL_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.MotanConsumerFetchRequestURLInterceptor"; - private static final String INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ConsumerInvokeInterceptor"; + private static final String INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.MotanConsumerInvokeInterceptor"; @Override protected String enhanceClassName() { diff --git a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanProviderInstrumentation.java b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanProviderInstrumentation.java index 5e47bbb99..34db6c28e 100644 --- a/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanProviderInstrumentation.java +++ b/skywalking-sniffer/skywalking-sdk-plugin/motan-plugin/src/main/java/com/a/eye/skywalking/plugin/motan/define/MotanProviderInstrumentation.java @@ -3,6 +3,7 @@ package com.a.eye.skywalking.plugin.motan.define; 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.motan.MotanProviderInterceptor; import com.weibo.api.motan.rpc.Request; import net.bytebuddy.description.method.MethodDescription; @@ -13,7 +14,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named; /** * {@link MotanProviderInstrumentation} presents that skywalking will use - * {@link com.a.eye.skywalking.plugin.motan.ProviderInterceptor} to intercept + * {@link MotanProviderInterceptor} to intercept * all constructor of {@link com.weibo.api.motan.rpc.AbstractProvider} and * {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}. * @@ -28,11 +29,11 @@ public class MotanProviderInstrumentation extends ClassInstanceMethodsEnhancePlu /** * Class that intercept all constructor of ${@link com.weibo.api.motan.rpc.AbstractProvider}. */ - private static final String CONSTRUCTOR_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ProviderInterceptor"; + private static final String CONSTRUCTOR_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.MotanProviderInterceptor"; /** * Class that intercept {@link com.weibo.api.motan.rpc.AbstractProvider#call(Request)}. */ - private static final String PROVIDER_INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.ProviderInterceptor"; + private static final String PROVIDER_INVOKE_INTERCEPT_CLASS = "com.a.eye.skywalking.plugin.motan.MotanProviderInterceptor"; @Override protected String enhanceClassName() { From c87cc00787fd75dd0323b79ce7193db2e25c6db9 Mon Sep 17 00:00:00 2001 From: wusheng Date: Sat, 25 Feb 2017 20:12:07 +0800 Subject: [PATCH 11/12] Rename local variable name. --- .../com/a/eye/skywalking/collector/actor/AbstractWorker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/skywalking-collector/skywalking-collector-actor/src/main/java/com/a/eye/skywalking/collector/actor/AbstractWorker.java b/skywalking-collector/skywalking-collector-actor/src/main/java/com/a/eye/skywalking/collector/actor/AbstractWorker.java index 3ec70c2f5..1d442528a 100644 --- a/skywalking-collector/skywalking-collector-actor/src/main/java/com/a/eye/skywalking/collector/actor/AbstractWorker.java +++ b/skywalking-collector/skywalking-collector-actor/src/main/java/com/a/eye/skywalking/collector/actor/AbstractWorker.java @@ -42,8 +42,8 @@ public abstract class AbstractWorker extends UntypedActor { } public void tell(AbstractWorkerProvider targetWorkerProvider, WorkerSelector selector, T message) throws Throwable { - List avaibleWorks = WorkersRefCenter.INSTANCE.availableWorks(targetWorkerProvider.roleName()); - selector.select(avaibleWorks, message).tell(message, getSelf()); + List availableWorks = WorkersRefCenter.INSTANCE.availableWorks(targetWorkerProvider.roleName()); + selector.select(availableWorks, message).tell(message, getSelf()); } void register(Member member) { From 20eeac9504e57edca6ecbbed8811a4af5ec20245 Mon Sep 17 00:00:00 2001 From: wusheng Date: Sat, 25 Feb 2017 22:14:12 +0800 Subject: [PATCH 12/12] Test ci of protobuf --- skywalking-commons/skywalking-trace/pom.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/skywalking-commons/skywalking-trace/pom.xml b/skywalking-commons/skywalking-trace/pom.xml index b6f669f50..59ed8e442 100644 --- a/skywalking-commons/skywalking-trace/pom.xml +++ b/skywalking-commons/skywalking-trace/pom.xml @@ -52,7 +52,7 @@ - src/java/generated-source/protobuf/java + ${basedir}/target/generated-sources/protobuf/java @@ -79,6 +79,8 @@ + +