Search in sources :

Example 36 with PressureMeasureError

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

the class SendMessageHookImpl method sendMessageBefore.

@Override
public void sendMessageBefore(SendMessageContext context) {
    try {
        if (context == null || context.getMessage() == null) {
            return;
        }
        Message message = context.getMessage();
        if (message == null) {
            return;
        }
        ClusterTestUtils.validateClusterTest();
        MQTraceBean traceBean = new MQTraceBean();
        traceBean.setTopic(message.getTopic());
        traceBean.setOriginMsgId(MessageAccessor.getOriginMessageId(message));
        traceBean.setTags(message.getTags());
        traceBean.setKeys(message.getKeys());
        traceBean.setBuyerId(message.getBuyerId());
        traceBean.setTransferFlag(MessageAccessor.getTransferFlag(message));
        traceBean.setCorrectionFlag(MessageAccessor.getCorrectionFlag(message));
        traceBean.setBodyLength(message.getBody().length);
        traceBean.setBornHost(context.getBornHost());
        String brokerAddr = context.getBrokerAddr();
        String port = "";
        int index = -1;
        if (brokerAddr != null && (index = brokerAddr.indexOf(':')) != -1) {
            port = brokerAddr.substring(index + 1);
            brokerAddr = brokerAddr.substring(0, index);
        }
        traceBean.setStoreHost(brokerAddr);
        traceBean.setPort(port);
        traceBean.setBrokerName(context.getMq().getBrokerName());
        // 上游AppName,记录当前应用的AppName
        traceBean.setProps(context.getProps());
        ArrayList<MQTraceBean> traceBeans = new ArrayList<MQTraceBean>(1);
        traceBeans.add(traceBean);
        MQTraceContext mqTraceContext = new MQTraceContext();
        contexts.put(context, mqTraceContext);
        mqTraceContext.setMqType(MQType.ROCKETMQ);
        mqTraceContext.setTopic(context.getMq().getTopic());
        mqTraceContext.setGroup(context.getProducerGroup());
        mqTraceContext.setAsync(CommunicationMode.ASYNC == context.getCommunicationMode());
        mqTraceContext.setTraceBeans(traceBeans);
        Map<String, String> rpcContext = new HashMap<String, String>();
        for (String key : Pradar.getInvokeContextTransformKeys()) {
            String value = message.getProperty(key);
            if (value != null) {
                rpcContext.put(key, value);
            }
        }
        traceBean.setContext(rpcContext);
        traceBean.setClusterTest(message.getUserProperty(PradarService.PRADAR_CLUSTER_TEST_KEY));
        MQSendMessageTraceLog.sendMessageBefore(mqTraceContext);
        for (Map.Entry<String, String> entry : traceBean.getContext().entrySet()) {
            putUserProperty(message, entry.getKey(), entry.getValue());
        }
    } 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 : Message(com.alibaba.rocketmq.common.message.Message) PradarException(com.pamirs.pradar.exception.PradarException) HashMap(java.util.HashMap) ConcurrentWeakHashMap(com.shulie.instrument.simulator.message.ConcurrentWeakHashMap) ArrayList(java.util.ArrayList) MQTraceBean(com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceBean) MQTraceContext(com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceContext) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentWeakHashMap(com.shulie.instrument.simulator.message.ConcurrentWeakHashMap)

Example 37 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError 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 = contexts.remove(context);
        if (mqTraceContext == null) {
            return;
        }
        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.alibaba.rocketmq.common.MQTraceContext) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) MQTraceBean(com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceBean)

Example 38 with PressureMeasureError

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

the class AbstractUseShadowConsumerReplaceInterceptor method cutoff0.

@Override
public CutOffResult cutoff0(Advice advice) {
    if (!Pradar.isClusterTest()) {
        return CutOffResult.passed();
    }
    /**
     * 主要负责Consumer 注册,每一批的消息消费都会经过此方法
     * 如果是已经注册过的,则忽略
     */
    DefaultMQPushConsumer defaultMQPushConsumer = (DefaultMQPushConsumer) advice.getTarget();
    /**
     * 如果影子消费者,也忽略
     */
    if (ConsumerRegistry.isShadowConsumer(defaultMQPushConsumer)) {
        return CutOffResult.passed();
    }
    if (!ConsumerRegistry.hasRegistered(defaultMQPushConsumer)) {
        throw new PressureMeasureError(String.format("Alibaba-RocketMQ: %s err, can't found shadow consumer, queue: %s ", advice.getBehaviorName(), advice.getParameterArray()[0]));
    }
    DefaultMQPushConsumer consumer = ConsumerRegistry.getConsumer(defaultMQPushConsumer);
    if (consumer == null) {
        throw new PressureMeasureError("Alibaba-RocketMQ: shadow consumer is null this should never happened!");
    }
    return execute(consumer, advice);
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) DefaultMQPushConsumer(com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer)

Example 39 with PressureMeasureError

use of com.pamirs.pradar.exception.PressureMeasureError 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 = contexts.remove(context);
        if (mqTraceContext == null) {
            return;
        }
        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.alibaba.rocketmq.common.MQTraceContext) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 40 with PressureMeasureError

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

the class OrderlyTraceAfterInterceptor method doAfter.

@Override
public void doAfter(Advice advice) throws Throwable {
    try {
        ConsumeOrderlyStatus status = (ConsumeOrderlyStatus) advice.getParameterArray()[1];
        ConsumeMessageContext consumeMessageContext = OrderlyTraceContexts.get();
        if (consumeMessageContext == null || consumeMessageContext.getMsgList() == null) {
            return;
        }
        consumeMessageContext.setSuccess(ConsumeOrderlyStatus.SUCCESS == status || ConsumeOrderlyStatus.COMMIT == status);
        consumeMessageContext.setStatus(status.name());
        hook.consumeMessageAfter(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);
        }
    } finally {
        OrderlyTraceContexts.remove();
    }
}
Also used : ConsumeMessageContext(com.alibaba.rocketmq.client.hook.ConsumeMessageContext) PradarException(com.pamirs.pradar.exception.PradarException) ConsumeOrderlyStatus(com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyStatus) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Aggregations

PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)150 PradarException (com.pamirs.pradar.exception.PradarException)34 DataSourceMeta (com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)14 Connection (java.sql.Connection)14 SQLException (java.sql.SQLException)13 ArrayList (java.util.ArrayList)13 Map (java.util.Map)11 MatchConfig (com.pamirs.pradar.internal.config.MatchConfig)8 ShadowDatabaseConfig (com.pamirs.pradar.internal.config.ShadowDatabaseConfig)8 HashMap (java.util.HashMap)8 MongoNamespace (com.mongodb.MongoNamespace)7 RequestIndexRename (com.pamirs.attach.plugin.es.common.RequestIndexRename)7 ProcessControlException (com.shulie.instrument.simulator.api.ProcessControlException)7 MQTraceContext (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceContext)6 SpanRecord (com.pamirs.pradar.interceptor.SpanRecord)6 ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)6 List (java.util.List)6 ConsumeMessageContext (org.apache.rocketmq.client.hook.ConsumeMessageContext)6 ConsumeMessageContext (com.alibaba.rocketmq.client.hook.ConsumeMessageContext)5 WrapperRequest (com.pamirs.attach.plugin.hessian.common.WrapperRequest)5