From 720c4ced6fac215154d980f16e34ab3e9ebc5636 Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 17 Mar 2016 11:26:16 +0800 Subject: [PATCH 1/7] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=99=A8=E5=AE=9E=E4=BE=8B=E5=8C=96=E7=9A=84=E5=88=A4=E6=96=AD?= =?UTF-8?q?=EF=BC=8C#36=E3=80=82=202.httpClient-4.x-plugin=EF=BC=8C?= =?UTF-8?q?=E5=85=A8=E9=9D=A2=E6=94=AF=E6=8C=814.0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E3=80=82=E5=AE=8C=E6=88=904.2=E5=92=8C4.3=E5=B7=AE=E5=BC=82?= =?UTF-8?q?=E5=8C=96API=E6=B5=8B=E8=AF=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interceptor/EnhanceClazz4Interceptor.java | 5 +- .../plugin/interceptor/EnhanceException.java | 13 ++++ .../httpClient-4.x-plugin/pom.xml | 9 +++ .../plugin/HttpClientExecuteInterceptor.java | 6 +- .../AbstractHttpClientPluginDefine.java | 11 +--- .../DefaultRequestDirectorPluginDefine.java | 22 +++++++ .../src/main/resources/skywalking-plugin.def | 3 +- .../v4/plugin/TestHttpClientV42.java | 60 +++++++++++++++++++ 8 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceException.java create mode 100644 skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/DefaultRequestDirectorPluginDefine.java create mode 100644 skywalking-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/httpClient/v4/plugin/TestHttpClientV42.java diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java index 022d62ae5..07b399eb8 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java @@ -50,7 +50,7 @@ public class EnhanceClazz4Interceptor { private void enhance0(String interceptorDefineClassName) throws InstantiationException, IllegalAccessException, - ClassNotFoundException { + ClassNotFoundException, EnhanceException { logger.debug("prepare to enhance class by {}.", interceptorDefineClassName); InterceptorDefine define = (InterceptorDefine) Class.forName( @@ -94,6 +94,9 @@ public class EnhanceClazz4Interceptor { * required by interceptorDefineClass.
*/ IAroundInterceptor interceptor = define.instance(); + if(interceptor == null){ + throw new EnhanceException("no IAroundInterceptor instance. "); + } DynamicType.Builder newClassBuilder = new ByteBuddy().subclass( originClass, ConstructorStrategy.Default.IMITATE_SUPER_CLASS); diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceException.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceException.java new file mode 100644 index 000000000..bdcfb5e9e --- /dev/null +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceException.java @@ -0,0 +1,13 @@ +package com.ai.cloud.skywalking.plugin.interceptor; + +public class EnhanceException extends Exception { + private static final long serialVersionUID = -2234782755784217255L; + + public EnhanceException(String message) { + super(message); + } + + public EnhanceException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml b/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml index 11ed432c3..34ee574de 100644 --- a/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml @@ -23,12 +23,21 @@ 1.0-SNAPSHOT + org.apache.httpcomponents httpclient 4.3 test + org.apache.logging.log4j diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/HttpClientExecuteInterceptor.java b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/HttpClientExecuteInterceptor.java index fc9a12a3f..1c7d4ddd6 100644 --- a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/HttpClientExecuteInterceptor.java +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/HttpClientExecuteInterceptor.java @@ -12,9 +12,9 @@ import com.ai.cloud.skywalking.plugin.interceptor.MethodInvokeContext; public class HttpClientExecuteInterceptor implements IAroundInterceptor { /** - * TODO: need laod from config + * default headname of sky walking context
*/ - public static String traceHearName = ""; + public static String TRACE_HEAD_NAME = "SkyWalking-TRACING-NAME"; private static RPCBuriedPointSender sender = new RPCBuriedPointSender(); @@ -35,7 +35,7 @@ public class HttpClientExecuteInterceptor implements IAroundInterceptor { HttpRequest httpRequest = (HttpRequest) allArguments[1]; httpRequest .setHeader( - traceHearName, + TRACE_HEAD_NAME, "ContextData=" + sender.beforeSend( Identification diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java index 5e601321a..42fca394d 100644 --- a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/AbstractHttpClientPluginDefine.java @@ -1,11 +1,5 @@ package org.skywalking.httpClient.v4.plugin.define; -import io.netty.handler.codec.http.HttpRequest; - -import javax.xml.ws.spi.http.HttpContext; - -import org.apache.http.HttpHost; - import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint; public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine { @@ -20,13 +14,10 @@ public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine { * public final HttpResponse execute(HttpHost target, HttpRequest request, * HttpContext context)
* - * since version 4.3,intercept method: doExecute
*/ @Override public InterceptPoint[] getBeInterceptedMethods() { return new InterceptPoint[] { - new InterceptPoint("doExecute"), - new InterceptPoint("execute", HttpHost.class, - HttpRequest.class, HttpContext.class) }; + new InterceptPoint("doExecute")}; } } diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/DefaultRequestDirectorPluginDefine.java b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/DefaultRequestDirectorPluginDefine.java new file mode 100644 index 000000000..b80c7f309 --- /dev/null +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/java/org/skywalking/httpClient/v4/plugin/define/DefaultRequestDirectorPluginDefine.java @@ -0,0 +1,22 @@ +package org.skywalking.httpClient.v4.plugin.define; + +import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint; + +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 getBeInterceptedClassName() { + return "org.apache.http.impl.client.DefaultRequestDirector"; + } + + @Override + public InterceptPoint[] getBeInterceptedMethods() { + return new InterceptPoint[] { + new InterceptPoint("execute")}; + } + +} diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def index 4c138b961..7840ba779 100644 --- a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/main/resources/skywalking-plugin.def @@ -1,3 +1,4 @@ org.skywalking.httpClient.v4.plugin.define.AbstractHttpClientPluginDefine org.skywalking.httpClient.v4.plugin.define.InternalHttpClientPluginDefine -org.skywalking.httpClient.v4.plugin.define.MinimalHttpClientPluginDefine \ No newline at end of file +org.skywalking.httpClient.v4.plugin.define.MinimalHttpClientPluginDefine +org.skywalking.httpClient.v4.plugin.define.DefaultRequestDirectorPluginDefine \ No newline at end of file diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/httpClient/v4/plugin/TestHttpClientV42.java b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/httpClient/v4/plugin/TestHttpClientV42.java new file mode 100644 index 000000000..7e0dc2d39 --- /dev/null +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/src/test/java/org/skywalking/httpClient/v4/plugin/TestHttpClientV42.java @@ -0,0 +1,60 @@ +package org.skywalking.httpClient.v4.plugin; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; +import java.sql.SQLException; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; +import org.junit.Test; + +import com.ai.cloud.skywalking.plugin.TracingBootstrap; + +public class TestHttpClientV42 { + @Test + public void testsql() throws IllegalAccessException, + IllegalArgumentException, InvocationTargetException, + NoSuchMethodException, SecurityException, ClassNotFoundException { + TracingBootstrap + .main(new String[] { "org.skywalking.httpClient.v4.plugin.TestHttpClientV42" }); + } + + public static void main(String[] args) throws ClassNotFoundException, + SQLException, InterruptedException, ClientProtocolException, IOException { + // 默认的client类。 + HttpClient client = new DefaultHttpClient(); + // 设置为get取连接的方式. + HttpGet get = new HttpGet("http://www.baidu.com"); + // 得到返回的response. + HttpResponse response = client.execute(get); + // 得到返回的client里面的实体对象信息. + HttpEntity entity = response.getEntity(); + if (entity != null) { + System.out.println("内容编码是:" + entity.getContentEncoding()); + System.out.println("内容类型是:" + entity.getContentType()); + // 得到返回的主体内容. + InputStream instream = entity.getContent(); + try { + BufferedReader reader = new BufferedReader( + new InputStreamReader(instream, "UTF-8")); + System.out.println(reader.readLine()); + } catch (Exception e) { + e.printStackTrace(); + } finally { + instream.close(); + } + } + + // 关闭连接. + client.getConnectionManager().shutdown(); + + Thread.sleep(5*1000); + } +} From 8439763610b5100d726f8db4c56f1ba74e05082a Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 17 Mar 2016 14:10:04 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml b/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml index 34ee574de..28bbbc348 100644 --- a/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml +++ b/skywalking-sdk-plugin/httpClient-4.x-plugin/pom.xml @@ -8,9 +8,12 @@ skywalking-sdk-plugin 1.0-SNAPSHOT + skywalking-httpClient-4.x-plugin - skywalking-httpClient-4.x-plugin - http://maven.apache.org + jar + + httpclient-4.x-plugin + http://maven.apache.org UTF-8 From a5802403d53b69a1510b7988ca32ee4964382e40 Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 17 Mar 2016 14:35:24 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E6=8F=92=E4=BB=B6skywalking-httpClient-4.x-plugin-dubbox-rest-?= =?UTF-8?q?attachment=EF=BC=8C=E7=94=A8=E4=BA=8E=E9=80=82=E9=85=8DhttpClie?= =?UTF-8?q?nt-4.x=E6=8F=92=E4=BB=B6=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=B0=83=E7=94=A8dubbox-rest=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E7=9A=84=E6=9C=8D=E5=8A=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/cloud/skywalking/plugin/PluginCfg.java | 1 - .../interceptor/EnhanceClazz4Interceptor.java | 6 ++ skywalking-sdk-plugin/pom.xml | 8 +- .../pom.xml | 79 +++++++++++++++++++ .../DubboxRestHeadSetterAttachment.java | 32 ++++++++ .../src/main/resources/skywalking-plugin.def | 1 + .../rest/attachment/TestHttpClientV43.java | 60 ++++++++++++++ .../src/test/resources/log4j2.xml | 16 ++++ .../src/test/resources/sky-walking.auth | 47 +++++++++++ 9 files changed, 246 insertions(+), 4 deletions(-) create mode 100644 skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/pom.xml create mode 100644 skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/main/java/org/skywalking/httpClient/v4/plugin/dubbox/rest/attachment/DubboxRestHeadSetterAttachment.java create mode 100644 skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/main/resources/skywalking-plugin.def create mode 100644 skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/java/test/skywalking/httpClient/v4x/plugin/dubbox/rest/attachment/TestHttpClientV43.java create mode 100644 skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/resources/log4j2.xml create mode 100644 skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/resources/sky-walking.auth diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/PluginCfg.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/PluginCfg.java index a0ea8cc98..01355211b 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/PluginCfg.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/PluginCfg.java @@ -6,7 +6,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; -import java.util.Set; import com.ai.cloud.skywalking.util.StringUtil; diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java index 07b399eb8..deeabc577 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/plugin/interceptor/EnhanceClazz4Interceptor.java @@ -21,6 +21,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.ai.cloud.skywalking.plugin.PluginCfg; +import com.ai.cloud.skywalking.util.StringUtil; public class EnhanceClazz4Interceptor { private static Logger logger = LogManager @@ -57,6 +58,11 @@ public class EnhanceClazz4Interceptor { interceptorDefineClassName).newInstance(); String enhanceOriginClassName = define.getBeInterceptedClassName(); + if(StringUtil.isEmpty(enhanceOriginClassName)){ + logger.warn("classname of being intercepted is not defined by {}.", + interceptorDefineClassName); + return; + } logger.debug("prepare to enhance class {} by {}.", enhanceOriginClassName, interceptorDefineClassName); diff --git a/skywalking-sdk-plugin/pom.xml b/skywalking-sdk-plugin/pom.xml index 5205d8075..e8c170c98 100644 --- a/skywalking-sdk-plugin/pom.xml +++ b/skywalking-sdk-plugin/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 com.ai.cloud @@ -13,8 +14,9 @@ web-plugin httpclient-4.2.x-plugin httpclient-4.3.x-plugin - httpClient-4.x-plugin - + httpClient-4.x-plugin + httpClient-4.x-plugin-dubbox-rest-attachment + pom skywalking-sdk-plugin diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/pom.xml b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/pom.xml new file mode 100644 index 000000000..b4f389a3d --- /dev/null +++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/pom.xml @@ -0,0 +1,79 @@ + + + 4.0.0 + + com.ai.cloud + skywalking-sdk-plugin + 1.0-SNAPSHOT + + + skywalking-httpClient-4.x-plugin-dubbox-rest-attachment + jar + + httpclient-4.x-plugin + http://maven.apache.org + + + UTF-8 + + + + + com.ai.cloud + skywalking-httpClient-4.x-plugin + 1.0-SNAPSHOT + compile + + + + + org.apache.httpcomponents + httpclient + 4.3 + test + + + + + org.apache.logging.log4j + log4j-core + 2.4.1 + test + + + + junit + junit + 4.12 + test + + + + + + maven-compiler-plugin + + 1.7 + 1.7 + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-resources-plugin + 2.4.3 + + ${project.build.sourceEncoding} + + + + + diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/main/java/org/skywalking/httpClient/v4/plugin/dubbox/rest/attachment/DubboxRestHeadSetterAttachment.java b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/main/java/org/skywalking/httpClient/v4/plugin/dubbox/rest/attachment/DubboxRestHeadSetterAttachment.java new file mode 100644 index 000000000..6f46e7cf6 --- /dev/null +++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/main/java/org/skywalking/httpClient/v4/plugin/dubbox/rest/attachment/DubboxRestHeadSetterAttachment.java @@ -0,0 +1,32 @@ +package org.skywalking.httpClient.v4.plugin.dubbox.rest.attachment; + +import org.skywalking.httpClient.v4.plugin.HttpClientExecuteInterceptor; + +import com.ai.cloud.skywalking.plugin.interceptor.IAroundInterceptor; +import com.ai.cloud.skywalking.plugin.interceptor.InterceptPoint; +import com.ai.cloud.skywalking.plugin.interceptor.InterceptorDefine; + +public class DubboxRestHeadSetterAttachment implements InterceptorDefine { + + /** + * this method is called as InterceptorDefine
+ * don't return be intercepted classname,
+ * just run as a pre setter of attribute:HttpClientExecuteInterceptor.TRACE_HEAD_NAME + */ + @Override + public String getBeInterceptedClassName() { + HttpClientExecuteInterceptor.TRACE_HEAD_NAME = "Dubbo-Attachments"; + return null; + } + + @Override + public InterceptPoint[] getBeInterceptedMethods() { + return null; + } + + @Override + public IAroundInterceptor instance() { + return null; + } + +} diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/main/resources/skywalking-plugin.def b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/main/resources/skywalking-plugin.def new file mode 100644 index 000000000..fbb5519f6 --- /dev/null +++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/main/resources/skywalking-plugin.def @@ -0,0 +1 @@ +org.skywalking.httpClient.v4.plugin.dubbox.rest.attachment.DubboxRestHeadSetterAttachment \ No newline at end of file diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/java/test/skywalking/httpClient/v4x/plugin/dubbox/rest/attachment/TestHttpClientV43.java b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/java/test/skywalking/httpClient/v4x/plugin/dubbox/rest/attachment/TestHttpClientV43.java new file mode 100644 index 000000000..ab4bfc609 --- /dev/null +++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/java/test/skywalking/httpClient/v4x/plugin/dubbox/rest/attachment/TestHttpClientV43.java @@ -0,0 +1,60 @@ +package test.skywalking.httpClient.v4x.plugin.dubbox.rest.attachment; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.sql.SQLException; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.util.EntityUtils; +import org.junit.Test; + +import com.ai.cloud.skywalking.plugin.TracingBootstrap; + +public class TestHttpClientV43 { + @Test + public void testsql() throws IllegalAccessException, + IllegalArgumentException, InvocationTargetException, + NoSuchMethodException, SecurityException, ClassNotFoundException { + TracingBootstrap + .main(new String[] { "test.skywalking.httpClient.v4x.plugin.dubbox.rest.attachment.TestHttpClientV43" }); + } + + public static void main(String[] args) throws ClassNotFoundException, + SQLException, InterruptedException { + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + // HttpClient + CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); + + HttpGet httpGet = new HttpGet("http://www.baidu.com"); + System.out.println(httpGet.getRequestLine()); + try { + // 执行get请求 + HttpResponse httpResponse = closeableHttpClient.execute(httpGet); + // 获取响应消息实体 + HttpEntity entity = httpResponse.getEntity(); + // 响应状态 + System.out.println("status:" + httpResponse.getStatusLine()); + // 判断响应实体是否为空 + if (entity != null) { + System.out.println("contentEncoding:" + + entity.getContentEncoding()); + System.out.println("response content:" + + EntityUtils.toString(entity)); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { // 关闭流并释放资源 + closeableHttpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + Thread.sleep(5*1000); + } +} diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/resources/log4j2.xml b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/resources/log4j2.xml new file mode 100644 index 000000000..4e2af7485 --- /dev/null +++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/resources/log4j2.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/resources/sky-walking.auth b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/resources/sky-walking.auth new file mode 100644 index 000000000..c794ea37c --- /dev/null +++ b/skywalking-sdk-plugin/skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/src/test/resources/sky-walking.auth @@ -0,0 +1,47 @@ +#skyWalking用户ID +skywalking.user_id=123 +#skyWalking应用编码 +skywalking.application_code=test +#skywalking auth的环境变量名字 +skywalking.auth_system_env_name=SKYWALKING_RUN +#skywalking数据编码 +skywalking.charset=UTF-8 + +#是否打印数据 +buriedpoint.printf=true +#埋点异常的最大长度 +buriedpoint.max_exception_stack_length=4000 +#业务字段的最大长度 +buriedpoint.businesskey_max_length=300 +#过滤异常 +buriedpoint.exclusive_exceptions=java.lang.RuntimeException + +#最大发送者的连接数阀比例 +sender.connect_percent=100 +#发送服务端配置 +sender.servers_addr=127.0.0.1:34000 +#最大发送的副本数量 +sender.max_copy_num=2 +#发送的最大长度 +sender.max_send_length=20000 +#当没有Sender时,尝试获取sender的等待周期 +sender.retry_get_sender_wait_interval=2000 +#是否开启发送消息 +sender.is_off=false + + +#最大消费线程数 +consumer.max_consumer=2 +#消费者最大等待时间 +consumer.max_wait_time=5 +#发送失败等待时间 +consumer.consumer_fail_retry_wait_interval=50 + +#每个Buffer的最大个数 +buffer.buffer_max_size=18000 +#Buffer池的最大长度 +buffer.pool_size=5 + +#发送检查线程检查周期 +senderchecker.check_polling_time=200 + From a0f1f2c89c0a17446005c7b82ce619d527070638 Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 17 Mar 2016 14:41:22 +0800 Subject: [PATCH 4/7] no message --- BUILD_DOC.md | 115 ++++++++++++++++++++++++++++++++++++++++++ README.md | 137 +++++---------------------------------------------- 2 files changed, 127 insertions(+), 125 deletions(-) create mode 100644 BUILD_DOC.md diff --git a/BUILD_DOC.md b/BUILD_DOC.md new file mode 100644 index 000000000..751324624 --- /dev/null +++ b/BUILD_DOC.md @@ -0,0 +1,115 @@ +### 部署第三方软件 +- JDK 1.7 +- 安装zookeeper 3.4.6 +- 安装apache hbase 1.1.2 +- 安装mysql +- 安装tomcat 7 +- redis-3.0.5 + +### 编译安装SkyWalking Server +- 编译工程 +```shell +$cd github/sky-walking/skywalking-server +$mvn package -Dmaven.test.skip=true +$cd github/sky-walking/skywalking-server/target/installer +``` +- 拷贝installer到服务器 +- 根据服务器环境修改/config/config.properties +```properties +#服务器收集数据监听端口 +server.port=34000 + +#数据缓存文件目录,请确保此目录有一定的存储容量 +buffer.data_buffer_file_parent_directory=D:/test-data/data/buffer +#偏移量注册文件的目录,这里为系统绝对路径 +registerpersistence.register_file_parent_directory=d:/test-data/data/offset + +#hbase zk quorum,hbase的zk地址 +hbaseconfig.zk_hostname=10.1.235.197,10.1.235.198,10.1.235.199 +#hbase zk port,hbase的zk使用端口 +hbaseconfig.client_port=29181 + +#告警数据暂存的Redis配置 +alarm.redis_server=10.1.241.18:16379 +``` +- 启动服务 +```shell +$cd installer/bin +$./swserver.sh +``` +- 可根据需要部署多个实例 +- 启动服务前,请注意hbase的客户端使用机器名而非ip连接主机,请在server所在机器上正确配置hosts文件,否则会造成数据无法入库 + +### 编译安装SkyWalking Alarm +- 编译工程 +```shell +$cd github/sky-walking/skywalking-alarm +$mvn package -Dmaven.test.skip=true +$cd github/sky-walking/skywalking-alarm/target/installer +``` +- 拷贝installer到服务器 +- 根据服务器环境修改/config/config.properties +```properties +#zookeeper连接地址,用于协调集群,可以和hbase的zookeeper共用 +zkpath.connect_str=10.1.241.18:29181,10.1.241.19:29181,10.1.241.20:29181 + +#管理数据库的JDBC连接信息 +#数据库连接地址 +db.url=jdbc:mysql://10.1.241.20:31306/sw_db +#数据库用户名 +db.user_name=sw_dbusr01 +#数据库密码 +db.password=sw_dbusr01 + +#告警信息存在的redis服务器地址,需要和skywalking-server的alarm.redis_server设置一致 +alarm.redis_server=127.0.0.1:6379 +``` +- 启动服务 +```shell +$cd installer/bin +$./sw-alarm-server.sh +``` +- 可根据需要部署多个实例,根据实例启动数量,自动负载均衡 + +### 编译安装SkyWalking WebUI +- 修改配置文件config.properties +```properties +#hbase的连接地址 +hbaseconfig.quorum=10.1.235.197,10.1.235.198,10.1.235.199 +hbaseconfig.client_port=29181 +``` +- 修改配置文件jdbc.properties +```properties +#管理数据库的JDBC连接信息 +jdbc.url=jdbc:mysql://10.1.228.202:31316/test +jdbc.username=devrdbusr21 +jdbc.password=devrdbusr21 +``` +- 编译工程 +```shell +$cd github/sky-walking/skywalking-webui +$mvn package +``` +- 初始化管理数据库 +根据[数据库脚本](https://github.com/wu-sheng/sky-walking/blob/master/skywalking-webui/src/main/sql/table.mysql)初始化管理数据库。其中,脚本中如下SQL片段需要修改: +```sql +--配置告警邮件的发送人和SMTP信息 +INSERT INTO `system_config` (`config_id`,`conf_key`,`conf_value`,`val_type`,`val_desc`,`create_time`,`sts`,`modify_time`) VALUES (1000,'mail_info','{\"mail.host\":\"mail.asiainfo.com\",\"mail.transport.protocol\":\"smtp\",\"mail.smtp.auth\":\"true\",\"mail.smtp.starttls.enable\":\"false\",\"mail.username\":\"testA\",\"mail.password\":\"******\",\"mail.account.prefix\":\"@asiainfo.com\"}','json','默认邮件发送人信息','2015-12-10 11:54:06','A','2015-12-10 11:54:06'); +--配置部署页面地址,用于告警邮件内的链接 +INSERT INTO `system_config` (`config_id`,`conf_key`,`conf_value`,`val_type`,`val_desc`,`create_time`,`sts`,`modify_time`) VALUES (1001,'portal_addr','http://10.1.235.197:48080/skywalking/','string','默认门户地址','2015-12-10 15:23:53','A','2015-12-10 15:23:53'); +--配置SkyWalking Server的集群地址(内网地址) +INSERT INTO `system_config` (`config_id`,`conf_key`,`conf_value`,`val_type`,`val_desc`,`create_time`,`sts`,`modify_time`) VALUES (1002,'servers_addr','10.1.235.197:34000;10.1.235.197:35000;','string','日志采集地址','2015-12-10 15:23:53','A','2015-12-10 15:23:53'); +--配置SkyWalking Server的集群地址(外网地址) +INSERT INTO `system_config` (`config_id`,`conf_key`,`conf_value`,`val_type`,`val_desc`,`create_time`,`sts`,`modify_time`) VALUES (1003,'servers_addr_1','60.194.3.183:34000;60.194.3.183:35000;60.194.3.184:34000;60.194.3.184:35000;','string','日志采集地址-外网','2015-12-10 15:23:53','A','2015-12-10 15:23:53'); +``` +- 上传war包到服务器,启动Tomcat服务器 + +### 编译安装SkyWalking Analysis +暂未提供 + +## 使用maven发布各插件工程 +- 发布skywalking-sdk-plugin下的各子工程(dubbo-plugin,spring-plugin,web-plugin,jdbc-plugin,httpclient-4.2.x-plugin,httpclient-4.3.x-plugin) +- 请跳过maven.test环节,避免打包失败 +```properties +-Dmaven.test.skip=true +``` \ No newline at end of file diff --git a/README.md b/README.md index 982d01e5d..4ad33245a 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,17 @@ SkyWalking: Large-Scale Distributed Systems Tracing Infrastructure, 是一个对 * 支持国内常用的dubbo以及dubbox等常见RPC框架,支持应用异常的邮件告警 * 通过[byte-buddy](https://github.com/raphw/byte-buddy),部分插件将通过动态字节码机制,避免代码侵入性,完成监控。 -|插件名称|配置文件支持|动态代码机制|代码侵入| -| ----------- |---------| ----------|----------| -|web-plugin|web.xml| - | - | -|dubbo-plugin| dubbo/dubbox配置文件 | - | - | -|spring-plugin| spring配置文件 | - | - | -|jdbc-plugin| jdbc配置文件 | - | - | -|mysql-plugin| - | YES | - | -|httpClient-4.x-plugin| - | YES | - | -|httpclient-4.2.x-plugin| - | - | YES | -|httpclient-4.3.x-plugin| - | - | YES | +|插件名称|配置文件支持|动态代码机制|代码侵入模式|备注| +| ----------- |---------| ----------|----------|----------| +|web-plugin|web.xml| - | - | - | +|dubbo-plugin| dubbo/dubbox配置文件 | - | - | - | +|spring-plugin| spring配置文件 | - | - | - | +|jdbc-plugin| jdbc配置文件 | - | - | - | +|mysql-plugin| - | YES | - | - | +|httpClient-4.x-plugin| - | YES | - | - +|httpClient-4.x-plugin-dubbox-rest-attachment| - | YES | - | 需引用httpClient-4.x-plugin | +|httpclient-4.2.x-plugin| - | - | YES | 需要使用新提供的httpClient包装对象 | +|httpclient-4.3.x-plugin| - | - | YES | 需要使用新提供的httpClient包装对象 | # 新版本能力规划 * 提供一定的日志数据分析和展现能力,减少或者避免使用团队的二次开发 @@ -46,121 +47,7 @@ SkyWalking: Large-Scale Distributed Systems Tracing Infrastructure, 是一个对 # Quick Start ## 编译与部署 -### 部署第三方软件 -- JDK 1.7 -- 安装zookeeper 3.4.6 -- 安装apache hbase 1.1.2 -- 安装mysql -- 安装tomcat 7 -- redis-3.0.5 - -### 编译安装SkyWalking Server -- 编译工程 -```shell -$cd github/sky-walking/skywalking-server -$mvn package -Dmaven.test.skip=true -$cd github/sky-walking/skywalking-server/target/installer -``` -- 拷贝installer到服务器 -- 根据服务器环境修改/config/config.properties -```properties -#服务器收集数据监听端口 -server.port=34000 - -#数据缓存文件目录,请确保此目录有一定的存储容量 -buffer.data_buffer_file_parent_directory=D:/test-data/data/buffer -#偏移量注册文件的目录,这里为系统绝对路径 -registerpersistence.register_file_parent_directory=d:/test-data/data/offset - -#hbase zk quorum,hbase的zk地址 -hbaseconfig.zk_hostname=10.1.235.197,10.1.235.198,10.1.235.199 -#hbase zk port,hbase的zk使用端口 -hbaseconfig.client_port=29181 - -#告警数据暂存的Redis配置 -alarm.redis_server=10.1.241.18:16379 -``` -- 启动服务 -```shell -$cd installer/bin -$./swserver.sh -``` -- 可根据需要部署多个实例 -- 启动服务前,请注意hbase的客户端使用机器名而非ip连接主机,请在server所在机器上正确配置hosts文件,否则会造成数据无法入库 - -### 编译安装SkyWalking Alarm -- 编译工程 -```shell -$cd github/sky-walking/skywalking-alarm -$mvn package -Dmaven.test.skip=true -$cd github/sky-walking/skywalking-alarm/target/installer -``` -- 拷贝installer到服务器 -- 根据服务器环境修改/config/config.properties -```properties -#zookeeper连接地址,用于协调集群,可以和hbase的zookeeper共用 -zkpath.connect_str=10.1.241.18:29181,10.1.241.19:29181,10.1.241.20:29181 - -#管理数据库的JDBC连接信息 -#数据库连接地址 -db.url=jdbc:mysql://10.1.241.20:31306/sw_db -#数据库用户名 -db.user_name=sw_dbusr01 -#数据库密码 -db.password=sw_dbusr01 - -#告警信息存在的redis服务器地址,需要和skywalking-server的alarm.redis_server设置一致 -alarm.redis_server=127.0.0.1:6379 -``` -- 启动服务 -```shell -$cd installer/bin -$./sw-alarm-server.sh -``` -- 可根据需要部署多个实例,根据实例启动数量,自动负载均衡 - -### 编译安装SkyWalking WebUI -- 修改配置文件config.properties -```properties -#hbase的连接地址 -hbaseconfig.quorum=10.1.235.197,10.1.235.198,10.1.235.199 -hbaseconfig.client_port=29181 -``` -- 修改配置文件jdbc.properties -```properties -#管理数据库的JDBC连接信息 -jdbc.url=jdbc:mysql://10.1.228.202:31316/test -jdbc.username=devrdbusr21 -jdbc.password=devrdbusr21 -``` -- 编译工程 -```shell -$cd github/sky-walking/skywalking-webui -$mvn package -``` -- 初始化管理数据库 -根据[数据库脚本](https://github.com/wu-sheng/sky-walking/blob/master/skywalking-webui/src/main/sql/table.mysql)初始化管理数据库。其中,脚本中如下SQL片段需要修改: -```sql ---配置告警邮件的发送人和SMTP信息 -INSERT INTO `system_config` (`config_id`,`conf_key`,`conf_value`,`val_type`,`val_desc`,`create_time`,`sts`,`modify_time`) VALUES (1000,'mail_info','{\"mail.host\":\"mail.asiainfo.com\",\"mail.transport.protocol\":\"smtp\",\"mail.smtp.auth\":\"true\",\"mail.smtp.starttls.enable\":\"false\",\"mail.username\":\"testA\",\"mail.password\":\"******\",\"mail.account.prefix\":\"@asiainfo.com\"}','json','默认邮件发送人信息','2015-12-10 11:54:06','A','2015-12-10 11:54:06'); ---配置部署页面地址,用于告警邮件内的链接 -INSERT INTO `system_config` (`config_id`,`conf_key`,`conf_value`,`val_type`,`val_desc`,`create_time`,`sts`,`modify_time`) VALUES (1001,'portal_addr','http://10.1.235.197:48080/skywalking/','string','默认门户地址','2015-12-10 15:23:53','A','2015-12-10 15:23:53'); ---配置SkyWalking Server的集群地址(内网地址) -INSERT INTO `system_config` (`config_id`,`conf_key`,`conf_value`,`val_type`,`val_desc`,`create_time`,`sts`,`modify_time`) VALUES (1002,'servers_addr','10.1.235.197:34000;10.1.235.197:35000;','string','日志采集地址','2015-12-10 15:23:53','A','2015-12-10 15:23:53'); ---配置SkyWalking Server的集群地址(外网地址) -INSERT INTO `system_config` (`config_id`,`conf_key`,`conf_value`,`val_type`,`val_desc`,`create_time`,`sts`,`modify_time`) VALUES (1003,'servers_addr_1','60.194.3.183:34000;60.194.3.183:35000;60.194.3.184:34000;60.194.3.184:35000;','string','日志采集地址-外网','2015-12-10 15:23:53','A','2015-12-10 15:23:53'); -``` -- 上传war包到服务器,启动Tomcat服务器 - -### 编译安装SkyWalking Analysis -暂未提供 - -## 使用maven发布各插件工程 -- 发布skywalking-sdk-plugin下的各子工程(dubbo-plugin,spring-plugin,web-plugin,jdbc-plugin,httpclient-4.2.x-plugin,httpclient-4.3.x-plugin) -- 请跳过maven.test环节,避免打包失败 -```properties --Dmaven.test.skip=true -``` +- 参考[代码编译部署说明](BUILD_DOC.md) ## 引入核心SDK 无论试用哪种插件,都必须引入 From dd087347cf48ab990babe02d2e74a03c856072a8 Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 17 Mar 2016 14:47:31 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=99=9A=E4=B8=8A=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ad33245a..9d34d9524 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,17 @@ SkyWalking: Large-Scale Distributed Systems Tracing Infrastructure, 是一个对
``` +## 使用全新的main class。原main class,以及参数作为参数传入 +```shell +#原进程启动命令: +java com.company.product.Startup arg0 arg1 + +#全新的进程启动命令: +java com.ai.cloud.skywalking.plugin.TracingBootstrap com.company.product.Startup arg0 arg1 +``` + ## 根据所需插件,配置应用程序 -- 参考[SDK用户指南](https://github.com/wu-sheng/sky-walking/tree/master/skywalking-sdk-plugin) +- 参考[SDK用户指南](skywalking-sdk-plugin) - 注意:插件不会引用所需的第三方组件(如Spring、dubbo、dubbox等),请自行引入所需的版本。 From 59fe42672ec02a4dcb28dfb220bc6810dad963cc Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 17 Mar 2016 14:48:41 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d34d9524..5ad844892 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ SkyWalking: Large-Scale Distributed Systems Tracing Infrastructure, 是一个对 # Quick Start ## 编译与部署 -- 参考[代码编译部署说明](BUILD_DOC.md) +- 参考《[代码编译部署说明](BUILD_DOC.md)》 ## 引入核心SDK 无论试用哪种插件,都必须引入 @@ -77,7 +77,7 @@ java com.ai.cloud.skywalking.plugin.TracingBootstrap com.company.product.Startup ``` ## 根据所需插件,配置应用程序 -- 参考[SDK用户指南](skywalking-sdk-plugin) +- 参考《[SDK用户指南](skywalking-sdk-plugin)》 - 注意:插件不会引用所需的第三方组件(如Spring、dubbo、dubbox等),请自行引入所需的版本。 From 194a33c0174cdc5671b1e20f6779a8ac1df1fd76 Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 17 Mar 2016 14:57:18 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9SDK=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E4=B8=BA1.0b?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ai/cloud/skywalking/conf/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Constants.java b/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Constants.java index bd8fe3254..f90d9524f 100644 --- a/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Constants.java +++ b/skywalking-api/src/main/java/com/ai/cloud/skywalking/conf/Constants.java @@ -4,7 +4,7 @@ public class Constants { /** * 务必严格保持两位的version */ - public static String SDK_VERSION = "1.0a2"; + public static String SDK_VERSION = "1.0b"; public static final String HEALTH_DATA_SPILT_PATTERN = "^~";