From a5802403d53b69a1510b7988ca32ee4964382e40 Mon Sep 17 00:00:00 2001 From: wusheng Date: Thu, 17 Mar 2016 14:35:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84=E6=8F=92?= =?UTF-8?q?=E4=BB=B6skywalking-httpClient-4.x-plugin-dubbox-rest-attachmen?= =?UTF-8?q?t=EF=BC=8C=E7=94=A8=E4=BA=8E=E9=80=82=E9=85=8DhttpClient-4.x?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=EF=BC=8C=E7=94=A8=E4=BA=8E=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E7=94=A8dubbox-rest=E6=A8=A1=E5=BC=8F=E6=8F=90?= =?UTF-8?q?=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 +