fix all compile issues of sniffer on using new network protocol.
This commit is contained in:
parent
c98b41b083
commit
de32fce10b
|
|
@ -26,7 +26,7 @@ message RequestSpan {
|
|||
uint32 spanType = 8;
|
||||
string applicationId = 9;
|
||||
string userId = 10;
|
||||
string bussinessKey = 11;
|
||||
string businessKey = 11;
|
||||
int32 processNo = 13;
|
||||
string address = 14;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
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.conf.ConfigInitializer;
|
||||
import com.a.eye.skywalking.logging.EasyLogResolver;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
|
|
@ -25,7 +25,7 @@ import static net.bytebuddy.matcher.ElementMatchers.isInterface;
|
|||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||
|
||||
public class SkyWalkingAgent {
|
||||
static{
|
||||
static {
|
||||
LogManager.setLogResolver(new EasyLogResolver());
|
||||
}
|
||||
|
||||
|
|
@ -35,45 +35,36 @@ public class SkyWalkingAgent {
|
|||
easyLogger = LogManager.getLogger(SkyWalkingAgent.class);
|
||||
|
||||
initConfig();
|
||||
if (AuthDesc.isAuth()) {
|
||||
final PluginDefineCategory pluginDefineCategory =
|
||||
PluginDefineCategory.category(new PluginBootstrap().loadPlugins());
|
||||
final PluginDefineCategory pluginDefineCategory = PluginDefineCategory.category(new PluginBootstrap().loadPlugins());
|
||||
|
||||
new AgentBuilder.Default().type(enhanceClassMatcher(pluginDefineCategory).and(not(isInterface())))
|
||||
.transform(new AgentBuilder.Transformer() {
|
||||
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder,
|
||||
TypeDescription typeDescription, ClassLoader classLoader) {
|
||||
AbstractClassEnhancePluginDefine pluginDefine =
|
||||
pluginDefineCategory.findPluginDefine(typeDescription.getTypeName());
|
||||
return pluginDefine.define(typeDescription.getTypeName(), builder);
|
||||
}
|
||||
}).with(new AgentBuilder.Listener() {
|
||||
@Override
|
||||
public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader,
|
||||
JavaModule module, DynamicType dynamicType) {
|
||||
new AgentBuilder.Default().type(enhanceClassMatcher(pluginDefineCategory).and(not(isInterface()))).transform(new AgentBuilder.Transformer() {
|
||||
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader) {
|
||||
AbstractClassEnhancePluginDefine pluginDefine = pluginDefineCategory.findPluginDefine(typeDescription.getTypeName());
|
||||
return pluginDefine.define(typeDescription.getTypeName(), builder);
|
||||
}
|
||||
}).with(new AgentBuilder.Listener() {
|
||||
@Override
|
||||
public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, DynamicType dynamicType) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIgnored(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) {
|
||||
}
|
||||
@Override
|
||||
public void onIgnored(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String typeName, ClassLoader classLoader, JavaModule module, Throwable throwable) {
|
||||
easyLogger.error("Failed to enhance class " + typeName, throwable);
|
||||
}
|
||||
@Override
|
||||
public void onError(String typeName, ClassLoader classLoader, JavaModule module, Throwable throwable) {
|
||||
easyLogger.error("Failed to enhance class " + typeName, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(String typeName, ClassLoader classLoader, JavaModule module) {
|
||||
}
|
||||
}).installOn(instrumentation);
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onComplete(String typeName, ClassLoader classLoader, JavaModule module) {
|
||||
}
|
||||
}).installOn(instrumentation);
|
||||
}
|
||||
|
||||
|
||||
private static <T extends NamedElement> ElementMatcher.Junction<T> enhanceClassMatcher(
|
||||
PluginDefineCategory pluginDefineCategory) {
|
||||
private static <T extends NamedElement> ElementMatcher.Junction<T> enhanceClassMatcher(PluginDefineCategory pluginDefineCategory) {
|
||||
return new SkyWalkingEnhanceMatcher<T>(pluginDefineCategory);
|
||||
}
|
||||
|
||||
|
|
@ -85,13 +76,13 @@ public class SkyWalkingAgent {
|
|||
private static void initConfig() {
|
||||
Config.SkyWalking.IS_PREMAIN_MODE = true;
|
||||
Config.SkyWalking.AGENT_BASE_PATH = initAgentBasePath();
|
||||
|
||||
ConfigInitializer.initialize();
|
||||
}
|
||||
|
||||
private static String initAgentBasePath() {
|
||||
try {
|
||||
String urlString =
|
||||
SkyWalkingAgent.class.getClassLoader().getSystemClassLoader().getResource(generateLocationPath())
|
||||
.toString();
|
||||
String urlString = SkyWalkingAgent.class.getClassLoader().getSystemClassLoader().getResource(generateLocationPath()).toString();
|
||||
urlString = urlString.substring(urlString.indexOf("file:"), urlString.indexOf('!'));
|
||||
return new File(new URL(urlString).getFile()).getParentFile().getAbsolutePath();
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-logging</artifactId>
|
||||
<artifactId>skywalking-logging-api</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.a.eye.skywalking.api;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.conf.AuthDesc;
|
||||
import com.a.eye.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
|
||||
|
|
@ -17,8 +16,6 @@ public final class BusinessKeyAppender {
|
|||
* @param businessKey
|
||||
*/
|
||||
public static void setBusinessKey2Trace(String businessKey) {
|
||||
if (!AuthDesc.isAuth())
|
||||
return;
|
||||
|
||||
Span spanData = CurrentThreadSpanStack.peek();
|
||||
if (spanData == null) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package com.a.eye.skywalking.api;
|
||||
|
||||
import com.a.eye.skywalking.conf.AuthDesc;
|
||||
import com.a.eye.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.a.eye.skywalking.model.ContextData;
|
||||
import com.a.eye.skywalking.model.Span;
|
||||
import com.a.eye.skywalking.network.grpc.TraceId;
|
||||
|
||||
public class Tracing {
|
||||
/**
|
||||
|
|
@ -12,21 +12,24 @@ public class Tracing {
|
|||
* @return
|
||||
*/
|
||||
public static String getTraceId() {
|
||||
if (!AuthDesc.isAuth())
|
||||
return "";
|
||||
|
||||
Span spanData = CurrentThreadSpanStack.peek();
|
||||
if (spanData == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return spanData.getTraceId();
|
||||
return formatTraceId(spanData.getTraceId());
|
||||
}
|
||||
|
||||
public static String formatTraceId(TraceId traceId){
|
||||
StringBuilder traceIdBuilder = new StringBuilder();
|
||||
for (Long segment : traceId.getSegmentsList()) {
|
||||
traceIdBuilder.append(segment).append(".");
|
||||
}
|
||||
|
||||
return traceIdBuilder.substring(0, traceIdBuilder.length() - 1).toString();
|
||||
}
|
||||
|
||||
public static String getTracelevelId() {
|
||||
if (!AuthDesc.isAuth())
|
||||
return "";
|
||||
|
||||
Span spanData = CurrentThreadSpanStack.peek();
|
||||
if (spanData == null) {
|
||||
return "";
|
||||
|
|
@ -38,9 +41,6 @@ public class Tracing {
|
|||
}
|
||||
|
||||
public static String generateNextContextData() {
|
||||
if (!AuthDesc.isAuth())
|
||||
return null;
|
||||
|
||||
Span spanData = CurrentThreadSpanStack.peek();
|
||||
if (spanData == null) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
package com.a.eye.skywalking.conf;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import com.a.eye.skywalking.selfexamination.SDKHealthCollector;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class AuthDesc {
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(AuthDesc.class);
|
||||
static boolean isAuth = false;
|
||||
|
||||
static {
|
||||
InputStream authFileInputStream;
|
||||
if (Config.SkyWalking.IS_PREMAIN_MODE) {
|
||||
authFileInputStream = fetchAuthFileInputStream();
|
||||
} else {
|
||||
authFileInputStream = AuthDesc.class.getResourceAsStream("/sky-walking.auth");
|
||||
}
|
||||
|
||||
ConfigInitializer.initialize(authFileInputStream);
|
||||
ConfigValidator.validate();
|
||||
SDKHealthCollector.init();
|
||||
}
|
||||
|
||||
private static InputStream fetchAuthFileInputStream() {
|
||||
try {
|
||||
return new FileInputStream(Config.SkyWalking.AGENT_BASE_PATH + File.separator + "/sky-walking.auth");
|
||||
} catch (Exception e) {
|
||||
easyLogger.error("Error to fetch auth file input stream.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAuth() {
|
||||
return isAuth;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,32 +7,14 @@ public class Config {
|
|||
|
||||
public static String APPLICATION_CODE = "";
|
||||
|
||||
public static String AUTH_SYSTEM_ENV_NAME = "SKYWALKING_RUN";
|
||||
|
||||
public static boolean AUTH_OVERRIDE = false;
|
||||
|
||||
public static String CHARSET = "UTF-8";
|
||||
|
||||
public static boolean ALL_METHOD_MONITOR = false;
|
||||
|
||||
public static boolean IS_PREMAIN_MODE = false;
|
||||
|
||||
public static String AGENT_BASE_PATH = "";
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class Plugin{
|
||||
|
||||
public static class CustomLocalMethodInterceptorPlugin{
|
||||
|
||||
public static boolean IS_ENABLE = false;
|
||||
|
||||
public static String PACKAGE_PREFIX = "";
|
||||
|
||||
public static boolean RECORD_PARAM_ENABLE = false;
|
||||
}
|
||||
|
||||
public static class Disruptor{
|
||||
public static int BUFFER_SIZE = 1024 * 4;
|
||||
}
|
||||
|
||||
public static class BuriedPoint {
|
||||
|
|
@ -49,62 +31,6 @@ public class Config {
|
|||
}
|
||||
|
||||
|
||||
public static class Consumer {
|
||||
// 最大消费线程数
|
||||
public static int MAX_CONSUMER = 2;
|
||||
// 消费者最大等待时间
|
||||
public static long MAX_WAIT_TIME = 5L;
|
||||
|
||||
//
|
||||
public static long CONSUMER_FAIL_RETRY_WAIT_INTERVAL = 50L;
|
||||
}
|
||||
|
||||
|
||||
public static class Buffer {
|
||||
// 每个Buffer的最大个数
|
||||
public static int BUFFER_MAX_SIZE = 20000;
|
||||
|
||||
// Buffer池的最大长度
|
||||
public static int POOL_SIZE = 5;
|
||||
}
|
||||
|
||||
|
||||
public static class Sender {
|
||||
// 最大发送数据个数
|
||||
public static final int MAX_SEND_DATA_SIZE = 10;
|
||||
// 最大发送者的连接数阀比例
|
||||
public static int CONNECT_PERCENT = 50;
|
||||
|
||||
// 发送服务端配置
|
||||
public static String SERVERS_ADDR = "127.0.0.1:34000";
|
||||
|
||||
// 最大发送副本数量
|
||||
public static int MAX_COPY_NUM = 2;
|
||||
|
||||
// 发送的最大长度
|
||||
public static int MAX_SEND_LENGTH = 18500;
|
||||
|
||||
public static long RETRY_GET_SENDER_WAIT_INTERVAL = 2000L;
|
||||
|
||||
// 切换Sender的周期
|
||||
public static long SWITCH_SENDER_INTERVAL = 10 * 60 * 1000;
|
||||
|
||||
// 切换Sender之后,关闭Sender的倒计时
|
||||
public static long CLOSE_SENDER_COUNTDOWN = 10 * 1000;
|
||||
|
||||
// Checker线程处理完成等待周期
|
||||
public static long CHECKER_THREAD_WAIT_INTERVAL = 1000;
|
||||
|
||||
public static long RETRY_FIND_CONNECTION_SENDER = 1000;
|
||||
}
|
||||
|
||||
|
||||
public static class HealthCollector {
|
||||
// 默认健康检查上报时间
|
||||
public static long REPORT_INTERVAL = 5 * 60 * 1000L;
|
||||
}
|
||||
|
||||
|
||||
public static class Logging {
|
||||
// log文件名
|
||||
public static String LOG_FILE_NAME = "skywalking-api.log";
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.a.eye.skywalking.conf;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
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 java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
|
@ -11,28 +13,34 @@ import java.util.LinkedList;
|
|||
import java.util.Properties;
|
||||
|
||||
public class ConfigInitializer {
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(ConfigInitializer.class);
|
||||
private static ILog logger = LogManager.getLogger(ConfigInitializer.class);
|
||||
|
||||
static void initialize(InputStream inputStream) {
|
||||
if (inputStream == null) {
|
||||
easyLogger.info("Not provide sky-walking certification documents, sky-walking api auto shutdown.");
|
||||
public static void initialize() {
|
||||
InputStream configFileStream;
|
||||
if (Config.SkyWalking.IS_PREMAIN_MODE) {
|
||||
configFileStream = fetchAuthFileInputStream();
|
||||
} else {
|
||||
configFileStream = ConfigInitializer.class.getResourceAsStream("/sky-walking.auth");
|
||||
}
|
||||
|
||||
Config.SkyWalking.USER_ID = System.getProperty("userId");
|
||||
Config.SkyWalking.APPLICATION_CODE = System.getProperty("applicationCode");
|
||||
|
||||
if (configFileStream == null) {
|
||||
logger.info("Not provide sky-walking certification documents, sky-walking api run in default config.");
|
||||
} else {
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
properties.load(inputStream);
|
||||
properties.load(configFileStream);
|
||||
initNextLevel(properties, Config.class, new ConfigDesc());
|
||||
AuthDesc.isAuth = Boolean.valueOf(System.getenv(Config.SkyWalking.AUTH_SYSTEM_ENV_NAME));
|
||||
easyLogger.info("sky-walking system-env auth : " + AuthDesc.isAuth);
|
||||
if(!AuthDesc.isAuth && Config.SkyWalking.AUTH_OVERRIDE){
|
||||
AuthDesc.isAuth = Config.SkyWalking.AUTH_OVERRIDE;
|
||||
easyLogger.info("sky-walking auth override: " + AuthDesc.isAuth);
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
easyLogger.error("Parsing certification file failed, sky-walking api auto shutdown.", e);
|
||||
} catch (IOException e) {
|
||||
easyLogger.error("Failed to read the certification file, sky-walking api auto shutdown.", e);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to read the config file, sky-walking api run in default config.", e);
|
||||
}
|
||||
}
|
||||
|
||||
if(StringUtil.isEmpty(Config.SkyWalking.USER_ID)){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void initNextLevel(Properties properties, Class<?> recentConfigType, ConfigDesc parentDesc) throws NumberFormatException, IllegalArgumentException, IllegalAccessException {
|
||||
|
|
@ -59,6 +67,15 @@ public class ConfigInitializer {
|
|||
parentDesc.removeLastDesc();
|
||||
}
|
||||
}
|
||||
|
||||
private static InputStream fetchAuthFileInputStream() {
|
||||
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);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigDesc {
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
package com.a.eye.skywalking.conf;
|
||||
|
||||
public class ConfigValidator {
|
||||
private ConfigValidator() {
|
||||
// Non
|
||||
}
|
||||
|
||||
public static boolean validate() {
|
||||
if (!validateSendMaxLength()) {
|
||||
throw new IllegalArgumentException("Max send length must great than the sum of the maximum " +
|
||||
"length of sending exception stack and the maximum length of sending business key.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean validateSendMaxLength() {
|
||||
if (Config.Sender.MAX_SEND_LENGTH < (Config.BuriedPoint.MAX_EXCEPTION_STACK_LENGTH +
|
||||
Config.BuriedPoint.BUSINESSKEY_MAX_LENGTH)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
package com.a.eye.skywalking.disruptor;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.disruptor.ack.AckSpanFactory;
|
||||
import com.a.eye.skywalking.disruptor.ack.AckSpanHolder;
|
||||
import com.a.eye.skywalking.disruptor.ack.SendAckSpanEventHandler;
|
||||
import com.a.eye.skywalking.disruptor.request.RequestSpanFactory;
|
||||
import com.a.eye.skywalking.disruptor.request.RequestSpanHolder;
|
||||
import com.a.eye.skywalking.disruptor.request.SendRequestSpanEventHandler;
|
||||
import com.a.eye.skywalking.health.report.HealthCollector;
|
||||
import com.a.eye.skywalking.health.report.HeathReading;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
import com.a.eye.skywalking.network.grpc.RequestSpan;
|
||||
import com.lmax.disruptor.RingBuffer;
|
||||
import com.lmax.disruptor.dsl.Disruptor;
|
||||
import com.lmax.disruptor.util.DaemonThreadFactory;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/26.
|
||||
*/
|
||||
public class AckSpanDisruptor {
|
||||
private ILog logger = LogManager.getLogger(AckSpanDisruptor.class);
|
||||
|
||||
private Disruptor<AckSpanHolder> ackSpanDisruptor;
|
||||
private RingBuffer<AckSpanHolder> ackSpanRingBuffer;
|
||||
|
||||
public static final AckSpanDisruptor INSTANCE = new AckSpanDisruptor();
|
||||
|
||||
private AckSpanDisruptor(){
|
||||
ackSpanDisruptor = new Disruptor<AckSpanHolder>(new AckSpanFactory(), Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE);
|
||||
ackSpanDisruptor.handleEventsWith(new SendAckSpanEventHandler());
|
||||
ackSpanDisruptor.start();
|
||||
ackSpanRingBuffer = ackSpanDisruptor.getRingBuffer();
|
||||
}
|
||||
|
||||
public void ready2Send(AckSpan ackSpan) {
|
||||
long sequence = ackSpanRingBuffer.next(); // Grab the next sequence
|
||||
try {
|
||||
AckSpanHolder data = ackSpanRingBuffer.get(sequence);
|
||||
data.setData(ackSpan);
|
||||
|
||||
HealthCollector.getCurrentHeathReading("AckSpanDisruptor").updateData(HeathReading.INFO, "ready2Send stored.");
|
||||
} catch (Exception e) {
|
||||
logger.error("AckSpan trace-id[{}] ready2Send failure.", ackSpan.getTraceId(), e);
|
||||
HealthCollector.getCurrentHeathReading("AckSpanDisruptor").updateData(HeathReading.ERROR, "AckSpan ready2Send failure.");
|
||||
} finally {
|
||||
ackSpanRingBuffer.publish(sequence);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.a.eye.skywalking.disruptor;
|
||||
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import com.a.eye.skywalking.disruptor.request.RequestSpanFactory;
|
||||
import com.a.eye.skywalking.disruptor.request.RequestSpanHolder;
|
||||
import com.a.eye.skywalking.disruptor.request.SendRequestSpanEventHandler;
|
||||
import com.a.eye.skywalking.health.report.HealthCollector;
|
||||
import com.a.eye.skywalking.health.report.HeathReading;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.network.grpc.RequestSpan;
|
||||
import com.lmax.disruptor.RingBuffer;
|
||||
import com.lmax.disruptor.dsl.Disruptor;
|
||||
import com.lmax.disruptor.util.DaemonThreadFactory;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/26.
|
||||
*/
|
||||
public class RequestSpanDisruptor {
|
||||
private ILog logger = LogManager.getLogger(RequestSpanDisruptor.class);
|
||||
|
||||
private Disruptor<RequestSpanHolder> requestSpanDisruptor;
|
||||
private RingBuffer<RequestSpanHolder> requestSpanRingBuffer;
|
||||
|
||||
public static final RequestSpanDisruptor INSTANCE = new RequestSpanDisruptor();
|
||||
|
||||
private RequestSpanDisruptor(){
|
||||
requestSpanDisruptor = new Disruptor<RequestSpanHolder>(new RequestSpanFactory(), Config.Disruptor.BUFFER_SIZE, DaemonThreadFactory.INSTANCE);
|
||||
requestSpanDisruptor.handleEventsWith(new SendRequestSpanEventHandler());
|
||||
requestSpanDisruptor.start();
|
||||
requestSpanRingBuffer = requestSpanDisruptor.getRingBuffer();
|
||||
}
|
||||
|
||||
public void ready2Send(RequestSpan requestSpan) {
|
||||
long sequence = requestSpanRingBuffer.next(); // Grab the next sequence
|
||||
try {
|
||||
RequestSpanHolder data = requestSpanRingBuffer.get(sequence);
|
||||
data.setData(requestSpan);
|
||||
|
||||
HealthCollector.getCurrentHeathReading("RequestSpanDisruptor").updateData(HeathReading.INFO, "ready2Send stored.");
|
||||
} catch (Exception e) {
|
||||
logger.error("RequestSpan trace-id[{}] ready2Send failure.", requestSpan.getTraceId(), e);
|
||||
HealthCollector.getCurrentHeathReading("RequestSpanDisruptor").updateData(HeathReading.ERROR, "RequestSpan ready2Send failure.");
|
||||
} finally {
|
||||
requestSpanRingBuffer.publish(sequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.a.eye.skywalking.disruptor.ack;
|
||||
|
||||
import com.lmax.disruptor.EventFactory;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/24.
|
||||
*/
|
||||
public class AckSpanFactory implements EventFactory<AckSpanHolder> {
|
||||
@Override
|
||||
public AckSpanHolder newInstance() {
|
||||
return new AckSpanHolder();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.a.eye.skywalking.disruptor.ack;
|
||||
|
||||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/26.
|
||||
*/
|
||||
public class AckSpanHolder {
|
||||
private AckSpan data;
|
||||
|
||||
public AckSpan getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(AckSpan data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.a.eye.skywalking.disruptor.ack;
|
||||
|
||||
import com.a.eye.skywalking.health.report.HealthCollector;
|
||||
import com.a.eye.skywalking.health.report.HeathReading;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
import com.lmax.disruptor.EventHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/24.
|
||||
*/
|
||||
public class SendAckSpanEventHandler implements EventHandler<AckSpanHolder> {
|
||||
private static ILog logger = LogManager.getLogger(SendAckSpanEventHandler.class);
|
||||
private int bufferSize = 100;
|
||||
private List<AckSpan> buffer = new ArrayList<>(bufferSize);
|
||||
|
||||
public SendAckSpanEventHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(AckSpanHolder event, long sequence, boolean endOfBatch) throws Exception {
|
||||
buffer.add(event.getData());
|
||||
|
||||
if (endOfBatch || buffer.size() == bufferSize) {
|
||||
try {
|
||||
|
||||
HealthCollector.getCurrentHeathReading("SendAckSpanEventHandler").updateData(HeathReading.INFO, "%s messages were successful consumed .", buffer.size());
|
||||
} finally {
|
||||
buffer.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.a.eye.skywalking.disruptor.request;
|
||||
|
||||
import com.lmax.disruptor.EventFactory;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/24.
|
||||
*/
|
||||
public class RequestSpanFactory implements EventFactory<RequestSpanHolder> {
|
||||
@Override
|
||||
public RequestSpanHolder newInstance() {
|
||||
return new RequestSpanHolder();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.a.eye.skywalking.disruptor.request;
|
||||
|
||||
import com.a.eye.skywalking.network.grpc.RequestSpan;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/26.
|
||||
*/
|
||||
public class RequestSpanHolder {
|
||||
private RequestSpan data;
|
||||
|
||||
public RequestSpan getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(RequestSpan data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.a.eye.skywalking.disruptor.request;
|
||||
|
||||
import com.a.eye.skywalking.health.report.HealthCollector;
|
||||
import com.a.eye.skywalking.health.report.HeathReading;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import com.a.eye.skywalking.network.grpc.RequestSpan;
|
||||
import com.lmax.disruptor.EventHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wusheng on 2016/11/24.
|
||||
*/
|
||||
public class SendRequestSpanEventHandler implements EventHandler<RequestSpanHolder> {
|
||||
private static ILog logger = LogManager.getLogger(SendRequestSpanEventHandler.class);
|
||||
private static final int bufferSize = 100;
|
||||
private List<RequestSpan> buffer = new ArrayList<>(bufferSize);
|
||||
|
||||
public SendRequestSpanEventHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(RequestSpanHolder event, long sequence, boolean endOfBatch) throws Exception {
|
||||
buffer.add(event.getData());
|
||||
|
||||
if (endOfBatch || buffer.size() == bufferSize) {
|
||||
try {
|
||||
|
||||
|
||||
HealthCollector.getCurrentHeathReading("SendRequestSpanEventHandler").updateData(HeathReading.INFO, "%s messages were successful consumed .", buffer.size());
|
||||
} finally {
|
||||
buffer.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
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.EasyLogger;
|
||||
import com.a.eye.skywalking.conf.AuthDesc;
|
||||
import com.a.eye.skywalking.context.CurrentThreadSpanStack;
|
||||
import com.a.eye.skywalking.disruptor.AckSpanDisruptor;
|
||||
import com.a.eye.skywalking.disruptor.RequestSpanDisruptor;
|
||||
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.Span;
|
||||
import com.a.eye.skywalking.network.grpc.AckSpan;
|
||||
import com.a.eye.skywalking.network.grpc.RequestSpan;
|
||||
import com.a.eye.skywalking.protocol.util.BuriedPointMachineUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
|
@ -34,19 +34,35 @@ public abstract class BaseInvokeMonitor {
|
|||
CurrentThreadSpanStack.push(spanData);
|
||||
|
||||
// 根据SpanData生成RequestSpan,并保存
|
||||
ContextBuffer.save(RequestSpan.RequestSpanBuilder.
|
||||
newBuilder(CurrentThreadSpanStack.peek()).callType(id.getCallType()).viewPoint(id.getViewPoint())
|
||||
.spanTypeDesc(id.getSpanTypeDesc()).processNo(BuriedPointMachineUtil.getProcessNo())
|
||||
.address(BuriedPointMachineUtil.getHostDesc()).build());
|
||||
|
||||
CurrentThreadSpanStack.push(spanData);
|
||||
|
||||
sendRequestSpan(spanData, id);
|
||||
|
||||
// 并将当前的Context返回回去
|
||||
return new ContextData(spanData);
|
||||
}
|
||||
|
||||
protected void sendRequestSpan(Span span, Identification id){
|
||||
RequestSpan.Builder requestSpanBuilder = span.buildRequestSpan(RequestSpan.newBuilder());
|
||||
RequestSpan requestSpan = requestSpanBuilder
|
||||
.setViewPointId(id.getViewPoint())
|
||||
.setSpanTypeDesc(id.getSpanTypeDesc())
|
||||
.setBusinessKey(id.getBusinessKey())
|
||||
.setCallType(id.getCallType()).setProcessNo(BuriedPointMachineUtil.getProcessNo())
|
||||
.setAddress(BuriedPointMachineUtil.getHostDesc()).build();
|
||||
|
||||
RequestSpanDisruptor.INSTANCE.ready2Send(requestSpan);
|
||||
}
|
||||
|
||||
protected void sendAckSpan(Span span){
|
||||
AckSpan ackSpan = span.buildAckSpan(AckSpan.newBuilder()).build();
|
||||
|
||||
AckSpanDisruptor.INSTANCE.ready2Send(ackSpan);
|
||||
}
|
||||
|
||||
protected void afterInvoke() {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return;
|
||||
|
||||
// 弹出上下文的栈顶中的元素
|
||||
Span spanData = CurrentThreadSpanStack.pop();
|
||||
|
|
@ -55,10 +71,8 @@ public abstract class BaseInvokeMonitor {
|
|||
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));
|
||||
sendAckSpan(spanData);
|
||||
} catch (Throwable t) {
|
||||
easyLogger.error(t.getMessage(), t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ 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;
|
||||
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.util.ContextGenerator;
|
||||
|
||||
public class LocalMethodInvokeMonitor extends BaseInvokeMonitor {
|
||||
|
||||
|
|
@ -16,9 +15,6 @@ public class LocalMethodInvokeMonitor extends BaseInvokeMonitor {
|
|||
|
||||
public ContextData beforeInvoke(Identification id) {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return new EmptyContextData();
|
||||
|
||||
Span spanData = ContextGenerator.generateSpanFromThreadLocal(id);
|
||||
|
||||
return super.beforeInvoke(spanData,id);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
package com.a.eye.skywalking.invoke.monitor;
|
||||
|
||||
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.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;
|
||||
|
||||
public class RPCClientInvokeMonitor extends BaseInvokeMonitor {
|
||||
|
|
@ -18,9 +15,6 @@ public class RPCClientInvokeMonitor extends BaseInvokeMonitor {
|
|||
|
||||
public ContextData beforeInvoke(Identification id) {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return new EmptyContextData();
|
||||
|
||||
Span spanData = ContextGenerator.generateSpanFromThreadLocal(id);
|
||||
//设置SpanType的类型
|
||||
spanData.setSpanType(SpanType.RPC_CLIENT);
|
||||
|
|
@ -32,16 +26,7 @@ public class RPCClientInvokeMonitor extends BaseInvokeMonitor {
|
|||
|
||||
CurrentThreadSpanStack.push(spanData);
|
||||
|
||||
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);
|
||||
sendRequestSpan(spanData, id);
|
||||
|
||||
return new ContextData(spanData.getTraceId(), generateSubParentLevelId(spanData));
|
||||
} catch (Throwable t) {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@ 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.Span;
|
||||
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;
|
||||
|
||||
public class RPCServerInvokeMonitor extends BaseInvokeMonitor {
|
||||
|
||||
|
|
@ -16,9 +15,6 @@ public class RPCServerInvokeMonitor extends BaseInvokeMonitor {
|
|||
|
||||
public void beforeInvoke(ContextData context, Identification id) {
|
||||
try {
|
||||
if (!AuthDesc.isAuth())
|
||||
return;
|
||||
|
||||
Span spanData = ContextGenerator.generateSpanFromContextData(
|
||||
context, id);
|
||||
// 设置是否为接收端
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.a.eye.skywalking.logging;
|
||||
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogResolver;
|
||||
|
||||
/**
|
||||
|
|
@ -8,7 +7,7 @@ import com.a.eye.skywalking.logging.api.LogResolver;
|
|||
*/
|
||||
public class EasyLogResolver implements LogResolver {
|
||||
@Override
|
||||
public ILog getLogger(Class<?> clazz) {
|
||||
public com.a.eye.skywalking.logging.api.ILog getLogger(Class<?> clazz) {
|
||||
return new EasyLogger(clazz);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import java.util.Date;
|
|||
/**
|
||||
* Created by xin on 16-6-23.
|
||||
*/
|
||||
public class EasyLogger implements ILog {
|
||||
public class EasyLogger implements com.a.eye.skywalking.logging.api.ILog {
|
||||
|
||||
private Class toBeLoggerClass;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.a.eye.skywalking.model;
|
||||
|
||||
|
||||
import com.a.eye.skywalking.api.Tracing;
|
||||
import com.a.eye.skywalking.network.grpc.TraceId;
|
||||
|
||||
public class ContextData {
|
||||
|
|
@ -64,11 +65,8 @@ public class ContextData {
|
|||
@Override
|
||||
public String toString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
StringBuilder traceIdBuilder = new StringBuilder();
|
||||
for (Long segment : traceId.getSegmentsList()) {
|
||||
traceIdBuilder.append(segment).append(".");
|
||||
}
|
||||
stringBuilder.append(traceIdBuilder.substring(0, traceIdBuilder.length() - 1));
|
||||
|
||||
stringBuilder.append(Tracing.formatTraceId(traceId));
|
||||
stringBuilder.append("-");
|
||||
if (parentLevel == null || parentLevel.length() == 0) {
|
||||
stringBuilder.append(" ");
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.plugin;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
import com.a.eye.skywalking.logging.EasyLogger;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
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 EasyLogger easyLogger = LogManager.getLogger(PluginBootstrap.class);
|
||||
private static ILog logger = 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) {
|
||||
easyLogger.info("no plugin files (skywalking-plugin.properties) found, continue to start application.");
|
||||
logger.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) {
|
||||
easyLogger.error("plugin [{}] init failure.", new Object[] {pluginUrl}, t);
|
||||
logger.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 {
|
||||
easyLogger.debug("loading plugin class {}.", pluginClassName);
|
||||
logger.debug("loading plugin class {}.", pluginClassName);
|
||||
AbstractClassEnhancePluginDefine plugin =
|
||||
(AbstractClassEnhancePluginDefine) Class.forName(pluginClassName).newInstance();
|
||||
plugins.add(plugin);
|
||||
} catch (Throwable t) {
|
||||
easyLogger.error("loade plugin [{}] failure.", new Object[] {pluginClassName}, t);
|
||||
logger.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.EasyLogger;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
|
||||
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 EasyLogger easyLogger = LogManager.getLogger(PluginResourcesResolver.class);
|
||||
private static ILog logger = 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()){
|
||||
easyLogger.info("no plugin files (skywalking-plugin.properties) found");
|
||||
logger.info("no plugin files (skywalking-plugin.properties) found");
|
||||
}
|
||||
|
||||
while(urls.hasMoreElements()){
|
||||
URL pluginUrl = urls.nextElement();
|
||||
cfgUrlPaths.add(pluginUrl);
|
||||
easyLogger.info("find skywalking plugin define in {}", pluginUrl);
|
||||
logger.info("find skywalking plugin define in {}", pluginUrl);
|
||||
}
|
||||
|
||||
return cfgUrlPaths;
|
||||
} catch (IOException e) {
|
||||
easyLogger.error("read resources failure.", e);
|
||||
logger.error("read resources failure.", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,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.EasyLogger;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.dynamic.ClassFileLocator;
|
||||
import net.bytebuddy.dynamic.DynamicType;
|
||||
|
|
@ -21,7 +20,7 @@ import java.util.List;
|
|||
* @author wusheng
|
||||
*/
|
||||
public class TracingBootstrap {
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(TracingBootstrap.class);
|
||||
private static ILog logger = LogManager.getLogger(TracingBootstrap.class);
|
||||
|
||||
private TracingBootstrap() {
|
||||
}
|
||||
|
|
@ -33,30 +32,26 @@ public class TracingBootstrap {
|
|||
throw new RuntimeException("bootstrap failure. need args[0] to be main class.");
|
||||
}
|
||||
|
||||
if (!AuthDesc.isAuth()){
|
||||
return;
|
||||
}
|
||||
|
||||
List<AbstractClassEnhancePluginDefine> plugins = null;
|
||||
|
||||
try {
|
||||
PluginBootstrap bootstrap = new PluginBootstrap();
|
||||
plugins = bootstrap.loadPlugins();
|
||||
} catch (Throwable t) {
|
||||
easyLogger.error("PluginBootstrap start failure.", t);
|
||||
logger.error("PluginBootstrap start failure.", t);
|
||||
}
|
||||
|
||||
for (AbstractClassEnhancePluginDefine plugin : plugins) {
|
||||
String enhanceClassName = plugin.enhanceClassName();
|
||||
TypePool.Resolution resolution = TypePool.Default.ofClassPath().describe(enhanceClassName);
|
||||
if (!resolution.isResolved()) {
|
||||
easyLogger.error("Failed to resolve the class " + enhanceClassName);
|
||||
logger.error("Failed to resolve the class " + enhanceClassName, null);
|
||||
continue;
|
||||
}
|
||||
DynamicType.Builder<?> newClassBuilder =
|
||||
new ByteBuddy().rebase(resolution.resolve(), ClassFileLocator.ForClassLoader.ofClassPath());
|
||||
newClassBuilder = ((AbstractClassEnhancePluginDefine) plugin).define(enhanceClassName, newClassBuilder);
|
||||
newClassBuilder.make(TypeResolutionStrategy.Active.INSTANCE).load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.INJECTION)
|
||||
newClassBuilder.make(new TypeResolutionStrategy.Active()).load(ClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.INJECTION)
|
||||
.getLoaded();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.EasyLogger;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
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 EasyLogger easyLogger = LogManager
|
||||
private static ILog logger = LogManager
|
||||
.getLogger(ClassConstructorInterceptor.class);
|
||||
|
||||
private String instanceMethodsAroundInterceptorClassName;
|
||||
|
|
@ -34,7 +34,7 @@ public class ClassConstructorInterceptor {
|
|||
allArguments);
|
||||
interceptor.onConstruct(context, interceptorContext);
|
||||
} catch (Throwable t) {
|
||||
easyLogger.error("ClassConstructorInterceptor failue.", t);
|
||||
logger.error("ClassConstructorInterceptor failue.", t);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ import static net.bytebuddy.jar.asm.Opcodes.ACC_PRIVATE;
|
|||
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.EasyLogger;
|
||||
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.PluginException;
|
||||
import com.a.eye.skywalking.plugin.interceptor.EnhancedClassInstanceContext;
|
||||
|
|
@ -22,164 +23,141 @@ import com.a.eye.skywalking.plugin.interceptor.EnhanceException;
|
|||
import com.a.eye.skywalking.plugin.interceptor.MethodMatcher;
|
||||
|
||||
public abstract class ClassEnhancePluginDefine extends AbstractClassEnhancePluginDefine {
|
||||
private static EasyLogger easyLogger = LogManager
|
||||
.getLogger(ClassEnhancePluginDefine.class);
|
||||
private static ILog logger = LogManager.getLogger(ClassEnhancePluginDefine.class);
|
||||
|
||||
public static final String contextAttrName = "_$EnhancedClassInstanceContext";
|
||||
public static final String contextAttrName = "_$EnhancedClassInstanceContext";
|
||||
|
||||
@Override
|
||||
protected DynamicType.Builder<?> enhance(String enhanceOriginClassName,
|
||||
DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
newClassBuilder = this.enhanceClass(enhanceOriginClassName, newClassBuilder);
|
||||
|
||||
newClassBuilder = this.enhanceInstance(enhanceOriginClassName, newClassBuilder);
|
||||
|
||||
return newClassBuilder;
|
||||
}
|
||||
@Override
|
||||
protected DynamicType.Builder<?> enhance(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
newClassBuilder = this.enhanceClass(enhanceOriginClassName, newClassBuilder);
|
||||
|
||||
private DynamicType.Builder<?> enhanceInstance(String enhanceOriginClassName,
|
||||
DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
MethodMatcher[] methodMatchers = getInstanceMethodsMatchers();
|
||||
if(methodMatchers == null){
|
||||
return newClassBuilder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* alter class source code.<br/>
|
||||
*
|
||||
* new class need:<br/>
|
||||
* 1.add field '_$EnhancedClassInstanceContext' of type
|
||||
* EnhancedClassInstanceContext <br/>
|
||||
*
|
||||
* 2.intercept constructor by default, and intercept method which it's
|
||||
* required by interceptorDefineClass. <br/>
|
||||
*/
|
||||
String interceptor = getInstanceMethodsInterceptor();
|
||||
if (StringUtil.isEmpty(interceptor)) {
|
||||
throw new EnhanceException("no InstanceMethodsAroundInterceptor define. ");
|
||||
}
|
||||
newClassBuilder = this.enhanceInstance(enhanceOriginClassName, newClassBuilder);
|
||||
|
||||
newClassBuilder = newClassBuilder
|
||||
.defineField(contextAttrName,
|
||||
EnhancedClassInstanceContext.class, ACC_PRIVATE)
|
||||
.constructor(any())
|
||||
.intercept(
|
||||
SuperMethodCall.INSTANCE.andThen(MethodDelegation.to(
|
||||
new ClassConstructorInterceptor(interceptor))
|
||||
.appendParameterBinder(
|
||||
FieldProxy.Binder.install(
|
||||
FieldGetter.class,
|
||||
FieldSetter.class))));
|
||||
return newClassBuilder;
|
||||
}
|
||||
|
||||
ClassInstanceMethodsInterceptor classMethodInterceptor = new ClassInstanceMethodsInterceptor(
|
||||
interceptor);
|
||||
private DynamicType.Builder<?> enhanceInstance(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
MethodMatcher[] methodMatchers = getInstanceMethodsMatchers();
|
||||
if (methodMatchers == null) {
|
||||
return newClassBuilder;
|
||||
}
|
||||
|
||||
StringBuilder enhanceRules = new StringBuilder(
|
||||
"\nprepare to enhance class [" + enhanceOriginClassName
|
||||
+ "] instance methods as following rules:\n");
|
||||
int ruleIdx = 1;
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
enhanceRules.append("\t" + ruleIdx++ + ". " + methodMatcher + "\n");
|
||||
}
|
||||
easyLogger.debug(enhanceRules);
|
||||
ElementMatcher.Junction<MethodDescription> matcher = null;
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
easyLogger.debug("enhance class {} instance methods by rule: {}",
|
||||
enhanceOriginClassName, methodMatcher);
|
||||
if (matcher == null) {
|
||||
matcher = methodMatcher.buildMatcher();
|
||||
continue;
|
||||
}
|
||||
|
||||
matcher = matcher.or(methodMatcher.buildMatcher());
|
||||
/**
|
||||
* alter class source code.<br/>
|
||||
*
|
||||
* new class need:<br/>
|
||||
* 1.add field '_$EnhancedClassInstanceContext' of type
|
||||
* EnhancedClassInstanceContext <br/>
|
||||
*
|
||||
* 2.intercept constructor by default, and intercept method which it's
|
||||
* required by interceptorDefineClass. <br/>
|
||||
*/
|
||||
String interceptor = getInstanceMethodsInterceptor();
|
||||
if (StringUtil.isEmpty(interceptor)) {
|
||||
throw new EnhanceException("no InstanceMethodsAroundInterceptor define. ");
|
||||
}
|
||||
|
||||
}
|
||||
newClassBuilder = newClassBuilder.defineField(contextAttrName, EnhancedClassInstanceContext.class, ACC_PRIVATE).constructor(any()).intercept(SuperMethodCall.INSTANCE
|
||||
.andThen(MethodDelegation.to(new ClassConstructorInterceptor(interceptor)).appendParameterBinder(FieldProxy.Binder.install(FieldGetter.class, FieldSetter.class))));
|
||||
|
||||
/**
|
||||
* exclude static methods.
|
||||
*/
|
||||
matcher = matcher.and(not(ElementMatchers.isStatic()));
|
||||
newClassBuilder = newClassBuilder.method(matcher).intercept(
|
||||
MethodDelegation.to(classMethodInterceptor));
|
||||
ClassInstanceMethodsInterceptor classMethodInterceptor = new ClassInstanceMethodsInterceptor(interceptor);
|
||||
|
||||
return newClassBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回需要被增强的方法列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract MethodMatcher[] getInstanceMethodsMatchers();
|
||||
StringBuilder enhanceRules = new StringBuilder("\nprepare to enhance class [" + enhanceOriginClassName + "] instance methods as following rules:\n");
|
||||
int ruleIdx = 1;
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
enhanceRules.append("\t" + ruleIdx++ + ". " + methodMatcher + "\n");
|
||||
}
|
||||
logger.debug(enhanceRules.toString());
|
||||
ElementMatcher.Junction<MethodDescription> matcher = null;
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
logger.debug("enhance class {} instance methods by rule: {}", enhanceOriginClassName, methodMatcher);
|
||||
if (matcher == null) {
|
||||
matcher = methodMatcher.buildMatcher();
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回增强拦截器的实现<br/>
|
||||
* 每个拦截器在同一个被增强类的内部,保持单例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getInstanceMethodsInterceptor();
|
||||
|
||||
private DynamicType.Builder<?> enhanceClass(String enhanceOriginClassName,
|
||||
DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
MethodMatcher[] methodMatchers = getStaticMethodsMatchers();
|
||||
if(methodMatchers == null){
|
||||
return newClassBuilder;
|
||||
}
|
||||
matcher = matcher.or(methodMatcher.buildMatcher());
|
||||
|
||||
String interceptor = getStaticMethodsInterceptor();
|
||||
if (StringUtil.isEmpty(interceptor)) {
|
||||
throw new EnhanceException("no StaticMethodsAroundInterceptor define. ");
|
||||
}
|
||||
|
||||
|
||||
ClassStaticMethodsInterceptor classMethodInterceptor = new ClassStaticMethodsInterceptor(
|
||||
interceptor);
|
||||
}
|
||||
|
||||
StringBuilder enhanceRules = new StringBuilder(
|
||||
"\nprepare to enhance class [" + enhanceOriginClassName
|
||||
+ "] static methods as following rules:\n");
|
||||
int ruleIdx = 1;
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
enhanceRules.append("\t" + ruleIdx++ + ". " + methodMatcher + "\n");
|
||||
}
|
||||
easyLogger.debug(enhanceRules);
|
||||
ElementMatcher.Junction<MethodDescription> matcher = null;
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
easyLogger.debug("enhance class {} static methods by rule: {}",
|
||||
enhanceOriginClassName, methodMatcher);
|
||||
if (matcher == null) {
|
||||
matcher = methodMatcher.buildMatcher();
|
||||
continue;
|
||||
}
|
||||
/**
|
||||
* exclude static methods.
|
||||
*/
|
||||
matcher = matcher.and(not(ElementMatchers.isStatic()));
|
||||
newClassBuilder = newClassBuilder.method(matcher).intercept(MethodDelegation.to(classMethodInterceptor));
|
||||
|
||||
matcher = matcher.or(methodMatcher.buildMatcher());
|
||||
return newClassBuilder;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 返回需要被增强的方法列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract MethodMatcher[] getInstanceMethodsMatchers();
|
||||
|
||||
/**
|
||||
* restrict static methods.
|
||||
*/
|
||||
matcher = matcher.and(ElementMatchers.isStatic());
|
||||
newClassBuilder = newClassBuilder.method(matcher).intercept(
|
||||
MethodDelegation.to(classMethodInterceptor));
|
||||
/**
|
||||
* 返回增强拦截器的实现<br/>
|
||||
* 每个拦截器在同一个被增强类的内部,保持单例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getInstanceMethodsInterceptor();
|
||||
|
||||
return newClassBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回需要被增强的方法列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract MethodMatcher[] getStaticMethodsMatchers();
|
||||
private DynamicType.Builder<?> enhanceClass(String enhanceOriginClassName, DynamicType.Builder<?> newClassBuilder) throws PluginException {
|
||||
MethodMatcher[] methodMatchers = getStaticMethodsMatchers();
|
||||
if (methodMatchers == null) {
|
||||
return newClassBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回增强拦截器的实现<br/>
|
||||
* 每个拦截器在同一个被增强类的内部,保持单例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getStaticMethodsInterceptor();
|
||||
String interceptor = getStaticMethodsInterceptor();
|
||||
if (StringUtil.isEmpty(interceptor)) {
|
||||
throw new EnhanceException("no StaticMethodsAroundInterceptor define. ");
|
||||
}
|
||||
|
||||
|
||||
ClassStaticMethodsInterceptor classMethodInterceptor = new ClassStaticMethodsInterceptor(interceptor);
|
||||
|
||||
StringBuilder enhanceRules = new StringBuilder("\nprepare to enhance class [" + enhanceOriginClassName + "] static methods as following rules:\n");
|
||||
int ruleIdx = 1;
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
enhanceRules.append("\t" + ruleIdx++ + ". " + methodMatcher + "\n");
|
||||
}
|
||||
logger.debug(enhanceRules.toString());
|
||||
ElementMatcher.Junction<MethodDescription> matcher = null;
|
||||
for (MethodMatcher methodMatcher : methodMatchers) {
|
||||
logger.debug("enhance class {} static methods by rule: {}", enhanceOriginClassName, methodMatcher);
|
||||
if (matcher == null) {
|
||||
matcher = methodMatcher.buildMatcher();
|
||||
continue;
|
||||
}
|
||||
|
||||
matcher = matcher.or(methodMatcher.buildMatcher());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* restrict static methods.
|
||||
*/
|
||||
matcher = matcher.and(ElementMatchers.isStatic());
|
||||
newClassBuilder = newClassBuilder.method(matcher).intercept(MethodDelegation.to(classMethodInterceptor));
|
||||
|
||||
return newClassBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回需要被增强的方法列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract MethodMatcher[] getStaticMethodsMatchers();
|
||||
|
||||
/**
|
||||
* 返回增强拦截器的实现<br/>
|
||||
* 每个拦截器在同一个被增强类的内部,保持单例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getStaticMethodsInterceptor();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.EasyLogger;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
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 EasyLogger easyLogger = LogManager.getLogger(ClassInstanceMethodsInterceptor.class);
|
||||
private static ILog logger = LogManager.getLogger(ClassInstanceMethodsInterceptor.class);
|
||||
|
||||
private String instanceMethodsAroundInterceptorClassName;
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ public class ClassInstanceMethodsInterceptor {
|
|||
try {
|
||||
interceptor.beforeMethod(instanceContext, interceptorContext, result);
|
||||
} catch (Throwable t) {
|
||||
easyLogger.error("class[{}] before method[{}] intercept failue:{}", new Object[] {obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
logger.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) {
|
||||
easyLogger.error("class[{}] handle method[{}] exception failue:{}", new Object[] {obj.getClass(), method.getName(), t2.getMessage()}, t2);
|
||||
logger.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) {
|
||||
easyLogger.error("class[{}] after method[{}] intercept failue:{}", new Object[] {obj.getClass(), method.getName(), t.getMessage()}, t);
|
||||
logger.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.EasyLogger;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
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 EasyLogger easyLogger = LogManager.getLogger(ClassStaticMethodsInterceptor.class);
|
||||
private static ILog logger = LogManager.getLogger(ClassStaticMethodsInterceptor.class);
|
||||
|
||||
private String staticMethodsAroundInterceptorClassName;
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ public class ClassStaticMethodsInterceptor {
|
|||
try {
|
||||
interceptor.beforeMethod(interceptorContext, result);
|
||||
} catch (Throwable t) {
|
||||
easyLogger.error("class[{}] before static method[{}] intercept failue:{}", new Object[] {clazz, method.getName(), t.getMessage()}, t);
|
||||
logger.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) {
|
||||
easyLogger.error("class[{}] handle static method[{}] exception failue:{}", new Object[] {clazz, method.getName(), t2.getMessage()}, t2);
|
||||
logger.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) {
|
||||
easyLogger.error("class[{}] after static method[{}] intercept failue:{}", new Object[] {clazz, method.getName(), t.getMessage()}, t);
|
||||
logger.error("class[{}] after static method[{}] intercept failue:{}", new Object[] {clazz, method.getName(), t.getMessage()}, t);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.a.eye.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
import com.a.eye.skywalking.protocol.common.CallType;
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.Origin;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
|
|
|
|||
|
|
@ -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.EasyLogger;
|
||||
import com.a.eye.skywalking.logging.api.ILog;
|
||||
import com.a.eye.skywalking.logging.api.LogManager;
|
||||
|
||||
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 EasyLogger easyLogger = LogManager.getLogger(InterceptorInstanceLoader.class);
|
||||
private static ILog logger = 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 {
|
||||
easyLogger.debug("Read binary code of {} using classload {}", className, InterceptorInstanceLoader.class.getClassLoader());
|
||||
logger.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) {
|
||||
easyLogger.error(e.getMessage(), e);
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
if (is != null)
|
||||
try {
|
||||
|
|
@ -105,7 +105,7 @@ public class InterceptorInstanceLoader {
|
|||
}
|
||||
}
|
||||
defineClassMethod.setAccessible(true);
|
||||
easyLogger.debug("load binary code of {} to classload {}", className, targetClassLoader);
|
||||
logger.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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public final class ContextGenerator {
|
|||
*/
|
||||
public static Span generateSpanFromContextData(ContextData context, Identification id) {
|
||||
Span spanData = CurrentThreadSpanStack.peek();
|
||||
if (context != null && !StringUtil.isEmpty(context.getTraceId()) && spanData == null){
|
||||
if (context != null && context.getTraceId() != null && spanData == null){
|
||||
spanData = new Span(context.getTraceId(), context.getParentLevel(), context.getLevelId(), Config.SkyWalking.APPLICATION_CODE, Config.SkyWalking.USER_ID);
|
||||
}else{
|
||||
spanData = getSpanFromThreadLocal();
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
package test.a.eye.cloud.consumerworker;
|
||||
|
||||
import com.a.eye.skywalking.buffer.BufferGroup;
|
||||
import com.a.eye.skywalking.conf.Config;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class ConsumerWorkerTest {
|
||||
|
||||
@Test
|
||||
public void checkConsumerWorkerIsStartIfConsumerSizeIsZero() {
|
||||
Config.Consumer.MAX_CONSUMER = 0;
|
||||
BufferGroup bufferGroup = new BufferGroup("testBufferGroup");
|
||||
int count = getConsumerWorkerThreadCount();
|
||||
assertEquals(Config.Consumer.MAX_CONSUMER, count);
|
||||
|
||||
}
|
||||
|
||||
private int getConsumerWorkerThreadCount() {
|
||||
ThreadGroup group = Thread.currentThread().getThreadGroup();
|
||||
ThreadGroup topGroup = group;
|
||||
while (group != null) {
|
||||
topGroup = group;
|
||||
group = group.getParent();
|
||||
}
|
||||
|
||||
int activeCount = topGroup.activeCount();
|
||||
Thread[] threads = new Thread[activeCount];
|
||||
topGroup.enumerate(threads);
|
||||
int count = 0;
|
||||
for (Thread thread : threads) {
|
||||
if (thread != null && "ConsumerWorker".equals(thread.getName())) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package com.a.eye.skywalking.plugin.dubbo;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
import com.a.eye.skywalking.protocol.common.CallType;
|
||||
|
||||
public class DubboBuriedPointType implements IBuriedPointType {
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public class MonitorFilterInterceptor implements InstanceMethodsAroundIntercepto
|
|||
|
||||
|
||||
private boolean isConsumer(EnhancedClassInstanceContext context) {
|
||||
return (boolean) context.get("isConsumer");
|
||||
return (Boolean) context.get("isConsumer");
|
||||
}
|
||||
|
||||
private void dealException(Throwable t, EnhancedClassInstanceContext context) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.a.eye.skywalking.plugin.httpClient.v4;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
import com.a.eye.skywalking.protocol.common.CallType;
|
||||
|
||||
public class WebBuriedPointType implements IBuriedPointType {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.a.eye.skywalking.plugin.jdbc.define;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
import com.a.eye.skywalking.protocol.common.CallType;
|
||||
|
||||
public class JDBCBuriedPointType implements IBuriedPointType {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.a.eye.skywalking.plugin.jedis.v2;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
import com.a.eye.skywalking.protocol.common.CallType;
|
||||
|
||||
public class RedisBuriedPointType implements IBuriedPointType {
|
||||
private static RedisBuriedPointType redisBuriedPointType;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.a.eye.skywalking.plugin.motan;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
import com.a.eye.skywalking.protocol.common.CallType;
|
||||
|
||||
public class MotanBuriedPointType implements IBuriedPointType {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.a.eye.skywalking.plugin.tomcat78x;
|
||||
|
||||
import com.a.eye.skywalking.api.IBuriedPointType;
|
||||
import com.a.eye.skywalking.protocol.common.CallType;
|
||||
|
||||
public class WebBuriedPointType implements IBuriedPointType {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
package com.a.eye.skywalking.plugin.tomcat78x.define;
|
||||
|
||||
import com.a.eye.skywalking.logging.LogManager;
|
||||
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;
|
||||
import com.a.eye.skywalking.plugin.interceptor.matcher.SimpleMethodMatcher;
|
||||
|
||||
public class TomcatPluginDefine extends ClassInstanceMethodsEnhancePluginDefine {
|
||||
private static EasyLogger easyLogger = LogManager.getLogger(TomcatPluginDefine.class);
|
||||
|
||||
@Override
|
||||
protected MethodMatcher[] getInstanceMethodsMatchers() {
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-api</artifactId>
|
||||
<artifactId>skywalking-network</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package com.a.eye.skywalking.testframework.api;
|
||||
|
||||
|
||||
import com.a.eye.skywalking.protocol.common.ISerializable;
|
||||
import com.a.eye.skywalking.testframework.api.config.Config;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
|
@ -9,13 +7,13 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class ContextPoolOperator {
|
||||
public static List<ISerializable> acquireBufferData() {
|
||||
List<ISerializable> resultSpan = new ArrayList<ISerializable>();
|
||||
public static List<Object> acquireBufferData() {
|
||||
List<Object> resultSpan = new ArrayList<Object>();
|
||||
Object[] bufferGroupObjectArray = acquireBufferGroupObjectArrayByClassLoader();
|
||||
|
||||
for (Object bufferGroup : bufferGroupObjectArray) {
|
||||
ISerializable[] spanList = acquireBufferData(bufferGroup);
|
||||
for (ISerializable span : spanList) {
|
||||
Object[] spanList = acquireBufferData(bufferGroup);
|
||||
for (Object span : spanList) {
|
||||
if (span != null) {
|
||||
resultSpan.add(span);
|
||||
}
|
||||
|
|
@ -29,19 +27,19 @@ public class ContextPoolOperator {
|
|||
Object[] bufferGroupObjectArray = acquireBufferGroupObjectArrayByClassLoader();
|
||||
|
||||
for (Object bufferGroup : bufferGroupObjectArray) {
|
||||
ISerializable[] spanList = acquireBufferData(bufferGroup);
|
||||
Object[] spanList = acquireBufferData(bufferGroup);
|
||||
for (int i = 0; i < spanList.length; i++) {
|
||||
spanList[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ISerializable[] acquireBufferData(Object bufferGroup) {
|
||||
private static Object[] acquireBufferData(Object bufferGroup) {
|
||||
try {
|
||||
Class bufferGroupClass = Thread.currentThread().getContextClassLoader().loadClass(Config.BUFFER_GROUP_CLASS_NAME);
|
||||
Field spanArrayField = bufferGroupClass.getDeclaredField(Config.SPAN_ARRAY_FIELD_NAME);
|
||||
spanArrayField.setAccessible(true);
|
||||
return (ISerializable[]) spanArrayField.get(bufferGroup);
|
||||
return (Object[]) spanArrayField.get(bufferGroup);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to acquire span array", e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.a.eye.skywalking.testframework.api;
|
||||
|
||||
import com.a.eye.skywalking.protocol.RequestSpan;
|
||||
import com.a.eye.skywalking.protocol.common.ISerializable;
|
||||
import com.a.eye.skywalking.network.grpc.RequestSpan;
|
||||
import com.a.eye.skywalking.network.grpc.TraceId;
|
||||
import com.a.eye.skywalking.testframework.api.exception.SpanDataNotEqualsException;
|
||||
import com.a.eye.skywalking.testframework.api.exception.SpanDataFormatException;
|
||||
import com.a.eye.skywalking.testframework.api.exception.TraceIdNotSameException;
|
||||
|
|
@ -34,10 +34,10 @@ public class RequestSpanAssert {
|
|||
}
|
||||
|
||||
private static List<RequestSpan> acquiredRequestSpanFromBuffer() {
|
||||
List<ISerializable> spans = ContextPoolOperator.acquireBufferData();
|
||||
List<Object> spans = ContextPoolOperator.acquireBufferData();
|
||||
|
||||
List<RequestSpan> result = new ArrayList<RequestSpan>();
|
||||
for (ISerializable span : spans) {
|
||||
for (Object span : spans) {
|
||||
if (span instanceof RequestSpan) {
|
||||
result.add((RequestSpan) span);
|
||||
}
|
||||
|
|
@ -116,14 +116,22 @@ public class RequestSpanAssert {
|
|||
String traceId = null;
|
||||
for (RequestSpan span : traceSpanList) {
|
||||
if (traceId == null) {
|
||||
traceId = span.getTraceId();
|
||||
traceId = toLiteralLTraceId(span.getTraceId());
|
||||
}
|
||||
|
||||
if (!traceId.equals(span.getTraceId())) {
|
||||
if (!traceId.equals(toLiteralLTraceId(span.getTraceId()))) {
|
||||
throw new TraceIdNotSameException("trace id is not all the same.trace id :" +
|
||||
traceId + ",Error trace id :" + span.getTraceId());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static String toLiteralLTraceId(TraceId traceId){
|
||||
StringBuilder tid = new StringBuilder();
|
||||
for (Long segment : traceId.getSegmentsList()) {
|
||||
tid.append(segment).append(".");
|
||||
}
|
||||
return tid.substring(0, tid.length() - 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class RequestSpanData extends AbstractSpanData {
|
|||
}
|
||||
|
||||
public String getBusinessKey() {
|
||||
return requestSpan.getBussinessKey();
|
||||
return requestSpan.getBusinessKey();
|
||||
}
|
||||
|
||||
public String getCallType() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue