提交 e564c840 编写于 作者: A ascrutae

Merge remote-tracking branch 'origin/master'

......@@ -39,11 +39,6 @@
<artifactId>skywalking-httpClient-4.x-plugin</artifactId>
<version>1.0-Final</version>
</dependency>
<dependency>
<groupId>com.ai.cloud</groupId>
<artifactId>skywalking-httpClient-4.x-plugin-dubbox-rest-attachment</artifactId>
<version>1.0-Final</version>
</dependency>
<dependency>
<groupId>com.ai.cloud</groupId>
<artifactId>skywalking-dubbo-plugin</artifactId>
......
package com.ai.cloud.skywalking.plugin.interceptor;
import static com.ai.cloud.skywalking.plugin.PluginBootstrap.CLASS_TYPE_POOL;
import com.ai.cloud.skywalking.logging.LogManager;
import com.ai.cloud.skywalking.logging.Logger;
import com.ai.cloud.skywalking.plugin.IPlugin;
import com.ai.cloud.skywalking.plugin.PluginException;
import com.ai.cloud.skywalking.util.StringUtil;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.ClassFileLocator;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.pool.TypePool.Resolution;
import com.ai.cloud.skywalking.plugin.IPlugin;
import com.ai.cloud.skywalking.plugin.PluginException;
import com.ai.cloud.skywalking.util.StringUtil;
import static com.ai.cloud.skywalking.plugin.PluginBootstrap.CLASS_TYPE_POOL;
public abstract class AbstractClassEnhancePluginDefine implements IPlugin {
private static Logger logger = LogManager.getLogger(AbstractClassEnhancePluginDefine.class);
@Override
public void define() throws PluginException {
String interceptorDefineClassName = this.getClass().getName();
String enhanceOriginClassName = getBeInterceptedClassName();
private static Logger logger = LogManager.getLogger(AbstractClassEnhancePluginDefine.class);
@Override
public void define() throws PluginException {
String interceptorDefineClassName = this.getClass().getName();
String enhanceOriginClassName = enhanceClassName();
if (StringUtil.isEmpty(enhanceOriginClassName)) {
logger.warn("classname of being intercepted is not defined by {}.",
interceptorDefineClassName);
......@@ -38,13 +37,27 @@ public abstract class AbstractClassEnhancePluginDefine implements IPlugin {
return;
}
/**
* find witness classes for enhance class
*/
String[] witnessClasses = witnessClasses();
if(witnessClasses != null) {
for (String witnessClass : witnessClasses) {
Resolution witnessClassResolution = CLASS_TYPE_POOL.describe(witnessClass);
if (!witnessClassResolution.isResolved()) {
logger.warn("enhance class {} by plugin {} is not working. Because witness class {} is not existed.", enhanceOriginClassName, interceptorDefineClassName, witnessClass);
return;
}
}
}
/**
* find origin class source code for interceptor
*/
DynamicType.Builder<?> newClassBuilder = new ByteBuddy()
.rebase(resolution.resolve(),
ClassFileLocator.ForClassLoader.ofClassPath());
newClassBuilder = this.enhance(enhanceOriginClassName, newClassBuilder);
/**
......@@ -59,14 +72,24 @@ public abstract class AbstractClassEnhancePluginDefine implements IPlugin {
logger.debug("enhance class {} by {} completely.",
enhanceOriginClassName, interceptorDefineClassName);
}
protected abstract DynamicType.Builder<?> enhance(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException;
}
protected abstract DynamicType.Builder<?> enhance(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException;
/**
* 返回要被增强的类,应当返回类全名
*
* @return
*/
protected abstract String enhanceClassName();
/**
* 返回要被增强的类,应当返回类全名
*
* @return
*/
protected abstract String getBeInterceptedClassName();
/**
* 返回一个类名的列表
* 如果列表中的类在JVM中存在,则enhance可以会尝试生效
*
* @return
*/
protected String[] witnessClasses(){
return new String[]{};
}
}
......@@ -10,7 +10,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.PrivateMethodMatcher;
*/
public class TestMatcherDefine extends ClassInstanceMethodsEnhancePluginDefine {
@Override
public String getBeInterceptedClassName() {
public String enhanceClassName() {
return "test.ai.cloud.matcher.TestMatcherClass";
}
......
......@@ -9,7 +9,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
public class TestInterceptorDefine extends ClassEnhancePluginDefine {
@Override
public String getBeInterceptedClassName() {
public String enhanceClassName() {
return "test.ai.cloud.plugin.BeInterceptedClass";
}
......
<?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-Final</version>
</parent>
<artifactId>skywalking-httpClient-4.x-plugin-dubbox-rest-attachment</artifactId>
<packaging>jar</packaging>
<name>httpClient-4.x-plugin-dubbox-rest-attachment</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-Final</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>
<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>
<distributionManagement>
<repository>
<id>bintray-wu-sheng-sky-walking-repository</id>
<name>wu-sheng-sky-walking-repository</name>
<url>https://api.bintray.com/maven/wu-sheng/skywalking/com.ai.cloud.skywalking-httpClient-4.x-plugin-dubbox-rest-attachment/;publish=1</url>
</repository>
</distributionManagement>
</project>
<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>
<parent>
<groupId>com.ai.cloud</groupId>
<artifactId>skywalking-log</artifactId>
<version>1.0-Final</version>
</parent>
<artifactId>logback-plugin</artifactId>
<name>logback-plugin</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.ai.cloud</groupId>
<artifactId>skywalking-api</artifactId>
<version>1.0-Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<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>
<distributionManagement>
<repository>
<id>bintray-wu-sheng-sky-walking-repository</id>
<name>wu-sheng-sky-walking-repository</name>
<url>https://api.bintray.com/maven/wu-sheng/skywalking/com.ai.cloud.skywalking-log4j-1.x-plugin/;publish=1</url>
</repository>
</distributionManagement>
</project>
\ No newline at end of file
package com.ai.cloud.skywalking.plugin.log.logback;
import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.ai.cloud.skywalking.api.Tracing;
import com.ai.cloud.skywalking.conf.AuthDesc;
/**
*
* @author yushuqiang
*
*/
public class LogbackPatternConverter extends ClassicConverter {
@Override
public String convert(ILoggingEvent event) {
if (AuthDesc.isAuth()) {
return "TID:" + Tracing.getTraceId();
}
return "TID: N/A";
}
}
\ No newline at end of file
package com.ai.cloud.skywalking.plugin.log.logback;
import ch.qos.logback.classic.PatternLayout;
/**
*
* @author yushuqiang
*
*/
public class TraceIdPatternLogbackLayout extends PatternLayout {
static {
defaultConverterMap.put("tid",LogbackPatternConverter.class.getName());
}
}
\ No newline at end of file
package com.ai;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
public class LogbackMain {
static Logger logger = LoggerFactory.getLogger(LogbackMain.class);
public static void main(String[] args) throws JoranException {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.reset();
configurator.doConfigure("E:\\testdubbo\\sky-walking\\skywalking-collector\\skywalking-log\\logback-plugin\\src\\test\\resources\\logback.xml");
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
logger.info("Hello world11");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<!-- 日志输出格式 -->
<layout class="com.ai.cloud.skywalking.plugin.log.logback.TraceIdPatternLogbackLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%tid] [%thread] %-5level %logger{36} -%msg%n</Pattern>
</layout>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
\ No newline at end of file
......@@ -17,7 +17,7 @@ public class DubboPluginDefine extends ClassStaticMethodsEnhancePluginDefine {
}
@Override
protected String getBeInterceptedClassName() {
protected String enhanceClassName() {
return "com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper";
}
}
# 追踪通过httpClient调用dubbox发布的rest服务?
- 使用httpClient-4.x-plugin插件,[查看](../mysql-plugin)
- 引入所需插件
```xml
<dependency>
<groupId>com.ai.cloud</groupId>
<artifactId>skywalking-httpClient-4.x-plugin-dubbox-rest-attachment</artifactId>
<version>{latest_version}</version>
</dependency>
```
package org.skywalking.httpClient.v4.plugin.dubbox.rest.attachment;
import org.skywalking.httpClient.v4.plugin.HttpClientExecuteInterceptor;
import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher;
import com.ai.cloud.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import com.ai.cloud.skywalking.plugin.interceptor.enhance.IntanceMethodsAroundInterceptor;
public class DubboxRestHeadSetterAttachment extends ClassInstanceMethodsEnhancePluginDefine {
/**
* this method is called as InterceptorPluginDefine<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 MethodMatcher[] getInstanceMethodsMatchers() {
return null;
}
@Override
public IntanceMethodsAroundInterceptor getInstanceMethodsInterceptor() {
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
#最大消费线程数
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
......@@ -6,7 +6,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
public class AbstractHttpClientPluginDefine extends HttpClientPluginDefine {
@Override
public String getBeInterceptedClassName() {
public String enhanceClassName() {
return "org.apache.http.impl.client.AbstractHttpClient";
}
......
......@@ -10,7 +10,7 @@ public class DefaultRequestDirectorPluginDefine extends HttpClientPluginDefine {
* since 4.3, this class is Deprecated.
*/
@Override
public String getBeInterceptedClassName() {
public String enhanceClassName() {
return "org.apache.http.impl.client.DefaultRequestDirector";
}
......
......@@ -10,7 +10,7 @@ public class InternalHttpClientPluginDefine extends HttpClientPluginDefine {
}
@Override
public String getBeInterceptedClassName() {
public String enhanceClassName() {
return "org.apache.http.impl.client.InternalHttpClient";
}
......
......@@ -10,7 +10,7 @@ public class MinimalHttpClientPluginDefine extends HttpClientPluginDefine {
}
@Override
public String getBeInterceptedClassName() {
public String enhanceClassName() {
return "org.apache.http.impl.client.MinimalHttpClient";
}
......
......@@ -9,7 +9,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.AnyMethodsMatcher;
public class JedisClusterPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
@Override
public String getBeInterceptedClassName() {
public String enhanceClassName() {
return "redis.clients.jedis.JedisCluster";
}
......
......@@ -11,7 +11,7 @@ import com.ai.cloud.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
public class JedisPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
@Override
public String getBeInterceptedClassName() {
public String enhanceClassName() {
return "redis.clients.jedis.Jedis";
}
......
......@@ -16,7 +16,6 @@
<module>jdbc-plugin</module>
<module>web-plugin</module>
<module>httpClient-4.x-plugin</module>
<module>httpClient-4.x-plugin-dubbox-rest-attachment</module>
<module>jedis-2.x-plugin</module>
</modules>
<packaging>pom</packaging>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册