on rebuild javaagent.
This commit is contained in:
parent
bf60416eca
commit
c98b41b083
2
pom.xml
2
pom.xml
|
|
@ -11,7 +11,7 @@
|
|||
<module>skywalking-commons</module>
|
||||
<module>skywalking-alarm</module>
|
||||
<!--<module>skywalking-webui</module>-->
|
||||
<!--<module>skywalking-sniffer</module>-->
|
||||
<module>skywalking-sniffer</module>
|
||||
<module>skywalking-storage-center</module>
|
||||
<module>skywalking-opentracing-kit</module>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package com.a.eye.skywalking.logging.api;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/10.
|
||||
*/
|
||||
|
|
@ -16,10 +14,16 @@ public interface ILog {
|
|||
|
||||
void error(String format, Throwable e);
|
||||
|
||||
void error(String format, Object argument, Throwable e);
|
||||
void error(String format, Object arguments, Throwable e);
|
||||
|
||||
boolean isDebugEnable();
|
||||
|
||||
boolean isInfoEnable();
|
||||
|
||||
boolean isWarnEnable();
|
||||
|
||||
boolean isErrorEnable();
|
||||
|
||||
void debug(String format);
|
||||
|
||||
void debug(String format, Object... arguments);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,21 @@ public class NoopLogger implements ILog{
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format) {
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,21 @@ public class Log4j2Logger implements ILog {
|
|||
return logger.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnable() {
|
||||
return logger.isInfoEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnable() {
|
||||
return logger.isWarnEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnable() {
|
||||
return logger.isErrorEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format) {
|
||||
logger.debug(format);
|
||||
|
|
|
|||
|
|
@ -23,11 +23,6 @@
|
|||
<artifactId>skywalking-logging-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-logging-impl-log4j2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ message AckSpan {
|
|||
int32 statusCode = 5;
|
||||
string exceptionStack = 6;
|
||||
string viewpointId = 7;
|
||||
string userId = 8;
|
||||
string applicationId = 9;
|
||||
}
|
||||
|
||||
message RequestSpan {
|
||||
|
|
@ -25,7 +27,7 @@ message RequestSpan {
|
|||
string applicationId = 9;
|
||||
string userId = 10;
|
||||
string bussinessKey = 11;
|
||||
string processNo = 13;
|
||||
int32 processNo = 13;
|
||||
string address = 14;
|
||||
}
|
||||
|
||||
|
|
@ -43,10 +45,10 @@ message Span{
|
|||
string exceptionStack = 7;
|
||||
string spanTypeDesc = 8;
|
||||
string callType = 9;
|
||||
uint32 spanType = 10;
|
||||
int32 spanType = 10;
|
||||
string applicationId = 11;
|
||||
string userId = 12;
|
||||
string businessKey = 13;
|
||||
string processNo = 14;
|
||||
int32 processNo = 14;
|
||||
string address = 15;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,9 @@
|
|||
<module>skywalking-test-api</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<compiler.version>1.6</compiler.version>
|
||||
</properties>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@
|
|||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<shade.package>com.a.eye.skywalking.api.dependencies</shade.package>
|
||||
<premain.class>com.a.eye.skywalking.agent.SkyWalkingAgent</premain.class>
|
||||
<shade.net.bytebuddy.source>net.bytebuddy</shade.net.bytebuddy.source>
|
||||
<shade.net.bytebuddy.target>com.a.eye.skywalking.api.dependencies.net.bytebuddy</shade.net.bytebuddy.target>
|
||||
<shade.io.netty.source>io.netty</shade.io.netty.source>
|
||||
<shade.io.netty.target>com.a.eye.skywalking.api.dependencies.io.netty</shade.io.netty.target>
|
||||
<shade.com.google.gson.source>com.google.gson</shade.com.google.gson.source>
|
||||
<shade.com.google.gson.target>com.a.eye.skywalking.api.dependencies.com.google.gson</shade.com.google.gson.target>
|
||||
<shade.net.bytebuddy.target>${shade.package}.${shade.net.bytebuddy.source}}</shade.net.bytebuddy.target>
|
||||
<!-- disruptor -->
|
||||
<shade.com.lmax.disruptor.source>com.lmax.disruptor</shade.com.lmax.disruptor.source>
|
||||
<shade.com.lmax.disruptor.target>${shade.package}.${shade.com.lmax.disruptor.source}</shade.com.lmax.disruptor.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
|
@ -51,11 +51,6 @@
|
|||
<artifactId>tomcat-7.x-8.x-plugin</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>custom-local-method-interceptor-plugin</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
@ -91,12 +86,8 @@
|
|||
<shadedPattern>${shade.net.bytebuddy.target}</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>${shade.io.netty.source}</pattern>
|
||||
<shadedPattern>${shade.io.netty.target}</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>${shade.com.google.gson.source}</pattern>
|
||||
<shadedPattern>${shade.com.google.gson.target}</shadedPattern>
|
||||
<pattern>${shade.com.lmax.disruptor.source}</pattern>
|
||||
<shadedPattern>${shade.com.lmax.disruptor.target}</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@ package com.a.eye.skywalking.agent;
|
|||
import com.a.eye.skywalking.agent.junction.SkyWalkingEnhanceMatcher;
|
||||
import com.a.eye.skywalking.conf.AuthDesc;
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogResolver;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.plugin.AbstractClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.PluginBootstrap;
|
||||
import com.a.eye.skywalking.plugin.PluginDefineCategory;
|
||||
|
|
@ -24,9 +25,15 @@ import static net.bytebuddy.matcher.ElementMatchers.isInterface;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
public class SkyWalkingAgent {
|
||||
private static Logger logger = LogManager.getLogger(SkyWalkingAgent.class);
|
||||
static{
|
||||
LogManager.setLogResolver(new EasyLogResolver());
|
||||
}
|
||||
|
||||
private static ILog easyLogger;
|
||||
|
||||
public static void premain(String agentArgs, Instrumentation instrumentation) throws PluginException {
|
||||
easyLogger = LogManager.getLogger(SkyWalkingAgent.class);
|
||||
|
||||
initConfig();
|
||||
if (AuthDesc.isAuth()) {
|
||||
final PluginDefineCategory pluginDefineCategory =
|
||||
|
|
@ -53,7 +60,7 @@ public class SkyWalkingAgent {
|
|||
|
||||
@Override
|
||||
public void onError(String typeName, ClassLoader classLoader, JavaModule module, Throwable throwable) {
|
||||
logger.error("Failed to enhance class " + typeName, throwable);
|
||||
easyLogger.error("Failed to enhance class " + typeName, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -88,7 +95,7 @@ public class SkyWalkingAgent {
|
|||
urlString = urlString.substring(urlString.indexOf("file:"), urlString.indexOf('!'));
|
||||
return new File(new URL(urlString).getFile()).getParentFile().getAbsolutePath();
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to init config .", e);
|
||||
easyLogger.error("Failed to init config .", e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,102 +1,121 @@
|
|||
<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>
|
||||
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.a.eye</groupId>
|
||||
<artifactId>skywalking-sniffer</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-sniffer</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>skywalking-api</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<name>skywalking-api</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
<version>1.4.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
<version>1.5.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.0.33.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-network</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lmax</groupId>
|
||||
<artifactId>disruptor</artifactId>
|
||||
<version>3.3.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-registry</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-health-report</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-logging</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lmax</groupId>
|
||||
<artifactId>disruptor</artifactId>
|
||||
<version>3.3.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-test-api</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.6.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.6.5</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>
|
||||
<plugin>
|
||||
<!-- 源码插件 -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<!-- 发布时自动将源码同时发布的配置 -->
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<!-- test dependencies section -->
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-test-api</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>1.6.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>1.6.5</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>
|
||||
<plugin>
|
||||
<!-- 源码插件 -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<!-- 发布时自动将源码同时发布的配置 -->
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -1,125 +0,0 @@
|
|||
package com.a.eye.skywalking.buffer;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.selfexamination.HeathReading;
|
||||
import com.a.eye.skywalking.selfexamination.SDKHealthCollector;
|
||||
import com.a.eye.skywalking.sender.DataSenderFactoryWithBalance;
|
||||
import com.a.eye.skywalking.protocol.common.ISerializable;
|
||||
import com.a.eye.skywalking.protocol.util.AtomicRangeInteger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BufferGroup {
|
||||
private static Logger logger = LogManager.getLogger(BufferGroup.class);
|
||||
private String groupName;
|
||||
//注意: 修改这个变量名,需要修改test-api工程的Config类中的SPAN_ARRAY_FIELD_NAME变量
|
||||
private ISerializable[] dataBuffer = new ISerializable[Config.Buffer.BUFFER_MAX_SIZE];
|
||||
AtomicRangeInteger index = new AtomicRangeInteger(0, Config.Buffer.BUFFER_MAX_SIZE);
|
||||
|
||||
public BufferGroup(String groupName) {
|
||||
this.groupName = groupName;
|
||||
startConsumerWorker();
|
||||
}
|
||||
|
||||
private void startConsumerWorker() {
|
||||
if (Config.Consumer.MAX_CONSUMER > 0) {
|
||||
int step = (int) Math.ceil(Config.Buffer.BUFFER_MAX_SIZE * 1.0 / Config.Consumer.MAX_CONSUMER);
|
||||
int start = 0, end = 0;
|
||||
while (true) {
|
||||
if (end + step >= Config.Buffer.BUFFER_MAX_SIZE) {
|
||||
new ConsumerWorker(start, Config.Buffer.BUFFER_MAX_SIZE).start();
|
||||
break;
|
||||
}
|
||||
end += step;
|
||||
new ConsumerWorker(start, end).start();
|
||||
start = end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void save(ISerializable data) {
|
||||
int i = index.getAndIncrement();
|
||||
if (dataBuffer[i] != null) {
|
||||
logger.warn(
|
||||
"Group[{}] index[{}] data collision, discard old data.",
|
||||
groupName, i);
|
||||
SDKHealthCollector
|
||||
.getCurrentHeathReading("BufferGroup").updateData(HeathReading.WARNING, "BufferGroup index[" + i + "] data collision, data been coverd.");
|
||||
}
|
||||
dataBuffer[i] = data;
|
||||
SDKHealthCollector.getCurrentHeathReading("BufferGroup").updateData(HeathReading.INFO, "save span");
|
||||
}
|
||||
|
||||
class ConsumerWorker extends Thread {
|
||||
private int start = 0;
|
||||
private int end = Config.Buffer.BUFFER_MAX_SIZE;
|
||||
|
||||
private ConsumerWorker(int start, int end) {
|
||||
super("ConsumerWorker");
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.setDaemon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
List<ISerializable> packageData = new ArrayList<ISerializable>();
|
||||
while (true) {
|
||||
boolean bool = false;
|
||||
try {
|
||||
for (int i = start; i < end; i++) {
|
||||
if (dataBuffer[i] == null) {
|
||||
continue;
|
||||
}
|
||||
bool = true;
|
||||
if (packageData.size() >= Config.Sender.MAX_SEND_DATA_SIZE) {
|
||||
while (!DataSenderFactoryWithBalance.getSender()
|
||||
.send(packageData)) {
|
||||
try {
|
||||
Thread.sleep(Config.Consumer.CONSUMER_FAIL_RETRY_WAIT_INTERVAL);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Sleep Failure");
|
||||
}
|
||||
}
|
||||
logger.debug("send buried-point data, size:{}", packageData.size());
|
||||
packageData = new ArrayList<ISerializable>();
|
||||
}
|
||||
|
||||
packageData.add(dataBuffer[i]);
|
||||
dataBuffer[i] = null;
|
||||
}
|
||||
|
||||
if (packageData != null && packageData.size() > 0) {
|
||||
while (!DataSenderFactoryWithBalance.getSender().send(
|
||||
packageData)) {
|
||||
try {
|
||||
Thread.sleep(Config.Consumer.CONSUMER_FAIL_RETRY_WAIT_INTERVAL);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Sleep Failure");
|
||||
}
|
||||
}
|
||||
packageData = new ArrayList<ISerializable>();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("data group running failed", e);
|
||||
}
|
||||
|
||||
if (!bool) {
|
||||
try {
|
||||
Thread.sleep(Config.Consumer.MAX_WAIT_TIME);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Sleep Failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package com.a.eye.skywalking.buffer;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.protocol.common.ISerializable;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 16/7/21.
|
||||
*/
|
||||
class BufferPool {
|
||||
// 注意: 这个变量名如果改变需要改变test-api工程中的Config变量
|
||||
private static BufferGroup[] bufferGroups = new BufferGroup[Config.Buffer.POOL_SIZE];
|
||||
static {
|
||||
for (int i = 0; i < Config.Buffer.POOL_SIZE; i++) {
|
||||
bufferGroups[i] = new BufferGroup("buffer_group-" + i);
|
||||
}
|
||||
}
|
||||
|
||||
public void save(ISerializable data) {
|
||||
bufferGroups[ThreadLocalRandom.current().nextInt(0, Config.Buffer.POOL_SIZE)].save(data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package com.a.eye.skywalking.buffer;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.protocol.common.ISerializable;
|
||||
|
||||
public class ContextBuffer {
|
||||
private static Logger logger = LogManager.getLogger(ContextBuffer.class);
|
||||
|
||||
private static BufferPool pool = new BufferPool();
|
||||
|
||||
private ContextBuffer() {
|
||||
//non
|
||||
}
|
||||
|
||||
public static void save(ISerializable data) {
|
||||
try{
|
||||
pool.save(data);
|
||||
}catch(Throwable t){
|
||||
logger.error("save span error.", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.conf;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import com.a.eye.skywalking.selfexamination.SDKHealthCollector;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -9,8 +9,8 @@ import java.io.FileInputStream;
|
|||
import java.io.InputStream;
|
||||
|
||||
public class AuthDesc {
|
||||
private static Logger logger = LogManager.getLogger(AuthDesc.class);
|
||||
static boolean isAuth = false;
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(AuthDesc.class);
|
||||
static boolean isAuth = false;
|
||||
|
||||
static {
|
||||
InputStream authFileInputStream;
|
||||
|
|
@ -29,7 +29,7 @@ public class AuthDesc {
|
|||
try {
|
||||
return new FileInputStream(Config.SkyWalking.AGENT_BASE_PATH + File.separator + "/sky-walking.auth");
|
||||
} catch (Exception e) {
|
||||
logger.error("Error to fetch auth file input stream.", e);
|
||||
easyLogger.error("Error to fetch auth file input stream.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.conf;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -11,26 +11,26 @@ import java.util.LinkedList;
|
|||
import java.util.Properties;
|
||||
|
||||
public class ConfigInitializer {
|
||||
private static Logger logger = LogManager.getLogger(ConfigInitializer.class);
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(ConfigInitializer.class);
|
||||
|
||||
static void initialize(InputStream inputStream) {
|
||||
if (inputStream == null) {
|
||||
logger.info("Not provide sky-walking certification documents, sky-walking api auto shutdown.");
|
||||
easyLogger.info("Not provide sky-walking certification documents, sky-walking api auto shutdown.");
|
||||
} else {
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
properties.load(inputStream);
|
||||
initNextLevel(properties, Config.class, new ConfigDesc());
|
||||
AuthDesc.isAuth = Boolean.valueOf(System.getenv(Config.SkyWalking.AUTH_SYSTEM_ENV_NAME));
|
||||
logger.info("sky-walking system-env auth : " + AuthDesc.isAuth);
|
||||
easyLogger.info("sky-walking system-env auth : " + AuthDesc.isAuth);
|
||||
if(!AuthDesc.isAuth && Config.SkyWalking.AUTH_OVERRIDE){
|
||||
AuthDesc.isAuth = Config.SkyWalking.AUTH_OVERRIDE;
|
||||
logger.info("sky-walking auth override: " + AuthDesc.isAuth);
|
||||
easyLogger.info("sky-walking auth override: " + AuthDesc.isAuth);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.error("Parsing certification file failed, sky-walking api auto shutdown.", e);
|
||||
easyLogger.error("Parsing certification file failed, sky-walking api auto shutdown.", e);
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to read the certification file, sky-walking api auto shutdown.", e);
|
||||
easyLogger.error("Failed to read the certification file, sky-walking api auto shutdown.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ public class Constants {
|
|||
/**
|
||||
* 务必严格保持两位的version
|
||||
*/
|
||||
public static String SDK_VERSION = "1.0Final";
|
||||
public static int SDK_VERSION = 202016;
|
||||
|
||||
public static final String HEALTH_DATA_SPILT_PATTERN = "^~";
|
||||
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@ package com.a.eye.skywalking.invoke.monitor;
|
|||
|
||||
import com.a.eye.skywalking.buffer.ContextBuffer;
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import com.a.eye.skywalking.conf.AuthDesc;
|
||||
import com.a.eye.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.model.ContextData;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.protocol.AckSpan;
|
||||
import com.a.eye.skywalking.protocol.RequestSpan;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
import com.a.eye.skywalking.protocol.util.BuriedPointMachineUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
|
@ -18,7 +18,7 @@ import java.util.Set;
|
|||
|
||||
public abstract class BaseInvokeMonitor {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(BaseInvokeMonitor.class);
|
||||
private static ILog easyLogger = LogManager.getLogger(BaseInvokeMonitor.class);
|
||||
|
||||
private static String EXCEPTION_SPLIT = ",";
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ public abstract class BaseInvokeMonitor {
|
|||
|
||||
protected ContextData beforeInvoke(Span spanData, Identification id) {
|
||||
if (Config.BuriedPoint.PRINTF) {
|
||||
logger.debug("TraceId:" + spanData.getTraceId() + "\tParentLevelId:" + spanData.getParentLevel()
|
||||
easyLogger.debug("TraceId:" + spanData.getTraceId() + "\tParentLevelId:" + spanData.getParentLevel()
|
||||
+ "\tLevelId:" + spanData.getLevelId() + "\tbusinessKey:" + spanData.getBusinessKey());
|
||||
}
|
||||
|
||||
|
|
@ -52,13 +52,15 @@ public abstract class BaseInvokeMonitor {
|
|||
Span spanData = CurrentThreadSpanStack.pop();
|
||||
|
||||
if (Config.BuriedPoint.PRINTF) {
|
||||
logger.debug("TraceId-ACK:" + spanData.getTraceId() + "\tParentLevelId:" + spanData.getParentLevel()
|
||||
easyLogger.debug("TraceId-ACK:" + spanData.getTraceId() + "\tParentLevelId:" + spanData.getParentLevel()
|
||||
+ "\tLevelId:" + spanData.getLevelId() + "\tbusinessKey:" + spanData.getBusinessKey());
|
||||
}
|
||||
// 生成并保存到缓存
|
||||
AckSpan.Builder ackSpanBuilder = spanData.buildAckSpan(AckSpan.newBuilder());
|
||||
|
||||
ContextBuffer.save(new AckSpan(spanData));
|
||||
} catch (Throwable t) {
|
||||
logger.error(t.getMessage(), t);
|
||||
easyLogger.error(t.getMessage(), t);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +79,7 @@ public abstract class BaseInvokeMonitor {
|
|||
Span span = CurrentThreadSpanStack.peek();
|
||||
span.handleException(th, exclusiveExceptionSet, Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH);
|
||||
} catch (Throwable t) {
|
||||
logger.error(t.getMessage(), t);
|
||||
easyLogger.error(t.getMessage(), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.invoke.monitor;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.model.ContextData;
|
||||
import com.a.eye.skywalking.model.EmptyContextData;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
|
|
@ -11,7 +11,7 @@ import com.a.eye.skywalking.model.Span;
|
|||
|
||||
public class LocalMethodInvokeMonitor extends BaseInvokeMonitor {
|
||||
|
||||
private static Logger logger = LogManager
|
||||
private static ILog logger = LogManager
|
||||
.getLogger(LocalMethodInvokeMonitor.class);
|
||||
|
||||
public ContextData beforeInvoke(Identification id) {
|
||||
|
|
|
|||
|
|
@ -4,20 +4,16 @@ import com.a.eye.skywalking.buffer.ContextBuffer;
|
|||
import com.a.eye.skywalking.conf.AuthDesc;
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.model.ContextData;
|
||||
import com.a.eye.skywalking.model.EmptyContextData;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.model.*;
|
||||
import com.a.eye.skywalking.network.grpc.RequestSpan;
|
||||
import com.a.eye.skywalking.protocol.util.BuriedPointMachineUtil;
|
||||
import com.a.eye.skywalking.protocol.util.ContextGenerator;
|
||||
import com.a.eye.skywalking.protocol.RequestSpan;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.protocol.common.SpanType;
|
||||
|
||||
public class RPCClientInvokeMonitor extends BaseInvokeMonitor {
|
||||
|
||||
private static Logger logger = LogManager
|
||||
private static ILog logger = LogManager
|
||||
.getLogger(RPCClientInvokeMonitor.class);
|
||||
|
||||
public ContextData beforeInvoke(Identification id) {
|
||||
|
|
@ -36,12 +32,14 @@ public class RPCClientInvokeMonitor extends BaseInvokeMonitor {
|
|||
|
||||
CurrentThreadSpanStack.push(spanData);
|
||||
|
||||
RequestSpan requestSpan = RequestSpan.RequestSpanBuilder.newBuilder(CurrentThreadSpanStack.peek())
|
||||
.viewPoint(id.getViewPoint())
|
||||
.spanTypeDesc(id.getSpanTypeDesc())
|
||||
.bussinessKey(id.getBusinessKey())
|
||||
.callType(id.getCallType()).processNo(BuriedPointMachineUtil.getProcessNo())
|
||||
.address(BuriedPointMachineUtil.getHostDesc()).build();
|
||||
Span span = CurrentThreadSpanStack.peek();
|
||||
RequestSpan.Builder requestSpanBuilder = span.buildRequestSpan(RequestSpan.newBuilder());
|
||||
RequestSpan requestSpan = requestSpanBuilder
|
||||
.setViewPointId(id.getViewPoint())
|
||||
.setSpanTypeDesc(id.getSpanTypeDesc())
|
||||
.setBussinessKey(id.getBusinessKey())
|
||||
.setCallType(id.getCallType()).setProcessNo(BuriedPointMachineUtil.getProcessNo())
|
||||
.setAddress(BuriedPointMachineUtil.getHostDesc()).build();
|
||||
|
||||
ContextBuffer.save(requestSpan);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
package com.a.eye.skywalking.invoke.monitor;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.model.ContextData;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.model.SpanType;
|
||||
import com.a.eye.skywalking.protocol.util.ContextGenerator;
|
||||
import com.a.eye.skywalking.conf.AuthDesc;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.protocol.common.SpanType;
|
||||
|
||||
public class RPCServerInvokeMonitor extends BaseInvokeMonitor {
|
||||
|
||||
private static Logger logger = LogManager
|
||||
private static ILog logger = LogManager
|
||||
.getLogger(RPCServerInvokeMonitor.class);
|
||||
|
||||
public void beforeInvoke(ContextData context, Identification id) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.a.eye.skywalking.logging;
|
||||
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogResolver;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/26.
|
||||
*/
|
||||
public class EasyLogResolver implements LogResolver {
|
||||
@Override
|
||||
public ILog getLogger(Class<?> clazz) {
|
||||
return new EasyLogger(clazz);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.a.eye.skywalking.logging;
|
||||
|
||||
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.protocol.util.LoggingUtil;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
|
|
@ -10,12 +11,11 @@ import java.util.Date;
|
|||
/**
|
||||
* Created by xin on 16-6-23.
|
||||
*/
|
||||
public class Logger {
|
||||
public class EasyLogger implements ILog {
|
||||
|
||||
private Class toBeLoggerClass;
|
||||
|
||||
|
||||
public Logger(Class toBeLoggerClass) {
|
||||
public EasyLogger(Class toBeLoggerClass) {
|
||||
this.toBeLoggerClass = toBeLoggerClass;
|
||||
}
|
||||
|
||||
|
|
@ -37,50 +37,7 @@ public class Logger {
|
|||
}
|
||||
|
||||
|
||||
public void error(String message, Throwable e) {
|
||||
logger(ERROR, message, e);
|
||||
}
|
||||
|
||||
public void error(String message) {
|
||||
error(message, null);
|
||||
}
|
||||
|
||||
public void warn(String message, Object... parameters) {
|
||||
String tmpMessage = replaceParameter(message, parameters);
|
||||
logger(WARN, tmpMessage, null);
|
||||
}
|
||||
|
||||
|
||||
public void debug(String message) {
|
||||
logger(DEBUG, message, null);
|
||||
}
|
||||
|
||||
public void debug(Object message) {
|
||||
debug(message.toString());
|
||||
}
|
||||
|
||||
public void info(Object message) {
|
||||
info(message.toString());
|
||||
}
|
||||
|
||||
public void info(String message) {
|
||||
logger(INFO, message, null);
|
||||
}
|
||||
|
||||
public void debug(String message, Object... parameters) {
|
||||
debug(replaceParameter(message, parameters));
|
||||
}
|
||||
|
||||
public void error(String message, Object[] parameters, Throwable throwable) {
|
||||
logger(ERROR, replaceParameter(message, parameters), throwable);
|
||||
}
|
||||
|
||||
public void info(String message, Object paramter) {
|
||||
info(replaceParameter(message, new Object[]{paramter}));
|
||||
}
|
||||
|
||||
|
||||
private String replaceParameter(String message, Object... parameters) {
|
||||
private String replaceParam(String message, Object... parameters) {
|
||||
int startSize = 0;
|
||||
int parametersIndex = 0;
|
||||
int index = -1;
|
||||
|
|
@ -109,4 +66,63 @@ public class Logger {
|
|||
private static final String INFO = "INFO";
|
||||
|
||||
|
||||
@Override
|
||||
public void info(String format) {
|
||||
logger(INFO, format, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String format, Object... arguments) {
|
||||
logger(INFO, replaceParam(INFO, format, arguments), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object... arguments) {
|
||||
logger(WARN, replaceParam(WARN, format, arguments), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String format, Object arguments, Throwable e) {
|
||||
logger(WARN, replaceParam(WARN, format, arguments), e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Throwable e) {
|
||||
logger(ERROR, format, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String format, Object arguments, Throwable e) {
|
||||
logger(ERROR, replaceParam(ERROR, format, arguments), e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWarnEnable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isErrorEnable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format) {
|
||||
logger(DEBUG, format, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(String format, Object... arguments) {
|
||||
logger(DEBUG, replaceParam(DEBUG, format, arguments), null);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package com.a.eye.skywalking.logging;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-23.
|
||||
*/
|
||||
public class LogManager {
|
||||
|
||||
public static Logger getLogger(Class toBeLoggerClass) {
|
||||
return new Logger(toBeLoggerClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package com.a.eye.skywalking.logging;
|
||||
|
||||
/**
|
||||
* Created by xin on 16-6-23.
|
||||
*/
|
||||
public class LoggerManager {
|
||||
|
||||
public static Logger getLog(Class toBeClass) {
|
||||
return new Logger(toBeClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package com.a.eye.skywalking.model;
|
||||
|
||||
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.network.grpc.TraceId;
|
||||
|
||||
public class ContextData {
|
||||
private String traceId;
|
||||
private TraceId traceId;
|
||||
private String parentLevel;
|
||||
private int levelId;
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ public class ContextData {
|
|||
|
||||
}
|
||||
|
||||
public ContextData(String traceId, String parentLevel) {
|
||||
public ContextData(TraceId traceId, String parentLevel) {
|
||||
this.traceId = traceId;
|
||||
this.parentLevel = parentLevel;
|
||||
}
|
||||
|
|
@ -27,14 +27,29 @@ public class ContextData {
|
|||
// 反序列化参数
|
||||
String[] value = contextDataStr.split("-");
|
||||
if (value == null || value.length != 3) {
|
||||
throw new IllegalArgumentException("illegal context data.");
|
||||
throw new IllegalArgumentException("illegal context");
|
||||
}
|
||||
this.traceId = value[0];
|
||||
String traceIdStr = value[0];
|
||||
String[] traceIdSegments = traceIdStr.split(",");
|
||||
if(traceIdSegments == null || traceIdSegments.length != 6){
|
||||
throw new IllegalArgumentException("illegal traceid in context");
|
||||
}
|
||||
TraceId.Builder traceIdBuilder = TraceId.newBuilder();
|
||||
int i = 0;
|
||||
for (String traceIdSegment : traceIdSegments) {
|
||||
try {
|
||||
traceIdBuilder.addSegments(Long.parseLong(traceIdSegment));
|
||||
}catch(NumberFormatException e){
|
||||
throw new IllegalArgumentException("illegal traceid seg[" + i + "] in context", e);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
this.traceId = traceIdBuilder.build();
|
||||
this.parentLevel = value[1].trim();
|
||||
this.levelId = Integer.valueOf(value[2]);
|
||||
}
|
||||
|
||||
public String getTraceId() {
|
||||
public TraceId getTraceId() {
|
||||
return traceId;
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +64,11 @@ public class ContextData {
|
|||
@Override
|
||||
public String toString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(traceId);
|
||||
StringBuilder traceIdBuilder = new StringBuilder();
|
||||
for (Long segment : traceId.getSegmentsList()) {
|
||||
traceIdBuilder.append(segment).append(".");
|
||||
}
|
||||
stringBuilder.append(traceIdBuilder.substring(0, traceIdBuilder.length() - 1));
|
||||
stringBuilder.append("-");
|
||||
if (parentLevel == null || parentLevel.length() == 0) {
|
||||
stringBuilder.append(" ");
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
package com.a.eye.skywalking.model;
|
||||
|
||||
import com.a.eye.skywalking.protocol.common.SpanType;
|
||||
|
||||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
import com.a.eye.skywalking.network.grpc.RequestSpan;
|
||||
import com.a.eye.skywalking.network.grpc.TraceId;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -17,12 +18,12 @@ public class Span {
|
|||
/**
|
||||
* tid,调用链的全局唯一标识
|
||||
*/
|
||||
protected String traceId;
|
||||
protected TraceId traceId;
|
||||
/**
|
||||
* 当前调用链的上级描述<br/>
|
||||
* 如当前序号为:0.1.0时,parentLevel=0.1
|
||||
*/
|
||||
protected String parentLevel;
|
||||
protected String parentLevel;
|
||||
/**
|
||||
* 当前调用链的本机描述<br/>
|
||||
* 如当前序号为:0.1.0时,levelId=0
|
||||
|
|
@ -51,7 +52,7 @@ public class Span {
|
|||
* 节点类型<br/>
|
||||
* 如:RPC Client,RPC Server,Local
|
||||
*/
|
||||
private SpanType spanType = SpanType.LOCAL;
|
||||
private int spanType = SpanType.LOCAL;
|
||||
|
||||
/**
|
||||
* 业务字段<br/>
|
||||
|
|
@ -67,14 +68,14 @@ public class Span {
|
|||
private String userId;
|
||||
private String viewPointId;
|
||||
|
||||
public Span(String traceId, String applicationId, String userId) {
|
||||
public Span(TraceId traceId, String applicationId, String userId) {
|
||||
this.traceId = traceId;
|
||||
this.applicationId = applicationId;
|
||||
this.userId = userId;
|
||||
this.parentLevel = "";
|
||||
}
|
||||
|
||||
public Span(String traceId, String parentLevel, int levelId, String applicationId, String userId) {
|
||||
public Span(TraceId traceId, String parentLevel, int levelId, String applicationId, String userId) {
|
||||
this.traceId = traceId;
|
||||
this.parentLevel = parentLevel;
|
||||
this.levelId = levelId;
|
||||
|
|
@ -82,7 +83,7 @@ public class Span {
|
|||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getTraceId() {
|
||||
public TraceId getTraceId() {
|
||||
return traceId;
|
||||
}
|
||||
|
||||
|
|
@ -122,11 +123,11 @@ public class Span {
|
|||
this.exceptionStack = exceptionStack;
|
||||
}
|
||||
|
||||
public void setSpanType(SpanType spanType) {
|
||||
public void setSpanType(int spanType) {
|
||||
this.spanType = spanType;
|
||||
}
|
||||
|
||||
public SpanType getSpanType() {
|
||||
public int getSpanType() {
|
||||
return spanType;
|
||||
}
|
||||
|
||||
|
|
@ -186,14 +187,26 @@ public class Span {
|
|||
this.userId = userId;
|
||||
}
|
||||
|
||||
|
||||
public void setViewPointId(String viewPointId) {
|
||||
this.viewPointId = viewPointId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getViewPointId() {
|
||||
return viewPointId;
|
||||
}
|
||||
|
||||
public RequestSpan.Builder buildRequestSpan(RequestSpan.Builder builder) {
|
||||
builder.setTraceId(this.traceId).setParentLevel(this.parentLevel).setLevelId(this.levelId).setSpanType(this.spanType).setApplicationId(this.applicationId)
|
||||
.setUserId(this.userId);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public AckSpan.Builder buildAckSpan(AckSpan.Builder builder){
|
||||
builder.setTraceId(this.traceId).setParentLevel(this.parentLevel).setLevelId(this.levelId)
|
||||
.setCost(System.currentTimeMillis() - this.startDate).setStatusCode(this.statusCode)
|
||||
.setExceptionStack(this.exceptionStack).setUserId(this.userId).setApplicationId(this.applicationId)
|
||||
.setViewpointId(this.viewPointId);
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.a.eye.skywalking.model;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/26.
|
||||
*/
|
||||
public interface SpanType {
|
||||
int LOCAL = 0;
|
||||
int RPC_CLIENT = 1;
|
||||
int RPC_SERVER = 2;
|
||||
}
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
package com.a.eye.skywalking.plugin;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.protocol.util.StringUtil;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
import net.bytebuddy.pool.TypePool.Resolution;
|
||||
|
||||
public abstract class AbstractClassEnhancePluginDefine{
|
||||
private static Logger logger = LogManager.getLogger(AbstractClassEnhancePluginDefine.class);
|
||||
private static ILog logger = LogManager.getLogger(AbstractClassEnhancePluginDefine.class);
|
||||
|
||||
public DynamicType.Builder<?> define(String transformClassName, DynamicType.Builder<?> builder) throws PluginException {
|
||||
String interceptorDefineClassName = this.getClass().getName();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.plugin;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import net.bytebuddy.pool.TypePool;
|
||||
|
||||
import java.net.URL;
|
||||
|
|
@ -9,7 +9,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class PluginBootstrap {
|
||||
private static Logger logger = LogManager.getLogger(PluginBootstrap.class);
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(PluginBootstrap.class);
|
||||
|
||||
public static TypePool CLASS_TYPE_POOL = null;
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ public class PluginBootstrap {
|
|||
List<URL> resources = resolver.getResources();
|
||||
|
||||
if (resources == null || resources.size() == 0) {
|
||||
logger.info("no plugin files (skywalking-plugin.properties) found, continue to start application.");
|
||||
easyLogger.info("no plugin files (skywalking-plugin.properties) found, continue to start application.");
|
||||
return new ArrayList<AbstractClassEnhancePluginDefine>();
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ public class PluginBootstrap {
|
|||
try {
|
||||
PluginCfg.CFG.load(pluginUrl.openStream());
|
||||
} catch (Throwable t) {
|
||||
logger.error("plugin [{}] init failure.", new Object[] {pluginUrl}, t);
|
||||
easyLogger.error("plugin [{}] init failure.", new Object[] {pluginUrl}, t);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -37,12 +37,12 @@ public class PluginBootstrap {
|
|||
List<AbstractClassEnhancePluginDefine> plugins = new ArrayList<AbstractClassEnhancePluginDefine>();
|
||||
for (String pluginClassName : pluginClassList) {
|
||||
try {
|
||||
logger.debug("loading plugin class {}.", pluginClassName);
|
||||
easyLogger.debug("loading plugin class {}.", pluginClassName);
|
||||
AbstractClassEnhancePluginDefine plugin =
|
||||
(AbstractClassEnhancePluginDefine) Class.forName(pluginClassName).newInstance();
|
||||
plugins.add(plugin);
|
||||
} catch (Throwable t) {
|
||||
logger.error("loade plugin [{}] failure.", new Object[] {pluginClassName}, t);
|
||||
easyLogger.error("loade plugin [{}] failure.", new Object[] {pluginClassName}, t);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.plugin;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
|
@ -10,7 +10,7 @@ import java.util.Enumeration;
|
|||
import java.util.List;
|
||||
|
||||
public class PluginResourcesResolver {
|
||||
private static Logger logger = LogManager.getLogger(PluginResourcesResolver.class);
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(PluginResourcesResolver.class);
|
||||
|
||||
public List<URL> getResources(){
|
||||
List<URL> cfgUrlPaths = new ArrayList<URL>();
|
||||
|
|
@ -19,18 +19,18 @@ public class PluginResourcesResolver {
|
|||
urls = getDefaultClassLoader().getResources("skywalking-plugin.def");
|
||||
|
||||
if(!urls.hasMoreElements()){
|
||||
logger.info("no plugin files (skywalking-plugin.properties) found");
|
||||
easyLogger.info("no plugin files (skywalking-plugin.properties) found");
|
||||
}
|
||||
|
||||
while(urls.hasMoreElements()){
|
||||
URL pluginUrl = urls.nextElement();
|
||||
cfgUrlPaths.add(pluginUrl);
|
||||
logger.info("find skywalking plugin define in {}", pluginUrl);
|
||||
easyLogger.info("find skywalking plugin define in {}", pluginUrl);
|
||||
}
|
||||
|
||||
return cfgUrlPaths;
|
||||
} catch (IOException e) {
|
||||
logger.error("read resources failure.", e);
|
||||
easyLogger.error("read resources failure.", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.a.eye.skywalking.plugin;
|
|||
|
||||
import com.a.eye.skywalking.conf.AuthDesc;
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.dynamic.ClassFileLocator;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
|
|
@ -21,7 +21,7 @@ import java.util.List;
|
|||
* @author wusheng
|
||||
*/
|
||||
public class TracingBootstrap {
|
||||
private static Logger logger = LogManager.getLogger(TracingBootstrap.class);
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(TracingBootstrap.class);
|
||||
|
||||
private TracingBootstrap() {
|
||||
}
|
||||
|
|
@ -43,14 +43,14 @@ public class TracingBootstrap {
|
|||
PluginBootstrap bootstrap = new PluginBootstrap();
|
||||
plugins = bootstrap.loadPlugins();
|
||||
} catch (Throwable t) {
|
||||
logger.error("PluginBootstrap start failure.", t);
|
||||
easyLogger.error("PluginBootstrap start failure.", t);
|
||||
}
|
||||
|
||||
for (AbstractClassEnhancePluginDefine plugin : plugins) {
|
||||
String enhanceClassName = plugin.enhanceClassName();
|
||||
TypePool.Resolution resolution = TypePool.Default.ofClassPath().describe(enhanceClassName);
|
||||
if (!resolution.isResolved()) {
|
||||
logger.error("Failed to resolve the class " + enhanceClassName);
|
||||
easyLogger.error("Failed to resolve the class " + enhanceClassName);
|
||||
continue;
|
||||
}
|
||||
DynamicType.Builder<?> newClassBuilder =
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.loader.InterceptorInstanceLoader;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
|
|
@ -10,7 +10,7 @@ import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
|||
import net.bytebuddy.implementation.bind.annotation.This;
|
||||
|
||||
public class ClassConstructorInterceptor {
|
||||
private static Logger logger = LogManager
|
||||
private static EasyLogger easyLogger = LogManager
|
||||
.getLogger(ClassConstructorInterceptor.class);
|
||||
|
||||
private String instanceMethodsAroundInterceptorClassName;
|
||||
|
|
@ -34,7 +34,7 @@ public class ClassConstructorInterceptor {
|
|||
allArguments);
|
||||
interceptor.onConstruct(context, interceptorContext);
|
||||
} catch (Throwable t) {
|
||||
logger.error("ClassConstructorInterceptor failue.", t);
|
||||
easyLogger.error("ClassConstructorInterceptor failue.", t);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import static net.bytebuddy.matcher.ElementMatchers.any;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import com.a.eye.skywalking.plugin.AbstractClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.PluginException;
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
|
|
@ -22,7 +22,7 @@ import com.a.eye.skywalking.plugin.interceptor.EnhanceException;
|
|||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
|
||||
public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePluginDefine {
|
||||
private static Logger logger = LogManager
|
||||
private static EasyLogger easyLogger = LogManager
|
||||
.getLogger(ClassEnhancePluginDefine.class);
|
||||
|
||||
public static final String contextAttrName = "_$EnhancedClassInstanceContext";
|
||||
|
|
@ -82,10 +82,10 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
enhanceRules.append("\t" + ruleIdx++ + ". " + methodMatcher + "\n");
|
||||
}
|
||||
logger.debug(enhanceRules);
|
||||
easyLogger.debug(enhanceRules);
|
||||
ElementMatcher.Junction<MethodDescription> matcher = null;
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
logger.debug("enhance class {} instance methods by rule: {}",
|
||||
easyLogger.debug("enhance class {} instance methods by rule: {}",
|
||||
enhanceOriginClassName, methodMatcher);
|
||||
if (matcher == null) {
|
||||
matcher = methodMatcher.buildMatcher();
|
||||
|
|
@ -144,10 +144,10 @@ public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePlugi
|
|||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
enhanceRules.append("\t" + ruleIdx++ + ". " + methodMatcher + "\n");
|
||||
}
|
||||
logger.debug(enhanceRules);
|
||||
easyLogger.debug(enhanceRules);
|
||||
ElementMatcher.Junction<MethodDescription> matcher = null;
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
logger.debug("enhance class {} static methods by rule: {}",
|
||||
easyLogger.debug("enhance class {} static methods by rule: {}",
|
||||
enhanceOriginClassName, methodMatcher);
|
||||
if (matcher == null) {
|
||||
matcher = methodMatcher.buildMatcher();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.loader.InterceptorInstanceLoader;
|
||||
import net.bytebuddy.implementation.bind.annotation.*;
|
||||
|
|
@ -15,7 +15,7 @@ import java.util.concurrent.Callable;
|
|||
* @author wusheng
|
||||
*/
|
||||
public class ClassInstanceMethodsInterceptor {
|
||||
private static Logger logger = LogManager.getLogger(ClassInstanceMethodsInterceptor.class);
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(ClassInstanceMethodsInterceptor.class);
|
||||
|
||||
private String instanceMethodsAroundInterceptorClassName;
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ public class ClassInstanceMethodsInterceptor {
|
|||
try {
|
||||
interceptor.beforeMethod(instanceContext, interceptorContext, result);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] before method[{}] intercept failue:{}", new Object[] {obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
easyLogger.error("class[{}] before method[{}] intercept failue:{}", new Object[] {obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
}
|
||||
|
||||
Object ret = null;
|
||||
|
|
@ -48,14 +48,14 @@ public class ClassInstanceMethodsInterceptor {
|
|||
try {
|
||||
interceptor.handleMethodException(t, instanceContext, interceptorContext);
|
||||
} catch (Throwable t2) {
|
||||
logger.error("class[{}] handle method[{}] exception failue:{}", new Object[] {obj.getClass(), method.getName(), t2.getMessage()}, t2);
|
||||
easyLogger.error("class[{}] handle method[{}] exception failue:{}", new Object[] {obj.getClass(), method.getName(), t2.getMessage()}, t2);
|
||||
}
|
||||
throw t;
|
||||
} finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(instanceContext, interceptorContext, ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] after method[{}] intercept failue:{}", new Object[] {obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
easyLogger.error("class[{}] after method[{}] intercept failue:{}", new Object[] {obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import com.a.eye.skywalking.plugin.interceptor.loader.InterceptorInstanceLoader;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.Origin;
|
||||
|
|
@ -17,7 +17,7 @@ import java.util.concurrent.Callable;
|
|||
* @author wusheng
|
||||
*/
|
||||
public class ClassStaticMethodsInterceptor {
|
||||
private static Logger logger = LogManager.getLogger(ClassStaticMethodsInterceptor.class);
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(ClassStaticMethodsInterceptor.class);
|
||||
|
||||
private String staticMethodsAroundInterceptorClassName;
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ public class ClassStaticMethodsInterceptor {
|
|||
try {
|
||||
interceptor.beforeMethod(interceptorContext, result);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] before static method[{}] intercept failue:{}", new Object[] {clazz, method.getName(), t.getMessage()}, t);
|
||||
easyLogger.error("class[{}] before static method[{}] intercept failue:{}", new Object[] {clazz, method.getName(), t.getMessage()}, t);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -50,14 +50,14 @@ public class ClassStaticMethodsInterceptor {
|
|||
try {
|
||||
interceptor.handleMethodException(t, interceptorContext);
|
||||
} catch (Throwable t2) {
|
||||
logger.error("class[{}] handle static method[{}] exception failue:{}", new Object[] {clazz, method.getName(), t2.getMessage()}, t2);
|
||||
easyLogger.error("class[{}] handle static method[{}] exception failue:{}", new Object[] {clazz, method.getName(), t2.getMessage()}, t2);
|
||||
}
|
||||
throw t;
|
||||
} finally {
|
||||
try {
|
||||
ret = interceptor.afterMethod(interceptorContext, ret);
|
||||
} catch (Throwable t) {
|
||||
logger.error("class[{}] after static method[{}] intercept failue:{}", new Object[] {clazz, method.getName(), t.getMessage()}, t);
|
||||
easyLogger.error("class[{}] after static method[{}] intercept failue:{}", new Object[] {clazz, method.getName(), t.getMessage()}, t);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.plugin.interceptor.loader;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
@ -16,7 +16,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||
* Created by wusheng on 16/8/2.
|
||||
*/
|
||||
public class InterceptorInstanceLoader {
|
||||
private static Logger logger = LogManager.getLogger(InterceptorInstanceLoader.class);
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(InterceptorInstanceLoader.class);
|
||||
|
||||
private static ConcurrentHashMap<String, Object> INSTANCE_CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ public class InterceptorInstanceLoader {
|
|||
BufferedInputStream is = null;
|
||||
ByteArrayOutputStream baos = null;
|
||||
try {
|
||||
logger.debug("Read binary code of {} using classload {}", className, InterceptorInstanceLoader.class.getClassLoader());
|
||||
easyLogger.debug("Read binary code of {} using classload {}", className, InterceptorInstanceLoader.class.getClassLoader());
|
||||
is = new BufferedInputStream(InterceptorInstanceLoader.class.getResourceAsStream(path));
|
||||
baos = new ByteArrayOutputStream();
|
||||
int ch = 0;
|
||||
|
|
@ -81,7 +81,7 @@ public class InterceptorInstanceLoader {
|
|||
}
|
||||
data = baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
easyLogger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
if (is != null)
|
||||
try {
|
||||
|
|
@ -105,7 +105,7 @@ public class InterceptorInstanceLoader {
|
|||
}
|
||||
}
|
||||
defineClassMethod.setAccessible(true);
|
||||
logger.debug("load binary code of {} to classload {}", className, targetClassLoader);
|
||||
easyLogger.debug("load binary code of {} to classload {}", className, targetClassLoader);
|
||||
Class<?> type = (Class<?>) defineClassMethod.invoke(targetClassLoader, className, data, 0, data.length, null);
|
||||
return (T) type.newInstance();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import java.net.InetAddress;
|
|||
import java.net.UnknownHostException;
|
||||
|
||||
public final class BuriedPointMachineUtil {
|
||||
private static String processNo;
|
||||
private static int processNo = -1;
|
||||
private static String IP;
|
||||
private static String hostName;
|
||||
|
||||
|
|
@ -13,10 +13,14 @@ public final class BuriedPointMachineUtil {
|
|||
processNo = getProcessNo();
|
||||
}
|
||||
|
||||
public static String getProcessNo() {
|
||||
if (StringUtil.isEmpty(processNo)) {
|
||||
public static int getProcessNo() {
|
||||
if (processNo != -1) {
|
||||
String name = ManagementFactory.getRuntimeMXBean().getName();
|
||||
processNo = name.split("@")[0];
|
||||
try {
|
||||
processNo = Integer.parseInt(name.split("@")[0]);
|
||||
}catch(Throwable t){
|
||||
processNo = 0;
|
||||
}
|
||||
}
|
||||
return processNo;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,42 +3,41 @@ package com.a.eye.skywalking.protocol.util;
|
|||
import java.util.UUID;
|
||||
|
||||
import com.a.eye.skywalking.conf.Constants;
|
||||
import com.a.eye.skywalking.network.grpc.TraceId;
|
||||
|
||||
public final class TraceIdGenerator {
|
||||
private static final ThreadLocal<Integer> ThreadTraceIdSequence = new ThreadLocal<Integer>();
|
||||
private static final ThreadLocal<Integer> ThreadTraceIdSequence = new ThreadLocal<Integer>();
|
||||
|
||||
private static final String PROCESS_UUID;
|
||||
private static final int PROCESS_UUID;
|
||||
|
||||
static {
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
PROCESS_UUID = uuid.substring(uuid.length() - 7);
|
||||
}
|
||||
static {
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
PROCESS_UUID = uuid.substring(uuid.length() - 7).hashCode();
|
||||
}
|
||||
|
||||
private TraceIdGenerator() {
|
||||
}
|
||||
private TraceIdGenerator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* TraceId由以下规则组成<br/>
|
||||
* 2位version号 + 1位时间戳(毫秒数) + 1位进程随机号(UUID后7位) + 1位进程数号 + 1位线程号 + 1位线程内序号
|
||||
*
|
||||
* 注意:这里的位,是指“.”作为分隔符所占的位数,非字符串长度的位数。
|
||||
* TraceId为不定长字符串,但保证在分布式集群条件下的唯一性
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String generate() {
|
||||
Integer seq = ThreadTraceIdSequence.get();
|
||||
if (seq == null || seq == 10000 || seq > 10000) {
|
||||
seq = 0;
|
||||
}
|
||||
seq++;
|
||||
ThreadTraceIdSequence.set(seq);
|
||||
/**
|
||||
* TraceId由以下规则组成<br/>
|
||||
* version号 + 1位时间戳(毫秒数) + 1位进程随机号(UUID后7位) + 1位进程数号 + 1位线程号 + 1位线程内序号
|
||||
* <p>
|
||||
* 注意:这里的位,是指“.”作为分隔符所占的位数,非字符串长度的位数。
|
||||
* TraceId为6个片段组成的数组
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static TraceId generate() {
|
||||
Integer seq = ThreadTraceIdSequence.get();
|
||||
if (seq == null || seq == 10000 || seq > 10000) {
|
||||
seq = 0;
|
||||
}
|
||||
seq++;
|
||||
ThreadTraceIdSequence.set(seq);
|
||||
|
||||
return Constants.SDK_VERSION
|
||||
+ "." + System.currentTimeMillis()
|
||||
+ "." + PROCESS_UUID
|
||||
+ "." + BuriedPointMachineUtil.getProcessNo()
|
||||
+ "." + Thread.currentThread().getId()
|
||||
+ "." + seq;
|
||||
}
|
||||
return TraceId.newBuilder().addSegments(Constants.SDK_VERSION)
|
||||
.addSegments(System.currentTimeMillis()).addSegments(PROCESS_UUID)
|
||||
.addSegments(BuriedPointMachineUtil.getProcessNo())
|
||||
.addSegments(Thread.currentThread().getId()).addSegments(seq).build();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,72 +0,0 @@
|
|||
package com.a.eye.skywalking.selfexamination;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HeathReading {
|
||||
public static final String ERROR = "[ERROR]";
|
||||
public static final String WARNING = "[WARNING]";
|
||||
public static final String INFO = "[INFO]";
|
||||
|
||||
private String id;
|
||||
|
||||
private Map<String, HeathDetailData> datas = new HashMap<String, HeathDetailData>();
|
||||
|
||||
/**
|
||||
* 健康读数,只应该在工作线程中创建
|
||||
*
|
||||
*/
|
||||
public HeathReading(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void updateData(String key, String newData){
|
||||
if(datas.containsKey(key)){
|
||||
datas.get(key).updateData(newData);
|
||||
}else{
|
||||
datas.put(key, new HeathDetailData(newData));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("id<").append(this.id).append(">\n");
|
||||
for(Map.Entry<String, HeathDetailData> data : datas.entrySet()){
|
||||
sb.append(data.getKey()).append(data.getValue().toString()).append("\n");
|
||||
}
|
||||
|
||||
//reset data
|
||||
datas = new HashMap<String, HeathReading.HeathDetailData>();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
class HeathDetailData{
|
||||
private String data;
|
||||
|
||||
private long statusTime;
|
||||
|
||||
HeathDetailData(String initialData){
|
||||
data = initialData;
|
||||
statusTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
void updateData(String newData){
|
||||
data = newData;
|
||||
statusTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
long getStatusTime() {
|
||||
return statusTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return data + "(t:" + statusTime + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
package com.a.eye.skywalking.selfexamination;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.conf.AuthDesc;
|
||||
import com.a.eye.skywalking.protocol.util.BuriedPointMachineUtil;
|
||||
|
||||
public class SDKHealthCollector extends Thread {
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(SDKHealthCollector.class);
|
||||
|
||||
private static Map<String, HeathReading> heathReadings = new ConcurrentHashMap<String, HeathReading>();
|
||||
|
||||
private SDKHealthCollector() {
|
||||
super("HealthCollector");
|
||||
this.setDaemon(true);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
if (AuthDesc.isAuth()) {
|
||||
new SDKHealthCollector().start();
|
||||
}
|
||||
}
|
||||
|
||||
public static HeathReading getCurrentHeathReading(String extraId) {
|
||||
String id = getId(extraId);
|
||||
if (!heathReadings.containsKey(id)) {
|
||||
synchronized (heathReadings) {
|
||||
if (!heathReadings.containsKey(id)) {
|
||||
if (heathReadings.keySet().size() > 5000) {
|
||||
throw new RuntimeException(
|
||||
"use ServerHealthCollector illegal. There is an overflow trend of SDK Health Collector Report Data.");
|
||||
}
|
||||
heathReadings.put(id, new HeathReading(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
return heathReadings.get(id);
|
||||
}
|
||||
|
||||
private static String getId(String extraId) {
|
||||
return "SDK-API,M:" + BuriedPointMachineUtil.getHostDesc() + ",P:"
|
||||
+ BuriedPointMachineUtil.getProcessNo() + ",T:"
|
||||
+ Thread.currentThread().getName() + "("
|
||||
+ Thread.currentThread().getId() + ")"
|
||||
+ (extraId == null ? "" : ",extra:" + extraId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
Map<String, HeathReading> heathReadingsSnapshot = heathReadings;
|
||||
heathReadings = new ConcurrentHashMap<String, HeathReading>();
|
||||
String[] keyList = heathReadingsSnapshot.keySet().toArray(
|
||||
new String[0]);
|
||||
Arrays.sort(keyList);
|
||||
StringBuilder log = new StringBuilder();
|
||||
log.append("\n---------SDK Health Collector Report---------\n");
|
||||
for (String key : keyList) {
|
||||
log.append(heathReadingsSnapshot.get(key)).append("\n");
|
||||
}
|
||||
log.append("------------------------------------------------\n");
|
||||
|
||||
logger.info(log);
|
||||
|
||||
try {
|
||||
Thread.sleep(Config.HealthCollector.REPORT_INTERVAL);
|
||||
} catch (InterruptedException e) {
|
||||
logger.warn("sleep error.", e);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
logger.error("SDKHealthCollector report error.", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
package com.a.eye.skywalking.sender;
|
||||
|
||||
import com.a.eye.skywalking.selfexamination.HeathReading;
|
||||
import com.a.eye.skywalking.selfexamination.SDKHealthCollector;
|
||||
import com.a.eye.skywalking.protocol.common.ISerializable;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
import io.netty.handler.codec.LengthFieldPrepender;
|
||||
import io.netty.handler.codec.bytes.ByteArrayDecoder;
|
||||
import io.netty.handler.codec.bytes.ByteArrayEncoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
|
||||
import com.a.eye.skywalking.protocol.TransportPackager;
|
||||
|
||||
public class DataSender implements IDataSender {
|
||||
private EventLoopGroup group;
|
||||
private SenderStatus status = SenderStatus.FAILED;
|
||||
private InetSocketAddress socketAddress;
|
||||
private Channel channel;
|
||||
|
||||
public DataSender(String ip, int port) throws IOException {
|
||||
this(new InetSocketAddress(ip, port));
|
||||
}
|
||||
|
||||
public DataSender(InetSocketAddress address) throws IOException {
|
||||
this.socketAddress = address;
|
||||
status = SenderStatus.READY;
|
||||
group = new NioEventLoopGroup();
|
||||
try {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
bootstrap.group(group)
|
||||
.channel(NioSocketChannel.class)
|
||||
.option(ChannelOption.TCP_NODELAY, true)
|
||||
.handler(new ChannelInitializer<SocketChannel>() {
|
||||
@Override
|
||||
protected void initChannel(SocketChannel ch) throws Exception {
|
||||
ChannelPipeline p = ch.pipeline();
|
||||
p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
|
||||
p.addLast("frameEncoder", new LengthFieldPrepender(4));
|
||||
p.addLast("decoder", new ByteArrayDecoder());
|
||||
p.addLast("encoder", new ByteArrayEncoder());
|
||||
p.addLast(new ChannelInboundHandlerAdapter() {
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
channel = ctx.channel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
bootstrap.connect(address).sync();
|
||||
} catch (Exception e) {
|
||||
status = SenderStatus.FAILED;
|
||||
SDKHealthCollector
|
||||
.getCurrentHeathReading("sender").updateData(HeathReading.INFO, "DataSender[" + socketAddress + "] send data successfully.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回是否发送成功
|
||||
*
|
||||
* @param packageData
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean send(List<ISerializable> packageData) {
|
||||
try {
|
||||
if (channel != null && channel.isActive()) {
|
||||
|
||||
byte[] dataPackage = TransportPackager.pack(packageData);
|
||||
channel.writeAndFlush(dataPackage);
|
||||
|
||||
SDKHealthCollector.getCurrentHeathReading("sender").updateData(HeathReading.INFO, "DataSender[" + socketAddress + "] send data successfully.");
|
||||
return true;
|
||||
}else{
|
||||
DataSenderFactoryWithBalance.unRegister(this);
|
||||
SDKHealthCollector.getCurrentHeathReading("sender").updateData(HeathReading.WARNING, "DataSender[" + socketAddress + "] channel isn't active. unregister sender.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
DataSenderFactoryWithBalance.unRegister(this);
|
||||
SDKHealthCollector.getCurrentHeathReading("sender").updateData(HeathReading.WARNING, "DataSender[" + socketAddress + "] channel broken. unregister sender.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public InetSocketAddress getServerAddr() {
|
||||
return this.socketAddress;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (group != null) {
|
||||
group.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
public enum SenderStatus {
|
||||
READY, FAILED
|
||||
}
|
||||
|
||||
public SenderStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(SenderStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,239 +0,0 @@
|
|||
package com.a.eye.skywalking.sender;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.selfexamination.HeathReading;
|
||||
import com.a.eye.skywalking.selfexamination.SDKHealthCollector;
|
||||
import com.a.eye.skywalking.protocol.util.StringUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class DataSenderFactoryWithBalance {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(DataSenderFactoryWithBalance.class);
|
||||
// unUsedServerAddress存放没有使用的服务器地址,
|
||||
private static List<InetSocketAddress> unusedServerAddresses = new ArrayList<InetSocketAddress>();
|
||||
|
||||
private static List<DataSender> usingDataSender = new ArrayList<DataSender>();
|
||||
private static int maxKeepConnectingSenderSize;
|
||||
|
||||
private static int calculateMaxKeeperConnectingSenderSize(int allAddressSize) {
|
||||
if (Config.Sender.CONNECT_PERCENT <= 0 || Config.Sender.CONNECT_PERCENT > 100) {
|
||||
logger.error("CONNECT_PERCENT must between 1 and 100");
|
||||
System.exit(-1);
|
||||
}
|
||||
return (int) Math.ceil(allAddressSize
|
||||
* ((1.0 * Config.Sender.CONNECT_PERCENT / 100) % 100));
|
||||
}
|
||||
|
||||
// 初始化服务端的地址数据
|
||||
static {
|
||||
// 获取数据
|
||||
if (StringUtil.isEmpty(Config.Sender.SERVERS_ADDR)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Collection service configuration error.");
|
||||
}
|
||||
|
||||
// 初始化地址
|
||||
Set<InetSocketAddress> tmpInetSocketAddress = new HashSet<InetSocketAddress>();
|
||||
for (String serverConfig : Config.Sender.SERVERS_ADDR.split(";")) {
|
||||
String[] server = serverConfig.split(":");
|
||||
if (server.length != 2)
|
||||
throw new IllegalArgumentException(
|
||||
"Collection service configuration error.");
|
||||
tmpInetSocketAddress.add(new InetSocketAddress(server[0], Integer
|
||||
.valueOf(server[1])));
|
||||
}
|
||||
|
||||
unusedServerAddresses.addAll(tmpInetSocketAddress);
|
||||
|
||||
// 根据配置的服务器集群的地址,来计算保持连接的Sender的数量
|
||||
maxKeepConnectingSenderSize = calculateMaxKeeperConnectingSenderSize(tmpInetSocketAddress
|
||||
.size());
|
||||
// 最大连接消费线程小于保持连接的Sender的数量,就不需要保持那么多的保持连接的Sender的数量
|
||||
if (maxKeepConnectingSenderSize > Config.Consumer.MAX_CONSUMER
|
||||
* Config.Buffer.POOL_SIZE) {
|
||||
maxKeepConnectingSenderSize = Config.Consumer.MAX_CONSUMER
|
||||
* Config.Buffer.POOL_SIZE;
|
||||
}
|
||||
|
||||
new DataSenderChecker().start();
|
||||
}
|
||||
|
||||
// 获取连接
|
||||
public static IDataSender getSender() {
|
||||
DataSenderWithCopies readySender = new DataSenderWithCopies(maxKeepConnectingSenderSize);
|
||||
while (true) {
|
||||
try {
|
||||
if (usingDataSender.size() > 0) {
|
||||
int index = ThreadLocalRandom.current().nextInt(0,
|
||||
usingDataSender.size());
|
||||
if (usingDataSender.get(index).getStatus() == DataSender.SenderStatus.READY) {
|
||||
while (readySender.append(usingDataSender.get(index))) {
|
||||
if (++index == usingDataSender.size()) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!readySender.isReady()) {
|
||||
try {
|
||||
Thread.sleep(Config.Sender.RETRY_GET_SENDER_WAIT_INTERVAL);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Sleep failed", e);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("get sender failed", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return readySender;
|
||||
}
|
||||
|
||||
// 定时Sender状态检查
|
||||
public static class DataSenderChecker extends Thread {
|
||||
public DataSenderChecker() {
|
||||
super("Data-Sender-Checker");
|
||||
this.setDaemon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long sleepTime = 0;
|
||||
while (true) {
|
||||
try {
|
||||
DataSender newSender;
|
||||
// removing failed sender
|
||||
Iterator<DataSender> senderIterator = usingDataSender
|
||||
.iterator();
|
||||
DataSender tmpDataSender;
|
||||
while (senderIterator.hasNext()) {
|
||||
tmpDataSender = senderIterator.next();
|
||||
if (tmpDataSender.getStatus() == DataSender.SenderStatus.FAILED) {
|
||||
tmpDataSender.close();
|
||||
unusedServerAddresses.add(tmpDataSender
|
||||
.getServerAddr());
|
||||
senderIterator.remove();
|
||||
SDKHealthCollector.getCurrentHeathReading("remove").updateData(HeathReading.INFO, "remove disconnected sender.");
|
||||
}
|
||||
}
|
||||
|
||||
// try to fill up senders. if size is not enough.
|
||||
while (unusedServerAddresses.size() > 0 && usingDataSender.size() < maxKeepConnectingSenderSize) {
|
||||
if ((newSender = findReadySender()) == null) {
|
||||
// no available sender. ignore.
|
||||
break;
|
||||
}
|
||||
usingDataSender.add(newSender);
|
||||
SDKHealthCollector.getCurrentHeathReading("add").updateData(HeathReading.INFO, "add new sender.");
|
||||
}
|
||||
|
||||
// try to switch.
|
||||
if (sleepTime >= Config.Sender.SWITCH_SENDER_INTERVAL && unusedServerAddresses.size() > 0) {
|
||||
// if sender is enough, go to switch for balancing.
|
||||
if (usingDataSender.size() >= maxKeepConnectingSenderSize) {
|
||||
DataSender toBeSwitchSender;
|
||||
DataSender tmpSender;
|
||||
|
||||
int toBeSwitchIndex;
|
||||
|
||||
if (usingDataSender.size() - 1 > 0) {
|
||||
toBeSwitchIndex = ThreadLocalRandom.current()
|
||||
.nextInt(0, usingDataSender.size() - 1);
|
||||
} else {
|
||||
toBeSwitchIndex = 0;
|
||||
}
|
||||
|
||||
toBeSwitchSender = usingDataSender
|
||||
.get(toBeSwitchIndex);
|
||||
tmpSender = findReadySender();
|
||||
if (tmpSender != null) {
|
||||
usingDataSender.set(toBeSwitchIndex, tmpSender);
|
||||
try {
|
||||
Thread.sleep(Config.Sender.CLOSE_SENDER_COUNTDOWN);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Sleep Failed", e);
|
||||
}
|
||||
toBeSwitchSender.close();
|
||||
unusedServerAddresses.remove(tmpSender
|
||||
.getServerAddr());
|
||||
unusedServerAddresses.add(toBeSwitchSender
|
||||
.getServerAddr());
|
||||
SDKHealthCollector.getCurrentHeathReading("switch").updateData(HeathReading.INFO, "switch existed sender.");
|
||||
}
|
||||
}
|
||||
sleepTime = 0;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
SDKHealthCollector.getCurrentHeathReading(null).updateData(HeathReading.ERROR, "DataSenderChecker running failed:" + e.getMessage());
|
||||
logger.error("DataSenderChecker running failed", e);
|
||||
} finally {
|
||||
SDKHealthCollector.getCurrentHeathReading(null).updateData(HeathReading.INFO, "using available DataSender connect to: " + listUsingServers());
|
||||
}
|
||||
|
||||
sleepTime += Config.Sender.CHECKER_THREAD_WAIT_INTERVAL;
|
||||
try {
|
||||
Thread.sleep(Config.Sender.CHECKER_THREAD_WAIT_INTERVAL);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Sleep failed");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static DataSender findReadySender() {
|
||||
DataSender result = null;
|
||||
int index = 0;
|
||||
|
||||
if (unusedServerAddresses.size() > 1) {
|
||||
index = ThreadLocalRandom.current().nextInt(0,
|
||||
unusedServerAddresses.size());
|
||||
}
|
||||
|
||||
for (int i = 0; i < unusedServerAddresses.size(); i++, index++) {
|
||||
|
||||
if (index == unusedServerAddresses.size()) {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
result = new DataSender(unusedServerAddresses.get(index));
|
||||
unusedServerAddresses.remove(index);
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
if (result != null) {
|
||||
result.close();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void unRegister(DataSender socket) {
|
||||
socket.setStatus(DataSender.SenderStatus.FAILED);
|
||||
}
|
||||
|
||||
private static String listUsingServers() {
|
||||
StringBuilder usingAddrDesc = new StringBuilder();
|
||||
if (usingDataSender.size() > 0) {
|
||||
for (DataSender sender : usingDataSender) {
|
||||
if (usingAddrDesc.length() > 0) {
|
||||
usingAddrDesc.append(",");
|
||||
}
|
||||
usingAddrDesc.append(sender.getServerAddr().toString());
|
||||
}
|
||||
}
|
||||
return usingAddrDesc.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
package com.a.eye.skywalking.sender;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.selfexamination.HeathReading;
|
||||
import com.a.eye.skywalking.selfexamination.SDKHealthCollector;
|
||||
import com.a.eye.skywalking.protocol.common.ISerializable;
|
||||
|
||||
/**
|
||||
* 带副本的数据发送器
|
||||
*
|
||||
* @author wusheng
|
||||
*
|
||||
*/
|
||||
public class DataSenderWithCopies implements IDataSender {
|
||||
private int maxCopyNum;
|
||||
|
||||
private Set<IDataSender> senders = new HashSet<IDataSender>();
|
||||
|
||||
public DataSenderWithCopies(int maxKeepConnectingSenderSize) {
|
||||
// 最大副本数量,不能大于可用最大连接数
|
||||
maxCopyNum = maxKeepConnectingSenderSize > Config.Sender.MAX_COPY_NUM ? Config.Sender.MAX_COPY_NUM
|
||||
: maxKeepConnectingSenderSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试增加到最大可用副本数,极端情况可能不足
|
||||
*
|
||||
* @param dataSender
|
||||
* @return
|
||||
*/
|
||||
public boolean append(IDataSender dataSender) {
|
||||
// 出现重复sender,副本到达最大限度
|
||||
if (senders.contains(dataSender)) {
|
||||
return false;
|
||||
}
|
||||
senders.add(dataSender);
|
||||
return senders.size() < maxCopyNum;
|
||||
}
|
||||
|
||||
boolean isReady(){
|
||||
return senders.size() > 0 ;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 尝试向所有副本发送
|
||||
*/
|
||||
public boolean send(List<ISerializable> packageData) {
|
||||
int successNum = 0;
|
||||
for (IDataSender sender : senders) {
|
||||
if (sender.send(packageData)) {
|
||||
successNum++;
|
||||
}
|
||||
}
|
||||
SDKHealthCollector.getCurrentHeathReading("DataSenderWithCopies").updateData(HeathReading.INFO, "DataSender send data with copynum=" + successNum + " successfully.");
|
||||
if (senders.size() == 1 && successNum == 1) {
|
||||
return true;
|
||||
} else if (successNum >= 2) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package com.a.eye.skywalking.sender;
|
||||
|
||||
import com.a.eye.skywalking.protocol.common.ISerializable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IDataSender {
|
||||
public boolean send(List<ISerializable> data);
|
||||
}
|
||||
|
|
@ -2,26 +2,26 @@ package test.a.eye.cloud.logging;
|
|||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LoggingTest {
|
||||
|
||||
Logger logger = LogManager.getLogger(LoggingTest.class);
|
||||
EasyLogger easyLogger = LogManager.getLogger(LoggingTest.class);
|
||||
|
||||
@Test
|
||||
public void testNormalLogging() {
|
||||
logger.debug("Hello World");
|
||||
easyLogger.debug("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorLogging() {
|
||||
logger.error("Hello World", new RuntimeException("Failed message"));
|
||||
easyLogger.error("Hello World", new RuntimeException("Failed message"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFile() {
|
||||
Config.Logging.MAX_LOG_FILE_LENGTH = 2400;
|
||||
logger.error("Hello World", new RuntimeException("Failed message"));
|
||||
easyLogger.error("Hello World", new RuntimeException("Failed message"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
<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">
|
||||
<parent>
|
||||
<artifactId>skywalking-sdk-plugin</artifactId>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<version>2.0-2016</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>custom-local-method-interceptor-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>custom-local-method-interceptor-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
package com.a.eye.skywalking.plugin.custom.localmethod;
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.buffer.ContextBuffer;
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.invoke.monitor.LocalMethodInvokeMonitor;
|
||||
import com.a.eye.skywalking.model.Identification;
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.*;
|
||||
import com.a.eye.skywalking.protocol.InputParametersSpan;
|
||||
import com.a.eye.skywalking.protocol.OutputParameterSpan;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class CustomLocalMethodInterceptor implements InstanceMethodsAroundInterceptor, StaticMethodsAroundInterceptor {
|
||||
|
||||
@Override
|
||||
public void onConstruct(EnhancedClassInstanceContext context, ConstructorInvokeContext interceptorContext) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
MethodInterceptResult result) {
|
||||
Identification.IdentificationBuilder identificationBuilder = Identification.newBuilder();
|
||||
identificationBuilder.spanType(new CustomLocalSpanType()).viewPoint(
|
||||
fullMethodName(interceptorContext.inst().getClass(), interceptorContext.methodName(),
|
||||
interceptorContext.argumentTypes()));
|
||||
|
||||
new LocalMethodInvokeMonitor().beforeInvoke(identificationBuilder.build());
|
||||
|
||||
recordParametersAndSave2BufferIfNecessary(interceptorContext.allArguments());
|
||||
}
|
||||
|
||||
private void recordParametersAndSave2BufferIfNecessary(Object[] arguments) {
|
||||
if (Config.Plugin.CustomLocalMethodInterceptorPlugin.RECORD_PARAM_ENABLE) {
|
||||
InputParametersSpan inputParametersSpan = new InputParametersSpan(Tracing.getTraceId(), Tracing.getTracelevelId());
|
||||
for (Object param : arguments) {
|
||||
String paramStr;
|
||||
try {
|
||||
paramStr = new Gson().toJson(param);
|
||||
} catch (Throwable e) {
|
||||
paramStr = "N/A";
|
||||
}
|
||||
inputParametersSpan.addParameter(paramStr);
|
||||
}
|
||||
|
||||
ContextBuffer.save(inputParametersSpan);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(EnhancedClassInstanceContext context, InstanceMethodInvokeContext interceptorContext,
|
||||
Object ret) {
|
||||
recordResultAndSave2BufferIfNecessary(ret);
|
||||
new LocalMethodInvokeMonitor().afterInvoke();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, EnhancedClassInstanceContext context,
|
||||
InstanceMethodInvokeContext interceptorContext) {
|
||||
new LocalMethodInvokeMonitor().occurException(t);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeMethod(StaticMethodInvokeContext interceptorContext, MethodInterceptResult result) {
|
||||
Identification.IdentificationBuilder identificationBuilder = Identification.newBuilder();
|
||||
identificationBuilder.spanType(new CustomLocalSpanType()).viewPoint(
|
||||
fullMethodName(interceptorContext.claszz(), interceptorContext.methodName(),
|
||||
interceptorContext.argumentTypes()));
|
||||
|
||||
new LocalMethodInvokeMonitor().beforeInvoke(identificationBuilder.build());
|
||||
|
||||
recordParametersAndSave2BufferIfNecessary(interceptorContext.allArguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object afterMethod(StaticMethodInvokeContext interceptorContext, Object ret) {
|
||||
recordResultAndSave2BufferIfNecessary(ret);
|
||||
new LocalMethodInvokeMonitor().afterInvoke();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void recordResultAndSave2BufferIfNecessary(Object ret) {
|
||||
if (Config.Plugin.CustomLocalMethodInterceptorPlugin.RECORD_PARAM_ENABLE){
|
||||
OutputParameterSpan outputParameterSpan = new OutputParameterSpan(Tracing.getTraceId(), Tracing.getTracelevelId());
|
||||
String retStr;
|
||||
try{
|
||||
retStr = new Gson().toJson(ret);
|
||||
}catch (Throwable e){
|
||||
retStr = "N/A";
|
||||
}
|
||||
outputParameterSpan.setOutputParameter(retStr);
|
||||
ContextBuffer.save(outputParameterSpan);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMethodException(Throwable t, MethodInvokeContext interceptorContext) {
|
||||
new LocalMethodInvokeMonitor().occurException(t);
|
||||
}
|
||||
|
||||
private String fullMethodName(Class clazz, String simpleMethodName, Class[] allArgumentTypes) {
|
||||
StringBuilder methodName = new StringBuilder(clazz.getName() + "." + simpleMethodName + "(");
|
||||
for (Class argument : allArgumentTypes) {
|
||||
methodName.append(argument.getName() + ",");
|
||||
}
|
||||
|
||||
if (allArgumentTypes.length > 0) {
|
||||
methodName.deleteCharAt(methodName.length() - 1);
|
||||
}
|
||||
|
||||
methodName.append(")");
|
||||
return methodName.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package com.a.eye.skywalking.plugin.custom.localmethod;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
import com.a.eye.skywalking.protocol.common.CallType;
|
||||
|
||||
public class CustomLocalSpanType implements IBuriedPointType {
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return "L";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return CallType.SYNC;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
package com.a.eye.skywalking.plugin.custom.localmethod.define;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassEnhancePluginDefine;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.AnyMethodsMatcher;
|
||||
|
||||
public class CustomLocalMethodPluginDefine extends ClassEnhancePluginDefine {
|
||||
|
||||
@Override
|
||||
protected MethodMatcher[] getInstanceMethodsMatchers() {
|
||||
return new MethodMatcher[] {new AnyMethodsMatcher()};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getInstanceMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.custom.localmethod.CustomLocalMethodInterceptor";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MethodMatcher[] getStaticMethodsMatchers() {
|
||||
return new MethodMatcher[] {new AnyMethodsMatcher()};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getStaticMethodsInterceptor() {
|
||||
return "com.a.eye.skywalking.plugin.custom.localmethod.CustomLocalMethodInterceptor";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String enhanceClassName() {
|
||||
if (!Config.Plugin.CustomLocalMethodInterceptorPlugin.IS_ENABLE){
|
||||
return null;
|
||||
}
|
||||
return Config.Plugin.CustomLocalMethodInterceptorPlugin.PACKAGE_PREFIX;
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
com.a.eye.skywalking.plugin.custom.localmethod.define.CustomLocalMethodPluginDefine
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
package com.a.eye.skywalking.plugin.custom.localmethod;
|
||||
|
||||
import com.a.eye.skywalking.plugin.TracingBootstrap;
|
||||
import com.a.eye.skywalking.testframework.api.RequestSpanAssert;
|
||||
import org.junit.Test;
|
||||
import test.com.ai.test.TestObject;
|
||||
import test.com.ai.test.TestParam;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class CustomLocalMethodPluginTest {
|
||||
|
||||
@Test
|
||||
public void test()
|
||||
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
TracingBootstrap.main(new String[]{"CustomLocalMethodPluginTest"});
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
TestObject testObject = new TestObject();
|
||||
testObject.printlnHelloWorld();
|
||||
TestObject.staticPrintlnHelloWorld("AA", new TestParam());
|
||||
RequestSpanAssert.assertEquals(new String[][] {
|
||||
{"0", "test.com.ai.test.TestObject.printlnHelloWorld()", ""},
|
||||
{"0", "test.com.ai.test.TestObject.staticPrintlnHelloWorld()", ""}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package test.com.ai.test;
|
||||
|
||||
public class TestObject {
|
||||
public static void staticPrintlnHelloWorld(String aa, TestParam param){
|
||||
System.out.println("Hello World" + aa);
|
||||
}
|
||||
|
||||
public void printlnHelloWorld(TestParam... params){
|
||||
System.out.println("Hello World");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package test.com.ai.test;
|
||||
|
||||
/**
|
||||
* Created by xin on 16/8/12.
|
||||
*/
|
||||
public class TestParam {
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
#skyWalking用户ID
|
||||
skywalking.user_id=123
|
||||
#skyWalking应用编码
|
||||
skywalking.application_code=skywalking-sample-dubbo
|
||||
#skywalking auth的环境变量名字
|
||||
skywalking.auth_system_env_name=SKYWALKING_RUN
|
||||
#skywalking数据编码
|
||||
skywalking.charset=UTF-8
|
||||
skywalking.auth_override=true
|
||||
#是否使用STD替换日志输出
|
||||
skywalking.logger_std_out_override=false;
|
||||
|
||||
#是否打印数据
|
||||
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=1
|
||||
#消费者最大等待时间
|
||||
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
|
||||
|
||||
#自定义本地方法插件是否开启
|
||||
plugin.customlocalmethodinterceptorplugin.is_enable=true
|
||||
#自定义插件拦截的包前缀
|
||||
plugin.customlocalmethodinterceptorplugin.package_prefix=test.com.ai.test.*
|
||||
#自定义插件是否记录入参
|
||||
plugin.customlocalmethodinterceptorplugin.record_param_enable=true
|
||||
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
<module>httpClient-4.x-plugin</module>
|
||||
<module>jedis-2.x-plugin</module>
|
||||
<module>tomcat-7.x-8.x-plugin</module>
|
||||
<module>custom-local-method-interceptor-plugin</module>
|
||||
<module>motan-plugin</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
package com.a.eye.skywalking.plugin.tomcat78x.define;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.Logger;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import com.a.eye.skywalking.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
|
||||
|
||||
public class TomcatPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
private static Logger logger = LogManager.getLogger(TomcatPluginDefine.class);
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(TomcatPluginDefine.class);
|
||||
|
||||
@Override
|
||||
protected MethodMatcher[] getInstanceMethodsMatchers() {
|
||||
|
|
|
|||
|
|
@ -19,5 +19,11 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class RequestSpanData extends AbstractSpanData {
|
|||
return requestSpan.getApplicationId();
|
||||
}
|
||||
|
||||
public String getProcessNo() {
|
||||
public int getProcessNo() {
|
||||
return requestSpan.getProcessNo();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue