use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class TraceInterceptor method doAfter.
@Override
public void doAfter(Advice advice) throws Throwable {
if (!simulatorConfig.getBooleanProperty("plugin." + getPluginName() + ".trace.enabled", true)) {
return;
}
ClusterTestUtils.validateClusterTest();
Throwable throwable = null;
try {
afterFirst(advice);
} catch (PradarException e) {
LOGGER.error("TraceInterceptor afterFirst exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (PressureMeasureError e) {
LOGGER.error("TraceInterceptor afterFirst exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (Throwable t) {
LOGGER.error("TraceInterceptor afterFirst exec err:{}", this.getClass().getName(), t);
throwable = t;
}
boolean clusterTest = Pradar.isClusterTest();
try {
if (isClient(advice)) {
endClientInvoke(advice);
} else {
endServerInvoke(advice);
}
} catch (PradarException e) {
LOGGER.error("TraceInterceptor after exec err:{}", this.getClass().getName(), e);
if (clusterTest) {
throw e;
}
} catch (PressureMeasureError e) {
LOGGER.error("TraceInterceptor after exec err:{}", this.getClass().getName(), e);
if (clusterTest) {
throw e;
}
} catch (Throwable e) {
if (clusterTest) {
LOGGER.error("TraceInterceptor after exec err:{}", this.getClass().getName(), e);
throw new PressureMeasureError(e);
}
} finally {
try {
afterLast(advice);
} catch (PradarException e) {
LOGGER.error("TraceInterceptor afterLast exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (PressureMeasureError e) {
LOGGER.error("TraceInterceptor afterLast exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (Throwable t) {
LOGGER.error("TraceInterceptor afterLast exec err:{}", this.getClass().getName(), t);
throwable = t;
}
}
if (throwable != null && clusterTest) {
throw throwable;
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class TraceInterceptor method doException.
@Override
public final void doException(Advice advice) throws Throwable {
if (!simulatorConfig.getBooleanProperty("plugin." + getPluginName() + ".trace.enabled", true)) {
return;
}
Throwable 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;
}
boolean clusterTest = Pradar.isClusterTest();
try {
if (isClient(advice)) {
endClientInvokeException(advice);
} else {
endServerInvokeException(advice);
}
} catch (PradarException e) {
LOGGER.error("TraceInterceptor exception exec err:{}", this.getClass().getName(), e);
if (clusterTest) {
throw e;
}
} catch (PressureMeasureError e) {
LOGGER.error("TraceInterceptor exception exec err:{}", this.getClass().getName(), e);
if (clusterTest) {
throw e;
}
} catch (Throwable e) {
if (clusterTest) {
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;
}
}
if (throwable != null && clusterTest) {
throw throwable;
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class ReverseTraceInterceptor method doAfter.
@Override
public final void doAfter(Advice advice) throws Throwable {
if (!simulatorConfig.getBooleanProperty("plugin." + getPluginName() + ".trace.enabled", true)) {
return;
}
ClusterTestUtils.validateClusterTest();
Throwable throwable = null;
try {
beforeFirst(advice);
} catch (PradarException e) {
LOGGER.error("ReverseTraceInterceptor beforeFirst exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (PressureMeasureError e) {
LOGGER.error("ReverseTraceInterceptor beforeFirst exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (Throwable t) {
LOGGER.error("ReverseTraceInterceptor beforeFirst exec err:{}", this.getClass().getName(), t);
throwable = t;
}
try {
if (isClient(advice)) {
startClientInvoke(advice);
} else {
startServerInvoke(advice);
}
} catch (PradarException e) {
LOGGER.error("ReverseTraceInterceptor before exec err:{}", this.getClass().getName(), e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (PressureMeasureError e) {
LOGGER.error("ReverseTraceInterceptor before exec err:{}", this.getClass().getName(), e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (Throwable e) {
if (Pradar.isClusterTest()) {
LOGGER.error("ReverseTraceInterceptor before exec err:{}", this.getClass().getName(), e);
throw new PressureMeasureError(e);
}
} finally {
try {
beforeLast(advice);
} catch (PradarException e) {
LOGGER.error("ReverseTraceInterceptor beforeLast exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (PressureMeasureError e) {
LOGGER.error("ReverseTraceInterceptor beforeLast exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (Throwable t) {
LOGGER.error("ReverseTraceInterceptor beforeLast exec err:{}", this.getClass().getName(), t);
throwable = t;
}
}
if (throwable != null && Pradar.isClusterTest()) {
throw throwable;
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class PullConsumeMessageHookImpl method consumeMessageBefore.
@Override
public void consumeMessageBefore(ConsumeMessageContext context) {
try {
if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) {
return;
}
MQTraceContext mqTraceContext = new MQTraceContext();
context.setMqTraceContext(mqTraceContext);
mqTraceContext.setMqType(MQType.ROCKETMQ);
mqTraceContext.setGroup(context.getConsumerGroup());
boolean silence = PradarService.isSilence();
List<MQTraceBean> beans = new ArrayList<MQTraceBean>();
for (MessageExt msg : context.getMsgList()) {
if (msg == null) {
continue;
}
MQTraceBean traceBean = new MQTraceBean();
Map<String, String> rpcContext = new HashMap<String, String>();
for (String key : Pradar.getInvokeContextTransformKeys()) {
String value = msg.getProperty(key);
if (value != null) {
rpcContext.put(key, value);
}
}
traceBean.setContext(rpcContext);
traceBean.setTopic(msg.getTopic());
traceBean.setMsgId(msg.getMsgId());
traceBean.setOriginMsgId(MessageAccessor.getOriginMessageId(msg));
traceBean.setTags(msg.getTags());
traceBean.setKeys(msg.getKeys());
traceBean.setBuyerId(msg.getBuyerId());
traceBean.setTransferFlag(MessageAccessor.getTransferFlag(msg));
traceBean.setCorrectionFlag(MessageAccessor.getCorrectionFlag(msg));
traceBean.setBodyLength(msg.getBody().length);
traceBean.setBornHost(StringUtils.substring(msg.getBornHost().toString(), 1));
String storeHost = "";
String port = "";
if (msg.getStoreHost() != null && msg.getStoreHost() instanceof InetSocketAddress) {
InetSocketAddress address = (InetSocketAddress) msg.getStoreHost();
storeHost = address.getAddress() == null ? null : address.getAddress().getHostAddress();
port = String.valueOf(address.getPort());
} else {
storeHost = StringUtils.substring(msg.getStoreHost().toString(), 1);
}
traceBean.setStoreHost(storeHost);
traceBean.setPort(port);
traceBean.setStoreTime(msg.getStoreTimestamp());
traceBean.setBrokerName(context.getMq().getBrokerName());
traceBean.setQueueId(msg.getQueueId());
traceBean.setOffset(msg.getQueueOffset());
traceBean.setRetryTimes(msg.getReconsumeTimes());
traceBean.setProps(context.getProps());
traceBean.setClusterTest(msg.getProperty(PradarService.PRADAR_CLUSTER_TEST_KEY));
boolean isClusterTest = msg.getTopic() != null && (Pradar.isClusterTestPrefix(msg.getTopic()) || Pradar.isClusterTestPrefix(msg.getTopic(), RETRYSTR) || Pradar.isClusterTestPrefix(msg.getTopic(), DLQSTR));
// 消息的properties是否包含Pradar.PRADAR_CLUSTER_TEST_KEY
isClusterTest = isClusterTest || ClusterTestUtils.isClusterTestRequest(msg.getProperty(PradarService.PRADAR_CLUSTER_TEST_KEY));
if (isClusterTest) {
traceBean.setClusterTest(Boolean.TRUE.toString());
}
if (silence && isClusterTest) {
throw new PressureMeasureError(this.getClass().getName() + ":silence module ! can not handle cluster test data");
}
beans.add(traceBean);
}
mqTraceContext.setTraceBeans(beans);
MQConsumeMessageTraceLog.consumeMessageBefore(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);
}
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class PushConsumeMessageHookImpl method consumeMessageBefore.
@Override
public void consumeMessageBefore(ConsumeMessageContext context) {
try {
if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) {
return;
}
MQTraceContext mqTraceContext = new MQTraceContext();
context.setMqTraceContext(mqTraceContext);
mqTraceContext.setMqType(MQType.ROCKETMQ);
mqTraceContext.setGroup(context.getConsumerGroup());
boolean silence = PradarService.isSilence();
List<MQTraceBean> beans = new ArrayList<MQTraceBean>();
for (MessageExt msg : context.getMsgList()) {
if (msg == null) {
continue;
}
MQTraceBean traceBean = new MQTraceBean();
Map<String, String> rpcContext = new HashMap<String, String>();
for (String key : Pradar.getInvokeContextTransformKeys()) {
String value = msg.getProperty(key);
if (value != null) {
rpcContext.put(key, value);
}
}
traceBean.setContext(rpcContext);
traceBean.setTopic(msg.getTopic());
traceBean.setMsgId(msg.getMsgId());
traceBean.setOriginMsgId(MessageAccessor.getOriginMessageId(msg));
traceBean.setTags(msg.getTags());
traceBean.setKeys(msg.getKeys());
traceBean.setBuyerId(msg.getBuyerId());
traceBean.setTransferFlag(MessageAccessor.getTransferFlag(msg));
traceBean.setCorrectionFlag(MessageAccessor.getCorrectionFlag(msg));
traceBean.setBodyLength(msg.getBody().length);
traceBean.setBornHost(StringUtils.substring(msg.getBornHost().toString(), 1));
String storeHost = "";
String port = "";
if (msg.getStoreHost() != null && msg.getStoreHost() instanceof InetSocketAddress) {
InetSocketAddress address = (InetSocketAddress) msg.getStoreHost();
storeHost = address.getAddress() == null ? null : address.getAddress().getHostAddress();
port = String.valueOf(address.getPort());
} else {
storeHost = StringUtils.substring(msg.getStoreHost().toString(), 1);
}
traceBean.setStoreHost(storeHost);
traceBean.setStoreTime(msg.getStoreTimestamp());
traceBean.setBrokerName(context.getMq().getBrokerName());
traceBean.setQueueId(msg.getQueueId());
traceBean.setOffset(msg.getQueueOffset());
traceBean.setRetryTimes(msg.getReconsumeTimes());
traceBean.setProps(context.getProps());
/**
* 如果有压测标则设置压测标,没有则根据topic是否是PT_开头,如果是则设置为压测流量
*/
boolean isClusterTest = msg.getTopic() != null && (Pradar.isClusterTestPrefix(msg.getTopic()) || Pradar.isClusterTestPrefix(msg.getTopic(), RETRYSTR) || Pradar.isClusterTestPrefix(msg.getTopic(), DLQSTR));
// 消息的properties是否包含Pradar.PRADAR_CLUSTER_TEST_KEY
isClusterTest = isClusterTest || ClusterTestUtils.isClusterTestRequest(msg.getProperty(PradarService.PRADAR_CLUSTER_TEST_KEY));
if (isClusterTest) {
traceBean.setClusterTest(Boolean.TRUE.toString());
}
if (silence && isClusterTest) {
throw new PressureMeasureError(this.getClass().getName() + ":silence module ! can not handle cluster test data");
}
beans.add(traceBean);
}
mqTraceContext.setTraceBeans(beans);
MQConsumeMessageTraceLog.consumeMessageBefore(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);
}
}
}
Aggregations