提交 a5802403 编写于 作者: wu-sheng's avatar wu-sheng

增加新的插件skywalking-httpClient-4.x-plugin-dubbox-rest-attachment,用于适配httpClient-4...

增加新的插件skywalking-httpClient-4.x-plugin-dubbox-rest-attachment,用于适配httpClient-4.x插件,用于支持调用dubbox-rest模式提供的服务。
上级 84397636
......@@ -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;
......
......@@ -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);
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ai.cloud</groupId>
......@@ -13,8 +14,9 @@
<module>web-plugin</module>
<module>httpclient-4.2.x-plugin</module>
<module>httpclient-4.3.x-plugin</module>
<module>httpClient-4.x-plugin</module>
</modules>
<module>httpClient-4.x-plugin</module>
<module>httpClient-4.x-plugin-dubbox-rest-attachment</module>
</modules>
<packaging>pom</packaging>
<name>skywalking-sdk-plugin</name>
......
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ai.cloud</groupId>
<artifactId>skywalking-sdk-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>skywalking-httpClient-4.x-plugin-dubbox-rest-attachment</artifactId>
<packaging>jar</packaging>
<name>httpclient-4.x-plugin</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.ai.cloud</groupId>
<artifactId>skywalking-httpClient-4.x-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3</version>
<scope>test</scope>
</dependency>
<!--
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2</version>
<scope>test</scope>
</dependency>
-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
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<br/>
* don't return be intercepted classname, <br/>
* 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;
}
}
org.skywalking.httpClient.v4.plugin.dubbox.rest.attachment.DubboxRestHeadSetterAttachment
\ No newline at end of file
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);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t](%F:%L) %-5level %logger{36} - %msg%n" />
</Console>
<Console name="Console2" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t](%F:%L) %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
\ No newline at end of file
#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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册