Search in sources :

Example 26 with InstrumentMethod

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

the class HessianPlugin method onActive.

@Override
public boolean onActive() throws Throwable {
    enhanceTemplate.enhance(this, "com.caucho.hessian.client.HessianProxy", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod addRequestHeadersMethod = target.getDeclaredMethod("addRequestHeaders", "com.caucho.hessian.client.HessianConnection");
            addRequestHeadersMethod.addInterceptor(Listeners.of(HessianProxyAddRequestHeadersInterceptor.class));
        }
    });
    enhanceTemplate.enhance(this, "com.caucho.hessian.client.HessianProxyFactory", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method = target.getDeclaredMethod("create", "java.lang.Class", "java.net.URL", "java.lang.ClassLoader");
            method.addInterceptor(Listeners.of(HessianProxyFactoryCreateInterceptor.class));
        }
    });
    enhanceTemplate.enhance(this, "com.caucho.hessian.server.HessianServlet", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod serviceMethod = target.getDeclaredMethod("service", "javax.servlet.ServletRequest", "javax.servlet.ServletResponse");
            serviceMethod.addInterceptor(Listeners.of(HessianServletServiceInterceptor.class));
            serviceMethod.addInterceptor(Listeners.of(HessianServletWrapperRequestInterceptor.class));
        }
    });
    enhanceTemplate.enhance(this, "com.caucho.burlap.server.BurlapServlet", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod serviceMethod = target.getDeclaredMethod("service", "javax.servlet.ServletRequest", "javax.servlet.ServletResponse");
            serviceMethod.addInterceptor(Listeners.of(BurlapServletServiceInterceptor.class));
            serviceMethod.addInterceptor(Listeners.of(HessianServletWrapperRequestInterceptor.class));
        }
    });
    enhanceTemplate.enhance(this, "org.springframework.remoting.caucho.HessianServiceExporter", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod serviceMethod = target.getDeclaredMethod("handleRequest", "javax.servlet.http.HttpServletRequest", "javax.servlet.http.HttpServletResponse");
            serviceMethod.addInterceptor(Listeners.of(HessianServiceExporterHandleRequestInterceptor.class));
            serviceMethod.addInterceptor(Listeners.of(HessianServletWrapperRequestInterceptor.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 27 with InstrumentMethod

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

the class JedisPlugin method onActive.

@Override
public boolean onActive() {
    EnhanceCallback jedisEnhanceCallback = new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method = target.getDeclaredMethods(RedisUtils.get().keySet());
            method.addInterceptor(Listeners.dynamicScope(JedisInterceptor.class, ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            method.addInterceptor(Listeners.of(JedisSentinelShadowServerInterceptor.class, "JEDIS_SENTINEL", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            /**
             * jedis单机模式客户端路由器
             */
            method.addInterceptor(Listeners.of(JedisSingleClientCutOffInterceptor.class, "JEDIS_SINGLE", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            method.addInterceptor(Listeners.of(MJedisInterceptor.class));
        }
    };
    this.enhanceTemplate.enhance(this, "redis.clients.jedis.BinaryJedis", jedisEnhanceCallback);
    this.enhanceTemplate.enhance(this, "redis.clients.jedis.Jedis", jedisEnhanceCallback);
    EnhanceCallback pluginMaxRedisExpireTimeEnhanceCallback = new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            target.getDeclaredMethods("expire", "pexpire", "setex", "psetex").addInterceptor(Listeners.of(PluginMaxRedisExpireTimeInterceptor.class));
            target.getDeclaredMethod("set", "java.lang.String", "java.lang.String", "redis.clients.jedis.params.SetParams").addInterceptor(Listeners.of(PluginMaxRedisExpireTimeInterceptor.class));
            target.getDeclaredMethod("set", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "long").addInterceptor(Listeners.of(PluginMaxRedisExpireTimeInterceptor.class));
            target.getDeclaredMethod("set", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "int").addInterceptor(Listeners.of(PluginMaxRedisExpireTimeInterceptor.class));
        }
    };
    this.enhanceTemplate.enhance(this, "redis.clients.jedis.BinaryJedisCluster", pluginMaxRedisExpireTimeEnhanceCallback);
    this.enhanceTemplate.enhance(this, "redis.clients.jedis.JedisCluster", pluginMaxRedisExpireTimeEnhanceCallback);
    this.enhanceTemplate.enhance(this, "redis.clients.jedis.PipelineBase", pluginMaxRedisExpireTimeEnhanceCallback);
    this.enhanceTemplate.enhance(this, "redis.clients.jedis.Jedis", pluginMaxRedisExpireTimeEnhanceCallback);
    EnhanceCallback jedisClusterEnhanceCallback = new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method = target.getDeclaredMethods(RedisUtils.get().keySet());
            method.addInterceptor(Listeners.of(MJedisInterceptor.class));
        }
    };
    this.enhanceTemplate.enhance(this, "redis.clients.jedis.BinaryJedisCluster", jedisClusterEnhanceCallback);
    this.enhanceTemplate.enhance(this, "redis.clients.jedis.JedisCluster", jedisClusterEnhanceCallback);
    // redis.clients.jedis.PipelineBase
    enhanceTemplate.enhanceWithSuperClass(this, "redis.clients.jedis.PipelineBase", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            String[] methodName = { "append", "brpop", "blpop", "decr", "decrBy", "del", "echo", "exists", "expire", "expireAt", "get", "getbit", "bitpos", "bitpos", "getrange", "getSet", "getrange", "hdel", "hexists", "hget", "hgetAll", "hincrBy", "hkeys", "hlen", "hmget", "hmset", "hset", "hsetnx", "hvals", "incr", "incrBy", "lindex", "linsert", "llen", "lpop", "lpush", "lpushx", "lrange", "lrem", "lset", "ltrim", "move", "persist", "rpop", "rpush", "rpushx", "sadd", "scard", "set", "setbit", "setex", "setnx", "setrange", "sismember", "smembers", "sort", "sort", "spop", "spop", "srandmember", "srandmember", "srem", "strlen", "substr", "ttl", "type", "zadd", "zadd", "zcard", "zcount", "zincrby", "zrange", "zrangeByScore", "zrangeByScoreWithScores", "zrevrangeByScore", "zrevrangeByScoreWithScores", "zrangeWithScores", "zrank", "zrem", "zremrangeByRank", "zremrangeByScore", "zrevrange", "zrevrangeWithScores", "zrevrank", "zscore", "zlexcount", "zrangeByLex", "zrevrangeByLex", "bitcount", "dump", "migrate", "objectRefcount", "objctRefcount", "objectEncoding", "objectIdletime", "pexpire", "pexpireAt", "pttl", "restore", "incrByFloat", "psetex", "set", "hincrByFloat", "eval", "evalsha", "pfadd", "pfcount", "geoadd", "geodist", "geohash", "geopos", "georadius", "georadiusByMember", "bitfield", "xread" };
            InstrumentMethod declaredMethod = target.getDeclaredMethods(methodName);
            declaredMethod.addInterceptor(Listeners.of(JedisPipelineBaseInterceptor.class));
        }
    });
    // 兜底
    enhanceTemplate.enhance(this, "redis.clients.jedis.Client", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method = target.getDeclaredMethods(RedisUtils.get().keySet());
            method.addInterceptor(Listeners.of(RedisDataCheckInterceptor.class));
        }
    });
    enhanceTemplate.enhance(this, "redis.clients.jedis.util.Pool", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod closeMethod = target.getDeclaredMethod("close");
            closeMethod.addInterceptor(Listeners.of(PoolCloseInterceptor.class));
        }
    });
    // redis.clients.jedis.JedisSlotBasedConnectionHandler.getConnectionFromSlot
    // 影子cluster Server
    enhanceTemplate.enhance(this, "redis.clients.jedis.JedisSlotBasedConnectionHandler", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod method1 = target.getDeclaredMethod("getConnectionFromSlot", "int");
            method1.addInterceptor(Listeners.of(JedisClusterConnectionInterceptor.class, "Jedis_Get_Connection_Scope", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            InstrumentMethod method2 = target.getDeclaredMethod("getConnection");
            method2.addInterceptor(Listeners.of(JedisClusterConnectionInterceptor.class, "Jedis_Get_Connection_Scope", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
        }
    });
    // redis.clients.jedis.JedisClusterConnectionHandler
    // 影子cluster Server
    enhanceTemplate.enhance(this, "redis.clients.jedis.JedisClusterConnectionHandler", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            // jedis 3.1.0
            // redis.clients.jedis.JedisClusterConnectionHandler#JedisClusterConnectionHandler(
            // java.util.Set<redis.clients.jedis.HostAndPort>,
            // org.apache.commons.pool2.impl.GenericObjectPoolConfig, int, int,
            // java.lang.String, java.lang.String, boolean, javax.net.ssl.SSLSocketFactory,
            // javax.net.ssl.SSLParameters, javax.net.ssl.HostnameVerifier,
            // redis.clients.jedis.JedisClusterHostAndPortMap)
            InstrumentMethod closeMethod = target.getDeclaredMethod("close");
            closeMethod.addInterceptor(Listeners.of(PoolCloseInterceptor.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 28 with InstrumentMethod

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

the class LettucePlugin method addRedisClient.

private void addRedisClient() {
    this.enhanceTemplate.enhance(this, "io.lettuce.core.RedisClient", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            // set RedisURI
            final InstrumentMethod constructor = target.getConstructor("io.lettuce.core.resource.ClientResources", "io.lettuce.core.RedisURI");
            constructor.addInterceptor(Listeners.of(RedisClientConstructorInterceptor.class));
            InstrumentMethod method = target.getDeclaredMethods("connect", "connectAsync", "connectPubSub", "connectPubSubAsync", "connectSentinel", "connectSentinelAsync");
            method.addInterceptor(Listeners.of(RedisClientAttachRedisURIsInterceptor.class, "Lettuce_Scope", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            method.addInterceptor(Listeners.of(RedisClientPerformanceInterceptor.class, "Lettuce_Scope", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
        }
    });
    this.enhanceTemplate.enhance(this, "io.lettuce.core.AbstractRedisClient", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod shutdownAsyncMethod = target.getDeclaredMethod("shutdownAsync", "long", "long", "java.util.concurrent.TimeUnit");
            shutdownAsyncMethod.addInterceptor(Listeners.of(LettuceMethodShutdownInterceptor.class));
            // TODO: 2021/8/25 获取连接信息收集客户端连接信息
            InstrumentMethod connection1 = target.getDeclaredMethod("getConnection", "io.lettuce.core.ConnectionFuture");
            InstrumentMethod connection2 = target.getDeclaredMethod("getConnection", "java.util.concurrent.CompletableFuture");
            connection1.addInterceptor(Listeners.of(ConnectionInterceptor.class));
            connection2.addInterceptor(Listeners.of(ConnectionInterceptor.class));
        }
    });
    this.enhanceTemplate.enhance(this, "io.lettuce.core.cluster.RedisClusterClient", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            // set RedisURI
            final InstrumentMethod constructor = target.getConstructor("io.lettuce.core.resource.ClientResources", "java.lang.Iterable");
            constructor.addInterceptor(Listeners.of(RedisClusterClientConstructorInterceptor.class));
            InstrumentMethod method = target.getDeclaredMethods("connect", "connectAsync", "connectPubSub", "connectPubSubAsync", "connectSentinel", "connectSentinelAsync");
            method.addInterceptor(Listeners.of(RedisClientAttachRedisURIsInterceptor.class, "Lettuce_Scope", ExecutionPolicy.BOUNDARY, Interceptors.SCOPE_CALLBACK));
            method.addInterceptor(Listeners.of(RedisClientPerformanceInterceptor.class, "Lettuce_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 29 with InstrumentMethod

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

the class EhcachePlugin method onActive.

@Override
public boolean onActive() throws Throwable {
    enhanceTemplate.enhance(this, new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod getMethod = target.getDeclaredMethod("get", "java.lang.Object");
            getMethod.addInterceptor(Listeners.of(CacheKeyInterceptor.class));
            InstrumentMethod putMethod = target.getDeclaredMethod("put", "java.lang.Object", "java.lang.Object");
            putMethod.addInterceptor(Listeners.of(CacheKeyInterceptor.class));
            InstrumentMethod putIfAbsentMethod = target.getDeclaredMethod("putIfAbsent", "java.lang.Object", "java.lang.Object");
            putIfAbsentMethod.addInterceptor(Listeners.of(CacheKeyInterceptor.class));
            InstrumentMethod containsKeyMethod = target.getDeclaredMethod("containsKey", "java.lang.Object");
            containsKeyMethod.addInterceptor(Listeners.of(CacheKeyInterceptor.class));
            InstrumentMethod removeMethod = target.getDeclaredMethod("remove", "java.lang.Object");
            removeMethod.addInterceptor(Listeners.of(CacheKeyInterceptor.class));
            InstrumentMethod removeMethod0 = target.getDeclaredMethod("remove", "java.lang.Object", "java.lang.Object");
            removeMethod0.addInterceptor(Listeners.of(CacheKeyInterceptor.class));
            InstrumentMethod replaceMethod = target.getDeclaredMethod("replace", "java.lang.Object", "java.lang.Object");
            replaceMethod.addInterceptor(Listeners.of(CacheKeyInterceptor.class));
            InstrumentMethod replaceMethod0 = target.getDeclaredMethod("replace", "java.lang.Object", "java.lang.Object", "java.lang.Object");
            replaceMethod0.addInterceptor(Listeners.of(CacheKeyInterceptor.class));
            InstrumentMethod iteratorMethod = target.getDeclaredMethod("iterator");
            iteratorMethod.addInterceptor(Listeners.of(CacheIteratorInterceptor.class));
            InstrumentMethod getAllMethod = target.getDeclaredMethod("getAll", "java.util.Set");
            getAllMethod.addInterceptor(Listeners.of(CacheGetAllRemoveAllInterceptor.class));
            InstrumentMethod getAllMethod0 = target.getDeclaredMethod("getAll", "java.util.Collection");
            getAllMethod0.addInterceptor(Listeners.of(CacheGetAllRemoveAllInterceptor.class));
            InstrumentMethod removeAllMethod = target.getDeclaredMethod("removeAll", "java.util.Set");
            removeAllMethod.addInterceptor(Listeners.of(CacheGetAllRemoveAllInterceptor.class));
        }
    }, "org.ehcache.core.Ehcache", "org.ehcache.core.EhcacheWithLoaderWriter", "org.ehcache.core.PersistentUserManagedEhcache");
    enhanceTemplate.enhance(this, new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod putInternalMethod = target.getDeclaredMethods("put", "putQuiet", "putWithWriter", "putIfAbsent", "removeElement", "replace", "isExpired");
            putInternalMethod.addInterceptor(Listeners.of(CacheKeyInterceptor0.class));
            InstrumentMethod method = target.getDeclaredMethods("get", "getQuiet", "load", "tryRemoveImmediately", "remove", "removeQuiet", "removeWithWriter", "isElementInMemory", "isElementOffHeap", "isElementOnDisk", "isKeyInCache", "asynchronousPut", "asynchronousLoad", "acquireReadLockOnKey", "acquireWriteLockOnKey", "tryReadLockOnKey", "tryWriteLockOnKey", "releaseReadLockOnKey", "releaseWriteLockOnKey", "isReadLockedByCurrentThread", "isWriteLockedByCurrentThread", "");
            method.addInterceptor(Listeners.of(CacheKeyInterceptor1.class));
            InstrumentMethod getKeysMethod = target.getDeclaredMethods("getKeys", "getKeysWithExpiryCheck", "getKeysNoDuplicateCheck");
            getKeysMethod.addInterceptor(Listeners.of(CacheGetKeysInterceptor.class));
            InstrumentMethod getWithLoaderMethod = target.getDeclaredMethod("getWithLoader", "java.lang.Object", "net.sf.ehcache.loader.CacheLoader", "java.lang.Object");
            getWithLoaderMethod.addInterceptor(Listeners.of(CacheGetWithLoaderInterceptor.class));
            InstrumentMethod getAllWithLoaderMethod = target.getDeclaredMethod("getAllWithLoader", "java.util.Collection", "java.lang.Object");
            getAllWithLoaderMethod.addInterceptor(Listeners.of(CacheGetAllWithLoaderInterceptor.class));
            InstrumentMethod loadAllMethod = target.getDeclaredMethod("loadAll", "java.util.Collection", "java.lang.Object");
            loadAllMethod.addInterceptor(Listeners.of(CacheLoadAllInterceptor.class));
            InstrumentMethod collectionMethod = target.getDeclaredMethods("removeAll");
            collectionMethod.addInterceptor(Listeners.of(CacheParameterCollectionInterceptor.class));
            InstrumentMethod putAllMethod = target.getDeclaredMethod("putAll", "java.util.Collection");
            putAllMethod.addInterceptor(Listeners.of(CacheParameterCollectionInterceptor.class));
        }
    }, "net.sf.ehcache.Cache", "net.sf.ehcache.constructs.blocking.BlockingCache");
    enhanceTemplate.enhance(this, "net.sf.ehcache.Element", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            InstrumentMethod getKeyMethod = target.getDeclaredMethods("getKey", "getObjectKey");
            getKeyMethod.addInterceptor(Listeners.of(ElementGetObjectKeyInterceptor.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 30 with InstrumentMethod

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

the class UndertowPlugin method onActive.

@Override
public boolean onActive() throws Throwable {
    enhanceTemplate.enhance(this, "io.undertow.server.Connectors", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            // Entry Point
            final InstrumentMethod connectorsExecuteRootHandlerMethod = target.getDeclaredMethod("executeRootHandler", "io.undertow.server.HttpHandler", "io.undertow.server.HttpServerExchange");
            connectorsExecuteRootHandlerMethod.addInterceptor(Listeners.of(ConnectorsExecuteRootHandlerInterceptor.class));
        }
    });
    enhanceTemplate.enhance(this, "io.undertow.servlet.spec.HttpServletRequestImpl", new EnhanceCallback() {

        @Override
        public void doEnhance(InstrumentClass target) {
            final InstrumentMethod startAsyncMethod = target.getDeclaredMethod("startAsync", "javax.servlet.ServletRequest", "javax.servlet.ServletResponse");
            startAsyncMethod.addInterceptor(Listeners.of(HttpServletRequestImplStartAsyncInterceptor.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