Search in sources :

Example 11 with InstrumentMethod

use of com.shulie.instrument.simulator.api.instrument.InstrumentMethod in project LinkAgent by shulieTech.

the class KafkaStreamPlugin method addHookRegisterInterceptor.

private boolean addHookRegisterInterceptor() {
    this.enhanceTemplate.enhance(this, "org.apache.kafka.streams.kstream.internals.KStreamMap$KStreamMapProcessor", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod processMethod = target.getDeclaredMethod("process", "java.lang.Object", "java.lang.Object");
            processMethod.addInterceptor(Listeners.of(KStreamMapProcessorProcessInterceptor.class));
        }
    });
    this.enhanceTemplate.enhance(this, "org.apache.kafka.streams.kstream.internals.KStreamPeek$KStreamPeekProcessor", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod processMethod = target.getDeclaredMethod("process", "java.lang.Object", "java.lang.Object");
            processMethod.addInterceptor(Listeners.of(KStreamPeekProcessorProcessInterceptor.class));
        }
    });
    this.enhanceTemplate.enhance(this, "org.apache.kafka.streams.KafkaStreams", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod processMethod = target.getDeclaredMethod("close", "long", "java.util.concurrent.TimeUnit");
            processMethod.addInterceptor(Listeners.of(KafkaStreamsCloseInterceptor.class));
        }
    });
    return true;
}
Also used : InstrumentClass(com.shulie.instrument.simulator.api.instrument.InstrumentClass) InstrumentMethod(com.shulie.instrument.simulator.api.instrument.InstrumentMethod) EnhanceCallback(com.shulie.instrument.simulator.api.instrument.EnhanceCallback)

Example 12 with InstrumentMethod

use of com.shulie.instrument.simulator.api.instrument.InstrumentMethod in project LinkAgent by shulieTech.

the class ElasticSearchPlugin method addRestClientInterceptor.

private void addRestClientInterceptor() {
    // spring boot elasticsearch 6.8.6测试版本
    // 修改影子索引
    enhanceTemplate.enhance(this, "org.elasticsearch.client.RestHighLevelClient", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method = target.getDeclaredMethods("internalPerformRequest", "internalPerformRequestAsync");
            method.addInterceptor(Listeners.of(RestHighLevelClientInterceptor.class, "SEARCH_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
        }
    });
    // BulkRequest修改影子索引需要在添加请求时就执行
    enhanceTemplate.enhance(this, "org.elasticsearch.action.bulk.BulkRequest", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method = target.getDeclaredMethod("add", "org.elasticsearch.action.index.IndexRequest");
            method.addInterceptor(Listeners.of(BulkRequestAddInterceptor.class, "SEARCH_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
        }
    });
    // 链路监控需要增强该类所有方法
    enhanceTemplate.enhance(this, "org.elasticsearch.client.RestClient", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod performRequestMethod = target.getDeclaredMethod("performRequest", "org.elasticsearch.client.Request");
            performRequestMethod.addInterceptor(Listeners.of(RestClientPerformRequestInterceptor.class, "SHADOW_SEARCH_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            InstrumentMethod performRequestAsyncMethod = target.getDeclaredMethod("performRequestAsync", "org.elasticsearch.client.Request", "org.elasticsearch.client.ResponseListener");
            InstrumentMethod performRequestAsyncMethodLowVersion = target.getDeclaredMethod("performRequestAsync", "java.lang.String", "java.lang.String", "java.util.Map", "org.apache.http.HttpEntity", "org.elasticsearch.client.HttpAsyncResponseConsumerFactory", "org.elasticsearch.client.ResponseListener", "org.apache.http.Header[]");
            if (performRequestAsyncMethod != null) {
                performRequestAsyncMethod.addInterceptor(Listeners.of(RestClientPerformAsyncRequestInterceptor.class, "SHADOW_SEARCH_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            }
            if (performRequestAsyncMethodLowVersion != null) {
                performRequestAsyncMethodLowVersion.addInterceptor(Listeners.of(RestClientPerformAsyncLowVersionRequestInterceptor.class, "SHADOW_SEARCH_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            }
        }
    });
}
Also used : InstrumentClass(com.shulie.instrument.simulator.api.instrument.InstrumentClass) InstrumentMethod(com.shulie.instrument.simulator.api.instrument.InstrumentMethod) EnhanceCallback(com.shulie.instrument.simulator.api.instrument.EnhanceCallback)

Example 13 with InstrumentMethod

use of com.shulie.instrument.simulator.api.instrument.InstrumentMethod in project LinkAgent by shulieTech.

the class MotanPlugin method onActive.

@Override
public boolean onActive() throws Throwable {
    enhanceTemplate.enhance(this, "com.weibo.api.motan.rpc.AbstractReferer", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod callMethod = target.getDeclaredMethod("call", "com.weibo.api.motan.rpc.Request");
            callMethod.addInterceptor(Listeners.of(AbstractRefererCallInterceptor.class));
        }
    });
    enhanceTemplate.enhance(this, "com.weibo.api.motan.transport.ProviderMessageRouter", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method = target.getDeclaredMethod("handle", "com.weibo.api.motan.transport.Channel", "java.lang.Object");
            method.addInterceptor(Listeners.of(ProviderMessageRouterCallInterceptor.class));
        }
    });
    return true;
}
Also used : InstrumentClass(com.shulie.instrument.simulator.api.instrument.InstrumentClass) InstrumentMethod(com.shulie.instrument.simulator.api.instrument.InstrumentMethod) EnhanceCallback(com.shulie.instrument.simulator.api.instrument.EnhanceCallback)

Example 14 with InstrumentMethod

use of com.shulie.instrument.simulator.api.instrument.InstrumentMethod in project LinkAgent by shulieTech.

the class MybatisPlugin method onActive.

@Override
public boolean onActive() throws Throwable {
    /**
     * mybatis 二级缓存
     */
    addInterceptorsForMapperBuilderAssistant();
    addInterceptorsForMappedStatement();
    enhanceTemplate.enhance(this, "org.apache.ibatis.session.defaults.DefaultSqlSession", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            final InstrumentMethod method = target.getDeclaredMethods("selectOne", "selectList", "selectMap", "selectCursor", "select", "insert", "update", "delete");
            method.addInterceptor(Listeners.of(SqlSessionOperationInterceptor.class, "MYBATIS_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
        }
    });
    enhanceTemplate.enhance(this, "org.mybatis.spring.SqlSessionTemplate", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            final InstrumentMethod method = target.getDeclaredMethods("selectOne", "selectList", "selectMap", "selectCursor", "select", "insert", "update", "delete");
            method.addInterceptor(Listeners.of(SqlSessionOperationInterceptor.class, "MYBATIS_SCOPE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
        }
    });
    return true;
}
Also used : InstrumentClass(com.shulie.instrument.simulator.api.instrument.InstrumentClass) InstrumentMethod(com.shulie.instrument.simulator.api.instrument.InstrumentMethod) EnhanceCallback(com.shulie.instrument.simulator.api.instrument.EnhanceCallback)

Example 15 with InstrumentMethod

use of com.shulie.instrument.simulator.api.instrument.InstrumentMethod in project LinkAgent by shulieTech.

the class MongoDBPlugin method onActive.

@Override
public boolean onActive() throws Throwable {
    /**
     * 因为这个插件与mongodb322插件冲突,所以当mongodb322插件启用时此插件禁用
     */
    // 默认不用4
    boolean use = false;
    String mongodb4Enabled = System.getProperty("mongodb4.enabled");
    if (mongodb4Enabled == null) {
        mongodb4Enabled = simulatorConfig.getProperty("mongodb4.enabled");
    }
    if (StringUtils.isNotBlank(mongodb4Enabled) && Boolean.valueOf(mongodb4Enabled)) {
        use = true;
    }
    if (!use) {
        return false;
    }
    enhanceTemplate.enhance(this, "com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            // for new version 4.x
            InstrumentMethod instrumentMethod_3 = target.getDeclaredMethod("execute", "com.mongodb.internal.operation.ReadOperation", "com.mongodb.ReadPreference", "com.mongodb.ReadConcern", "com.mongodb.client.ClientSession");
            InstrumentMethod instrumentMethod_4 = target.getDeclaredMethod("execute", "com.mongodb.internal.operation.WriteOperation", "com.mongodb.ReadConcern", "com.mongodb.client.ClientSession");
            instrumentMethod_3.addInterceptor(Listeners.of(DelegateOperationExecutorTraceInterceptor.class, "execute_trace", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            instrumentMethod_4.addInterceptor(Listeners.of(DelegateOperationExecutorTraceInterceptor.class, "execute_trace", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            instrumentMethod_3.addInterceptor(Listeners.of(DelegateOperationExecutorInterceptor.class));
            instrumentMethod_4.addInterceptor(Listeners.of(DelegateOperationExecutorInterceptor.class));
        }
    });
    return true;
}
Also used : InstrumentClass(com.shulie.instrument.simulator.api.instrument.InstrumentClass) InstrumentMethod(com.shulie.instrument.simulator.api.instrument.InstrumentMethod) EnhanceCallback(com.shulie.instrument.simulator.api.instrument.EnhanceCallback)

Aggregations

EnhanceCallback (com.shulie.instrument.simulator.api.instrument.EnhanceCallback)41 InstrumentClass (com.shulie.instrument.simulator.api.instrument.InstrumentClass)41 InstrumentMethod (com.shulie.instrument.simulator.api.instrument.InstrumentMethod)41 XxlJobAdapter (com.pamirs.attach.plugin.shadowjob.adapter.XxlJobAdapter)1 IEvent (com.pamirs.pradar.pressurement.agent.event.IEvent)1 ClusterTestSwitchOffEvent (com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOffEvent)1 ClusterTestSwitchOnEvent (com.pamirs.pradar.pressurement.agent.event.impl.ClusterTestSwitchOnEvent)1 EventResult (com.pamirs.pradar.pressurement.agent.listener.EventResult)1 PradarEventListener (com.pamirs.pradar.pressurement.agent.listener.PradarEventListener)1 ShadowImplListener (com.pamirs.pradar.pressurement.agent.listener.impl.ShadowImplListener)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1