use of com.shulie.instrument.simulator.api.instrument.EnhanceCallback in project LinkAgent by shulieTech.
the class ShadowJobPlugin method onActive.
@Override
public boolean onActive() throws Throwable {
final ShadowImplListener shaDowImplListener = new ShadowImplListener();
try {
XxlJobAdapter xxlJobAdapter = new XxlJobAdapter();
GlobalConfig.getInstance().addJobAdaptor(xxlJobAdapter.getJobName(), xxlJobAdapter);
} catch (Throwable t) {
// ignore
}
EventRouter.router().addListener(shaDowImplListener);
EventRouter.router().addListener(new PradarEventListener() {
@Override
public EventResult onEvent(IEvent event) {
if (event instanceof ClusterTestSwitchOnEvent) {
} else if (event instanceof ClusterTestSwitchOffEvent) {
String message = shaDowImplListener.disableAll();
if ("".equals(message)) {
return EventResult.success("shadow-job");
}
return EventResult.error("shadow-job", message);
}
return EventResult.IGNORE;
}
@Override
public int order() {
return 6;
}
});
enhanceTemplate.enhance(this, "org.activiti.engine.impl.cmd.AcquireAsyncJobsDueCmd", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod constructor = target.getConstructor("org.activiti.engine.impl.asyncexecutor.AsyncExecutor");
constructor.addInterceptor(Listeners.of(AcquireAsyncJobsDueCmdInterceptor.class));
}
});
enhanceTemplate.enhance(this, "org.quartz.core.QuartzScheduler", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod constructor = target.getConstructors();
constructor.addInterceptor(Listeners.of(QuartzInitAdapterInterceptor.class));
}
});
// enhanceTemplate.enhance(this, "com.dangdang.ddframe.job.lite.api.JobScheduler", new EnhanceCallback() {
// @Override
// public void doEnhance(InstrumentClass target) {
// InstrumentMethod constructor = target.getConstructors();
// constructor.addInterceptor(Listeners.of(ElasticInitAdapterInterceptor.class));
// }
// });
enhanceTemplate.enhance(this, "com.xxl.job.core.executor.XxlJobExecutor", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod declaredMethod = target.getDeclaredMethod("start");
declaredMethod.addInterceptor(Listeners.of(XxlInitAdapterInterceptor.class));
}
});
// enhanceTemplate.enhance(this, "org.springframework.context.support.ApplicationContextAwareProcessor", new EnhanceCallback() {
// @Override
// public void doEnhance(InstrumentClass target) {
// InstrumentMethod getMethod = target.getDeclaredMethod("invokeAwareInterfaces", "java.lang.Object");
// getMethod.addInterceptor(Listeners.of(SpringContextInterceptor.class));
// }
// });
enhanceTemplate.enhance(this, "org.springframework.context.support.AbstractRefreshableApplicationContext", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod getMethod = target.getDeclaredMethod("refreshBeanFactory");
getMethod.addInterceptor(Listeners.of(SpringContextInterceptor.class));
}
});
/**
* com.github.ltsopensource.spring.tasktracker.JobRunnerHolder
* lts spring任务注册切点
*/
enhanceTemplate.enhance(this, "com.github.ltsopensource.spring.tasktracker.JobRunnerHolder", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod getMethod = target.getDeclaredMethod("add", "java.lang.String", "com.github.ltsopensource.tasktracker.runner.JobRunner");
getMethod.addInterceptor(Listeners.of(JobRunnerHolderAddInterceptor.class));
}
});
/**
* com.github.ltsopensource.spring.tasktracker.JobRunnerHolder
* lts spring任务注册切点
*/
enhanceTemplate.enhance(this, "com.github.ltsopensource.jobtracker.support.JobReceiver", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod getMethod = target.getConstructor("com.github.ltsopensource.jobtracker.domain.JobTrackerAppContext");
getMethod.addInterceptor(Listeners.of(LtsJobReceiverInterceptor.class));
}
});
/**
* com.github.ltsopensource.spring.tasktracker.JobRunnerHolder
* lts taskTracker切点
*/
enhanceTemplate.enhance(this, "com.github.ltsopensource.tasktracker.TaskTracker", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod constructor = target.getConstructors();
constructor.addInterceptor(Listeners.of(LtsInitAdapterInterceptor.class));
}
});
// enhanceTemplate.enhance(this, "org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor", new EnhanceCallback() {
// @Override
// public void doEnhance(InstrumentClass target) {
// InstrumentMethod getMethod = target.getDeclaredMethod("processScheduled",
// "org.springframework.scheduling.annotation.Scheduled", "java.lang.reflect.Method", "java.lang.Object");
// getMethod.addInterceptor(Listeners.of(ScheduleJobInitAdapterInterceptor.class));
// }
// });
enhanceTemplate.enhance(this, "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
// springmvc 5.x版本
InstrumentMethod getMethod1 = target.getDeclaredMethod("invokeHandlerMethod", "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse", "org.springframework.web.method.HandlerMethod");
getMethod1.addInterceptor(Listeners.of(RequestMappingHandlerAdapterInterceptor.class));
// springmvc 4.x版本
InstrumentMethod getMethod2 = target.getDeclaredMethod("invokeHandleMethod", "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse", "org.springframework.web.method.HandlerMethod");
getMethod2.addInterceptor(Listeners.of(RequestMappingHandlerAdapterInterceptor.class));
}
});
// 新增对 spring bean 的调用拦截获取 BeanFactory,通过拦截器 TransactionInterceptor 获取到 BeanFactory
enhanceTemplate.enhance(this, "org.springframework.aop.framework.ReflectiveMethodInvocation", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod method = target.getDeclaredMethod("proceed");
method.addInterceptor(Listeners.of(ReflectiveMethodInvocationProceedInterceptor.class));
}
});
enhanceTemplate.enhance(this, "com.xxl.job.core.handler.impl.MethodJobHandler", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod getMethod = target.getDeclaredMethod("execute", "java.lang.String");
getMethod.addInterceptor(Listeners.of(MethodJobHandlerExecuteInterceptor.class));
}
});
enhanceTemplate.enhance(this, "com.dangdang.ddframe.job.executor.JobExecutorFactory", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod getMethod = target.getDeclaredMethod("getJobExecutor", "com.dangdang.ddframe.job.api.ElasticJob", "com.dangdang.ddframe.job.executor.JobFacade");
getMethod.addInterceptor(Listeners.of(JobExecutorFactoryGetJobExecutorInterceptor.class));
}
});
enhanceTemplate.enhance(this, "org.springframework.scheduling.support.ScheduledMethodRunnable", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod getMethod = target.getDeclaredMethod("run");
getMethod.addInterceptor(Listeners.of(ScheduledMethodRunnableRunInterceptor.class));
}
});
//
// enhanceTemplate.enhance(this, "org.springframework.scheduling.quartz.QuartzJobBean", new EnhanceCallback() {
// @Override
// public void doEnhance(InstrumentClass target) {
// InstrumentMethod getMethod = target.getDeclaredMethod("execute", "org.quartz.JobExecutionContext");
// getMethod.addInterceptor(Listeners.of(QuartzJobBeanExecuteInterceptor.class));
// }
// });
enhanceTemplate.enhance(this, "org.quartz.JobExecutionContext", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod constructor = target.getConstructor("org.quartz.Scheduler", "org.quartz.spi.TriggerFiredBundle", "org.quartz.Job");
constructor.addInterceptor(Listeners.of(JobExecutionContextInterceptor.class));
}
});
// org.quartz.core.JobRunShell.initialize quartz2.x
enhanceTemplate.enhance(this, "org.quartz.core.JobRunShell", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
// 2.x
InstrumentMethod declaredMethod_1 = target.getDeclaredMethod("initialize", "org.quartz.core.QuartzScheduler");
if (declaredMethod_1 != null) {
declaredMethod_1.addInterceptor(Listeners.of(JobRunShellInitializeInterceptor.class));
}
// 1.x
InstrumentMethod declaredMethod_2 = target.getDeclaredMethod("initialize", "org.quartz.core.QuartzScheduler", "org.quartz.spi.TriggerFiredBundle");
if (declaredMethod_2 != null) {
declaredMethod_2.addInterceptor(Listeners.of(JobRunShellInitializeInterceptor_1.class));
}
}
});
try {
Class.forName("com.dangdang.ddframe.job.spring.schedule.SpringJobScheduler");
PradarSpringUtil.onApplicationContextLoad(new Runnable() {
@Override
public void run() {
ElasticJobRegisterUtil.addShadowJob();
}
});
} catch (ClassNotFoundException e) {
// do nothing
}
return true;
}
use of com.shulie.instrument.simulator.api.instrument.EnhanceCallback in project LinkAgent by shulieTech.
the class SpringCloudGatewayPlugin method onActive.
@Override
public boolean onActive() throws Throwable {
this.enhanceTemplate.enhance(this, "org.springframework.cloud.gateway.handler.FilteringWebHandler", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
final InstrumentMethod handle = target.getDeclaredMethod("handle", "org.springframework.web.server.ServerWebExchange");
handle.addInterceptor(Listeners.of(FilteringWebHandlerHandleInterceptor.class, "SpringCloudGatewayScope", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
}
});
this.enhanceTemplate.enhance(this, "org.springframework.cloud.gateway.filter.NettyRoutingFilter", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
final InstrumentMethod filter = target.getDeclaredMethod("filter", "org.springframework.web.server.ServerWebExchange", "org.springframework.cloud.gateway.filter.GatewayFilterChain");
filter.addInterceptor(Listeners.of(GatewayFilterChainFilterInterceptor.class, "SpringCloudGatewayFilterScope", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
}
});
return true;
}
use of com.shulie.instrument.simulator.api.instrument.EnhanceCallback in project LinkAgent by shulieTech.
the class RocketMQPlugin method addHookRegisterInterceptor.
private boolean addHookRegisterInterceptor() {
this.enhanceTemplate.enhance(this, "org.apache.rocketmq.client.consumer.DefaultMQPushConsumer", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
final InstrumentMethod createTopicMethod = target.getDeclaredMethods("createTopic");
createTopicMethod.addInterceptor(Listeners.of(DefaultPushConsumerCreateTopicInterceptor.class));
final InstrumentMethod earliestMsgStoreTimeMethod = target.getDeclaredMethods("earliestMsgStore");
earliestMsgStoreTimeMethod.addInterceptor(Listeners.of(DefaultPushConsumerEarliestMsgStoreTimeInterceptor.class));
final InstrumentMethod searchOffsetMethod = target.getDeclaredMethods("searchOffset");
searchOffsetMethod.addInterceptor(Listeners.of(DefaultPushConsumerSearchOffsetInterceptor.class));
final InstrumentMethod maxOffsetMethod = target.getDeclaredMethods("maxOffset");
maxOffsetMethod.addInterceptor(Listeners.of(DefaultPushConsumerMaxOffsetInterceptor.class));
final InstrumentMethod minOffsetMethod = target.getDeclaredMethods("minOffset");
minOffsetMethod.addInterceptor(Listeners.of(DefaultPushConsumerMinOffsetInterceptor.class));
final InstrumentMethod viewMessageMethod = target.getDeclaredMethods("viewMessage");
viewMessageMethod.addInterceptor(Listeners.of(DefaultPushConsumerViewMessageInterceptor.class));
final InstrumentMethod queryMessageMethod = target.getDeclaredMethods("queryMessage");
queryMessageMethod.addInterceptor(Listeners.of(DefaultPushConsumerQueryMessageInterceptor.class));
final InstrumentMethod fetchSubscribeMessageQueuesMethod = target.getDeclaredMethods("fetchSubscribeMessageQueues");
fetchSubscribeMessageQueuesMethod.addInterceptor(Listeners.of(DefaultPushConsumerFetchSubscribeMessageQueuesInterceptor.class));
final InstrumentMethod sendMessageBackMethod = target.getDeclaredMethods("sendMessageBack");
sendMessageBackMethod.addInterceptor(Listeners.of(DefaultPushConsumerSendMessageBackInterceptor.class));
final InstrumentMethod shutdownMethod = target.getDeclaredMethod("shutdown");
shutdownMethod.addInterceptor(Listeners.of(DefaultPushConsumerShutdownInterceptor.class));
}
});
this.enhanceTemplate.enhance(this, "org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
final InstrumentMethod hasHookMethod = target.getDeclaredMethod("hasHook");
hasHookMethod.addInterceptor(Listeners.of(DefaultMQPushConsumerImplHasHookListener.class));
}
});
this.enhanceTemplate.enhance(this, "org.apache.rocketmq.client.impl.consumer.DefaultMQPullConsumerImpl", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
final InstrumentMethod pullSyncImplMethod = target.getDeclaredMethod("pullSyncImpl", "org.apache.rocketmq.common.message.MessageQueue", "java.lang.String", "long", "int", "boolean", "long");
pullSyncImplMethod.addInterceptor(Listeners.of(PullConsumerInterceptor.class));
}
});
this.enhanceTemplate.enhance(this, "org.apache.rocketmq.client.producer.DefaultMQProducer", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
// 压测代码
InstrumentMethod sendMethod = target.getDeclaredMethods("send*");
sendMethod.addInterceptor(Listeners.of(MQProducerSendInterceptor.class));
}
});
this.enhanceTemplate.enhance(this, "org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
// 压测代码
InstrumentMethod method = target.getDeclaredMethods("sendDefaultImpl");
method.addInterceptor(Listeners.of(MQProducerSendInterceptor.class));
InstrumentMethod sendMessageInTransactionMethod = target.getDeclaredMethods("sendMessageInTransaction");
sendMessageInTransactionMethod.addInterceptor(Listeners.of(MQProducerSendInterceptor.class));
// 压测代码 end
}
});
this.enhanceTemplate.enhance(this, "org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod enhanceMethod = target.getDeclaredMethods("checkTransactionState*");
enhanceMethod.addInterceptor(Listeners.of(TransactionCheckInterceptor.class));
}
});
this.enhanceTemplate.enhance(this, "org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService$ConsumeRequest", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod enhanceMethod = target.getDeclaredMethods("run");
enhanceMethod.addInterceptor(Listeners.of(ConcurrentlyTraceInterceptor.class));
}
});
// --for orderly
this.enhanceTemplate.enhance(this, "org.apache.rocketmq.client.impl.consumer.ConsumeMessageOrderlyService$ConsumeRequest", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod enhanceMethod = target.getDeclaredMethods("run");
enhanceMethod.addInterceptor(Listeners.of(OrderlyTraceContextInterceptor.class));
}
});
this.enhanceTemplate.enhance(this, "org.apache.rocketmq.client.impl.consumer.ProcessQueue", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod enhanceMethod = target.getDeclaredMethods("takeMessags");
enhanceMethod.addInterceptor(Listeners.of(OrderlyTraceBeforeInterceptor.class));
}
});
this.enhanceTemplate.enhance(this, "org.apache.rocketmq.client.impl.consumer.ConsumeMessageOrderlyService", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod enhanceMethod = target.getDeclaredMethods("processConsumeResult");
enhanceMethod.addInterceptor(Listeners.of(OrderlyTraceAfterInterceptor.class));
}
});
// --for orderly
return true;
}
use of com.shulie.instrument.simulator.api.instrument.EnhanceCallback in project LinkAgent by shulieTech.
the class Log4jPlugin method addV1AppenderAndRouter.
private void addV1AppenderAndRouter() {
// org.apache.log4j.Category.addAppender
enhanceTemplate.enhance(this, "org.apache.log4j.Category", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod method = target.getDeclaredMethods("addAppender");
method.addInterceptor(Listeners.of(AppenderV1RegisterInterceptor.class, new Object[] { isBusinessLogOpen, bizShadowLogPath }));
}
});
// org.apache.log4j.AppenderSkeleton.doAppend
enhanceTemplate.enhance(this, "org.apache.log4j.AppenderSkeleton", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod method = target.getDeclaredMethod("doAppend", "org.apache.log4j.spi.LoggingEvent");
method.addInterceptor(Listeners.of(AppenderV1RouterInterceptor.class, new Object[] { isBusinessLogOpen, bizShadowLogPath }));
}
});
}
use of com.shulie.instrument.simulator.api.instrument.EnhanceCallback in project LinkAgent by shulieTech.
the class LogbackPlugin method onActive.
@Override
public boolean onActive() {
this.isBusinessLogOpen = simulatorConfig.getBooleanProperty("pradar.biz.log.divider", false);
this.bizShadowLogPath = simulatorConfig.getProperty("pradar.biz.log.divider.path", simulatorConfig.getLogPath());
if (!isBusinessLogOpen) {
if (logger.isInfoEnabled()) {
logger.info("logback biz log divider switcher is not open. ignore enhanced logback.");
}
return false;
}
// 改版后sift appender隔离不了,先不支持,有碰到再说
// for sifting appender start
/*enhanceTemplate.enhance(this, "ch.qos.logback.core.sift.SiftingAppenderBase", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod addAppenderMethod = target.getDeclaredMethods("append", "java.lang.Object");
addAppenderMethod.addInterceptor(
Listeners.of(SiftingAppenderBaseInterceptor.class, new Object[]{isBusinessLogOpen}));
}
});
enhanceTemplate.enhance(this, "ch.qos.logback.core.spi.AbstractComponentTracker", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod addAppenderMethod = target.getDeclaredMethods("getOrCreate", "java.lang.String", "long");
addAppenderMethod.addInterceptor(
Listeners.of(ComponentTrackerInterceptor.class, new Object[]{isBusinessLogOpen, bizShadowLogPath}));
}
});*/
// for sifting appender end
enhanceTemplate.enhance(this, "ch.qos.logback.core.spi.AppenderAttachableImpl", new EnhanceCallback() {
@Override
public void doEnhance(InstrumentClass target) {
InstrumentMethod addAppenderMethod = target.getDeclaredMethods("appendLoopOnAppenders");
addAppenderMethod.addInterceptor(Listeners.of(LogInterceptor.class, new Object[] { bizShadowLogPath }));
}
});
return true;
}
Aggregations