Search in sources :

Example 6 with ReflectException

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

the class RealCallExecuteV2Interceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    InnerWhiteListCheckUtil.check();
    Object target = advice.getTarget();
    Request request = null;
    try {
        request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_REQUEST);
    } catch (ReflectException e) {
        request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_ORIGINAL_REQUEST);
    }
    SpanRecord record = new SpanRecord();
    record.setRemoteIp(request.url().getHost());
    record.setService(request.url().getPath());
    record.setMethod(StringUtils.upperCase(request.method()));
    record.setRemoteIp(request.url().getHost());
    record.setPort(request.url().getPort());
    record.setRequest(request.url().getQuery());
    String header = request.header("content-length");
    if (StringUtils.isNotBlank(header) && NumberUtils.isDigits(header)) {
        try {
            record.setRequestSize(Integer.valueOf(header));
        } catch (NumberFormatException e) {
        }
    }
    return record;
}
Also used : SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) Request(com.squareup.okhttp.Request) JSONObject(com.alibaba.fastjson.JSONObject) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException)

Example 7 with ReflectException

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

the class QueueingConsumerHandleInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    if (args == null || args.length == 0 || args[0] == null) {
        return null;
    }
    Object target = advice.getTarget();
    Class<?>[] classes = target.getClass().getClasses();
    if (classes.length != 1) {
        return null;
    }
    Object deliveryObj = args[0];
    if (deliveryObj == null) {
        return null;
    }
    SpanRecord record = new SpanRecord();
    try {
        Envelope envelope = Reflect.on(deliveryObj).get(RabbitmqConstants.DYNAMIC_FIELD_ENVELOPE);
        if (envelope == null) {
            // 说明是毒药,已经报错了
            return null;
        }
        record.setService(envelope.getExchange());
        record.setMethod(envelope.getRoutingKey());
    } catch (ReflectException e) {
    }
    try {
        AMQP.BasicProperties properties = Reflect.on(deliveryObj).get(RabbitmqConstants.DYNAMIC_FIELD_PROPERTIES);
        Map<String, Object> headers = properties.getHeaders();
        if (headers != null) {
            Map<String, String> rpcContext = new HashMap<String, String>();
            for (String key : Pradar.getInvokeContextTransformKeys()) {
                Object tmp = headers.get(key);
                if (tmp != null) {
                    String value = tmp.toString();
                    if (!StringUtil.isEmpty(value)) {
                        rpcContext.put(key, value);
                    }
                }
            }
            record.setContext(rpcContext);
        }
    } catch (ReflectException e) {
    }
    try {
        byte[] body = Reflect.on(deliveryObj).get(RabbitmqConstants.DYNAMIC_FIELD_BODY);
        record.setRequestSize(body.length);
        record.setRequest(body);
    } catch (ReflectException e) {
    }
    return record;
}
Also used : HashMap(java.util.HashMap) Envelope(com.rabbitmq.client.Envelope) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) AMQP(com.rabbitmq.client.AMQP)

Example 8 with ReflectException

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

the class SpringBlockingQueueConsumerDeliveryInterceptorV2 method initPropertiesField.

void initPropertiesField(Class deliveryClass) {
    if (propertiesField != null) {
        return;
    }
    try {
        propertiesField = deliveryClass.getDeclaredField("properties");
        propertiesField.setAccessible(true);
    } catch (NoSuchFieldException e) {
        throw new ReflectException(e);
    }
}
Also used : ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException)

Example 9 with ReflectException

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

the class HessianServiceExporterHandleRequestInterceptor method beforeTrace.

@Override
public SpanRecord beforeTrace(Advice advice) {
    Object[] args = advice.getParameterArray();
    Object target = advice.getTarget();
    if (args == null || args.length == 0) {
        return null;
    }
    if (!(args[0] instanceof HttpServletRequest)) {
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError("hessian servlet trace err! can't cast to HttpServletRequest");
        }
        return null;
    }
    WrapperRequest request = (WrapperRequest) args[0];
    if (!request.getMethod().equals("POST") && !request.getMethod().equals("post")) {
        return null;
    }
    String method = request.getHeader(HessianConstants.METHOD_HEADER);
    if (method != null && isSkip(method)) {
        return null;
    }
    HessianServiceExporter serviceExporter = (HessianServiceExporter) target;
    HessianSkeleton hessianSkeleton = null;
    try {
        hessianSkeleton = Reflect.on(serviceExporter).get(HessianConstants.DYNAMIC_FIELD_OBJECT_SKELETON);
    } catch (ReflectException e) {
    }
    SerializerFactory serializerFactory = null;
    try {
        serializerFactory = Reflect.on(serviceExporter).get(HessianConstants.DYNAMIC_FIELD_SERIALIZER_FACTORY);
    } catch (ReflectException e) {
    }
    Object[] result = getMethodArgs(request.getInputStream(), serializerFactory, hessianSkeleton);
    Object[] arguments = (Object[]) result[1];
    if (method == null) {
        method = (String) result[0];
    }
    Class<?> clazz = serviceExporter.getServiceInterface();
    SpanRecord spanRecord = new SpanRecord();
    spanRecord.setService(clazz.getName());
    spanRecord.setMethod(method);
    spanRecord.setRequest(arguments);
    return spanRecord;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SpanRecord(com.pamirs.pradar.interceptor.SpanRecord) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) WrapperRequest(com.pamirs.attach.plugin.hessian.common.WrapperRequest) HessianSkeleton(com.caucho.hessian.server.HessianSkeleton) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) HessianServiceExporter(org.springframework.remoting.caucho.HessianServiceExporter)

Example 10 with ReflectException

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

the class ChannelHolder method getThreadPoolInfoFromBiz.

private static ThreadPoolInfo getThreadPoolInfoFromBiz(Connection connection) {
    if (connection instanceof AMQConnection) {
        try {
            ConsumerWorkService workService = Reflect.on(connection).get("_workService");
            ExecutorService executorService = Reflect.on(workService).get("executor");
            if (executorService instanceof ThreadPoolExecutor) {
                ThreadPoolExecutor te = (ThreadPoolExecutor) executorService;
                int queueSize = getQueueSize(te.getQueue());
                if (isInfoEnabled) {
                    LOGGER.info("[RabbitMQ] biz consumer use thread pool info : [coreSize : {}, maxSize : {}, keepAliveTime : " + "{} " + "queueSize : {}]", te.getCorePoolSize(), te.getMaximumPoolSize(), te.getKeepAliveTime(TimeUnit.SECONDS), queueSize);
                }
                return new ThreadPoolInfo(te.getCorePoolSize(), te.getMaximumPoolSize(), (int) te.getKeepAliveTime(TimeUnit.SECONDS), queueSize);
            }
        } catch (Exception e) {
            LOGGER.warn("[RabbitMQ]  can not get executor from connection" + " try set max pool size equal channel num connection is : {}", connection.getClass().getName(), e);
            try {
                ChannelManager channelManager = Reflect.on(connection).get("_channelManager");
                Map map = Reflect.on(channelManager).get("_channelMap");
                return new ThreadPoolInfo(map.size(), map.size(), 10, Integer.MAX_VALUE);
            } catch (ReflectException ex) {
                LOGGER.warn("[RabbitMQ]  can not get channels from connection connection is : {}", connection.getClass().getName(), e);
            }
        }
    }
    return null;
}
Also used : ChannelManager(com.rabbitmq.client.impl.ChannelManager) AMQConnection(com.rabbitmq.client.impl.AMQConnection) ExecutorService(java.util.concurrent.ExecutorService) ConsumerWorkService(com.rabbitmq.client.impl.ConsumerWorkService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) TimeoutException(java.util.concurrent.TimeoutException) ReflectException(com.shulie.instrument.simulator.api.reflect.ReflectException) IOException(java.io.IOException)

Aggregations

ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)33 SpanRecord (com.pamirs.pradar.interceptor.SpanRecord)11 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)6 IOException (java.io.IOException)6 Map (java.util.Map)6 JSONObject (com.alibaba.fastjson.JSONObject)4 Request (com.squareup.okhttp.Request)4 HashMap (java.util.HashMap)4 WrapperRequest (com.pamirs.attach.plugin.hessian.common.WrapperRequest)3 MatchConfig (com.pamirs.pradar.internal.config.MatchConfig)3 ProcessControlException (com.shulie.instrument.simulator.api.ProcessControlException)3 Method (java.lang.reflect.Method)3 URL (java.net.URL)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HessianInputFactory (com.caucho.hessian.io.HessianInputFactory)2 HessianSkeleton (com.caucho.hessian.server.HessianSkeleton)2 ExecutionForwardCall (com.pamirs.pradar.internal.adapter.ExecutionForwardCall)2 AMQP (com.rabbitmq.client.AMQP)2 Envelope (com.rabbitmq.client.Envelope)2 Headers (com.squareup.okhttp.Headers)2