Search in sources :

Example 21 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class SendMessageHookImpl method sendMessageAfter.

@Override
public void sendMessageAfter(SendMessageContext context) {
    try {
        if (context == null || context.getMessage() == null) {
            return;
        }
        MQTraceContext mqTraceContext = (MQTraceContext) context.getMqTraceContext();
        MQTraceBean traceBean = mqTraceContext.getTraceBeans().get(0);
        if (traceBean != null && context.getSendResult() != null) {
            traceBean.setQueueId(context.getMq().getQueueId());
            traceBean.setMsgId(context.getSendResult().getMsgId());
            traceBean.setOffset(context.getSendResult().getQueueOffset());
            mqTraceContext.setSuccess(true);
            mqTraceContext.setStatus(context.getSendResult().getSendStatus().toString());
        } else {
            if (context.getException() != null) {
                String msg = context.getException().getMessage();
                mqTraceContext.setErrorMsg(StringUtils.substring(msg, 0, msg.indexOf("\n")));
            }
        }
        MQSendMessageTraceLog.sendMessageAfter(mqTraceContext);
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : MQTraceContext(com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceContext) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) MQTraceBean(com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceBean)

Example 22 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class ConcurrentlyTraceInterceptor method doBefore.

@Override
public void doBefore(Advice advice) throws Throwable {
    try {
        MessageQueue messageQueue = getMessageQueue(advice.getTarget());
        List<MessageExt> messageExts = getMessages(advice.getTarget());
        String consumeGroup = getConsumeGroup(advice.getTarget());
        if (messageExts == null || messageExts.isEmpty()) {
            return;
        }
        ConsumeMessageContext consumeMessageContext = new ConsumeMessageContext();
        consumeMessageContext.setConsumerGroup(consumeGroup);
        consumeMessageContext.setMq(messageQueue);
        consumeMessageContext.setMsgList(messageExts);
        consumeMessageContext.setSuccess(false);
        hook.consumeMessageBefore(consumeMessageContext);
        contextThreadLocal.set(consumeMessageContext);
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : MessageExt(org.apache.rocketmq.common.message.MessageExt) ConsumeMessageContext(org.apache.rocketmq.client.hook.ConsumeMessageContext) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 23 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class ConsumerPollInterceptor method doWithSpringIntercept.

public void doWithSpringIntercept(Advice advice) {
    try {
        if (!PradarSwitcher.isClusterTestEnabled()) {
            return;
        }
        if (advice.getReturnObj() == null) {
            return;
        }
        ConsumerRecords consumerRecords = (ConsumerRecords) advice.getReturnObj();
        if (consumerRecords.count() <= 0) {
            return;
        }
        Iterator iterator = consumerRecords.iterator();
        Object next = iterator.next();
        if (!(next instanceof ConsumerRecord)) {
            return;
        }
        ConsumerRecord record = (ConsumerRecord) next;
        String topic = record.topic();
        Pradar.setClusterTest(false);
        boolean isClusterTest = Pradar.isClusterTestPrefix(topic);
        if (PradarSwitcher.isKafkaMessageHeadersEnabled()) {
            Headers headers = record.headers();
            Header header = headers.lastHeader(PradarService.PRADAR_CLUSTER_TEST_KEY);
            if (header != null) {
                isClusterTest = isClusterTest || ClusterTestUtils.isClusterTestRequest(BytesUtils.toString(header.value()));
            }
        }
        if (isClusterTest) {
            Pradar.setClusterTest(true);
        }
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : Header(org.apache.kafka.common.header.Header) PradarException(com.pamirs.pradar.exception.PradarException) Headers(org.apache.kafka.common.header.Headers) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) Iterator(java.util.Iterator) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord)

Example 24 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class PullConsumeMessageHookImpl method consumeMessageAfter.

@Override
public void consumeMessageAfter(ConsumeMessageContext context) {
    try {
        if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) {
            return;
        }
        MQTraceContext mqTraceContext = (MQTraceContext) context.getMqTraceContext();
        mqTraceContext.setSuccess(context.isSuccess());
        mqTraceContext.setStatus(context.getStatus());
        MQConsumeMessageTraceLog.consumeMessageAfter(mqTraceContext);
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : MQTraceContext(com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceContext) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 25 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class BeforeTraceInterceptor method doException.

@Override
public final void doException(Advice advice) throws Throwable {
    Object ctx = advice.attachment();
    if (ctx == null) {
        return;
    }
    if (popContextBefore()) {
        return;
    }
    Object currentCtx = Pradar.getInvokeContext();
    Throwable throwable;
    try {
        /**
         * 如果出现异常则从 attachment中获取上下文,然后重建上下文
         */
        Pradar.setInvokeContext(ctx);
        advice.attach(null);
        throwable = null;
        try {
            exceptionFirst(advice);
        } catch (PradarException e) {
            LOGGER.error("TraceInterceptor exceptionFirst exec err:{}", this.getClass().getName(), e);
            throwable = e;
        } catch (PressureMeasureError e) {
            LOGGER.error("TraceInterceptor exceptionFirst exec err:{}", this.getClass().getName(), e);
            throwable = e;
        } catch (Throwable t) {
            LOGGER.error("TraceInterceptor exceptionFirst exec err:{}", this.getClass().getName(), t);
            throwable = t;
        }
        try {
            if (isClient(advice)) {
                endClientInvokeException(advice);
            } else {
                endServerInvokeException(advice);
            }
        } catch (PradarException e) {
            LOGGER.error("TraceInterceptor exception exec err:{}", this.getClass().getName(), e);
            if (Pradar.isClusterTest()) {
                throw e;
            }
        } catch (PressureMeasureError e) {
            LOGGER.error("TraceInterceptor exception exec err:{}", this.getClass().getName(), e);
            if (Pradar.isClusterTest()) {
                throw e;
            }
        } catch (Throwable e) {
            if (Pradar.isClusterTest()) {
                LOGGER.error("TraceInterceptor exception exec err:{}", this.getClass().getName(), e);
                throw new PressureMeasureError(e);
            }
        } finally {
            try {
                exceptionLast(advice);
            } catch (PradarException e) {
                LOGGER.error("TraceInterceptor exceptionLast exec err:{}", this.getClass().getName(), e);
                throwable = e;
            } catch (PressureMeasureError e) {
                LOGGER.error("TraceInterceptor exceptionLast exec err:{}", this.getClass().getName(), e);
                throwable = e;
            } catch (Throwable t) {
                LOGGER.error("TraceInterceptor exceptionLast exec err:{}", this.getClass().getName(), t);
                throwable = t;
            }
        }
    } finally {
        Pradar.setInvokeContext(currentCtx);
    }
    if (throwable != null && Pradar.isClusterTest()) {
        throw throwable;
    }
}
Also used : PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Aggregations

PradarException (com.pamirs.pradar.exception.PradarException)46 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)34 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 ConsumeMessageContext (com.alibaba.rocketmq.client.hook.ConsumeMessageContext)6 MQTraceContext (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceContext)6 ZipException (java.util.zip.ZipException)6 ConsumeMessageContext (org.apache.rocketmq.client.hook.ConsumeMessageContext)6 KeeperException (org.apache.zookeeper.KeeperException)6 MQTraceContext (com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceContext)5 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)4 MQTraceBean (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceBean)4 MQTraceBean (com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceBean)4 InetSocketAddress (java.net.InetSocketAddress)4 MessageExt (org.apache.rocketmq.common.message.MessageExt)4 MQTraceContext (com.pamirs.attach.plugin.pulsar.common.MQTraceContext)3 ConcurrentWeakHashMap (com.shulie.instrument.simulator.message.ConcurrentWeakHashMap)3 List (java.util.List)3 Map (java.util.Map)3 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)3