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 = (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);
}
}
}
use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.
the class MongoOperationUtil method generateWriteOperationWithShadowDb.
public static WriteOperation generateWriteOperationWithShadowDb(final WriteOperation operation, Mongo businessMongo) {
if (operation instanceof InsertOperation) {
if (Pradar.isClusterTestPrefix(((InsertOperation) operation).getNamespace().getDatabaseName()) || Pradar.isClusterTestPrefix(((InsertOperation) operation).getNamespace().getCollectionName())) {
return operation;
}
MongoNamespace ptNamespace;
ptNamespace = new MongoNamespace(Pradar.addClusterTestPrefix(((InsertOperation) operation).getNamespace().getDatabaseName()), ((InsertOperation) operation).getNamespace().getCollectionName());
return new InsertOperation(ptNamespace, ((InsertOperation) operation).isOrdered(), ((InsertOperation) operation).getWriteConcern(), retryWrites, ((InsertOperation) operation).getInsertRequests()).bypassDocumentValidation(((InsertOperation) operation).getBypassDocumentValidation());
} else if (operation instanceof UpdateOperation) {
if (Pradar.isClusterTestPrefix(((UpdateOperation) operation).getNamespace().getDatabaseName()) || Pradar.isClusterTestPrefix(((UpdateOperation) operation).getNamespace().getCollectionName())) {
return operation;
}
MongoNamespace ptNamespace;
ptNamespace = new MongoNamespace(Pradar.addClusterTestPrefix(((UpdateOperation) operation).getNamespace().getDatabaseName()), ((UpdateOperation) operation).getNamespace().getCollectionName());
return new UpdateOperation(ptNamespace, ((UpdateOperation) operation).isOrdered(), ((UpdateOperation) operation).getWriteConcern(), retryWrites, ((UpdateOperation) operation).getUpdateRequests()).bypassDocumentValidation(((UpdateOperation) operation).getBypassDocumentValidation());
} else if (operation instanceof DeleteOperation) {
if (Pradar.isClusterTestPrefix(((DeleteOperation) operation).getNamespace().getDatabaseName()) || Pradar.isClusterTestPrefix(((DeleteOperation) operation).getNamespace().getCollectionName())) {
return operation;
}
MongoNamespace ptNamespace;
ptNamespace = new MongoNamespace(Pradar.addClusterTestPrefix(((DeleteOperation) operation).getNamespace().getDatabaseName()), ((DeleteOperation) operation).getNamespace().getCollectionName());
return new DeleteOperation(ptNamespace, ((DeleteOperation) operation).isOrdered(), ((DeleteOperation) operation).getWriteConcern(), retryWrites, ((DeleteOperation) operation).getDeleteRequests()).bypassDocumentValidation(((DeleteOperation) operation).getBypassDocumentValidation());
} else if (operation instanceof MixedBulkWriteOperation) {
if (Pradar.isClusterTestPrefix(((MixedBulkWriteOperation) operation).getNamespace().getDatabaseName()) || Pradar.isClusterTestPrefix(((MixedBulkWriteOperation) operation).getNamespace().getCollectionName())) {
return operation;
}
MongoNamespace ptNamespace;
ptNamespace = new MongoNamespace(Pradar.addClusterTestPrefix(((MixedBulkWriteOperation) operation).getNamespace().getDatabaseName()), ((MixedBulkWriteOperation) operation).getNamespace().getCollectionName());
return new MixedBulkWriteOperation(ptNamespace, ((MixedBulkWriteOperation) operation).getWriteRequests(), ((MixedBulkWriteOperation) operation).isOrdered(), ((MixedBulkWriteOperation) operation).getWriteConcern(), retryWrites).bypassDocumentValidation(((MixedBulkWriteOperation) operation).getBypassDocumentValidation());
} else {
throw new PressureMeasureError("压测下 mongodb Operation is not support ");
}
}
use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.
the class DelegateOperationExecutorInterceptor method setWritePtMongoNamespace.
private void setWritePtMongoNamespace(Object operation, OperationAccessor operationAccessor, ShadowDatabaseConfig shadowDatabaseConfig) throws Exception {
// 写操作未配置则直接抛异常
MongoNamespace busMongoNamespace = operationAccessor.getMongoNamespace(operation);
String shadowTableName = getShadowTableName(shadowDatabaseConfig, busMongoNamespace.getCollectionName());
if (shadowTableName == null) {
ErrorReporter.Error error = ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0005").setMessage("mongo 未配置对应影子表4:" + busMongoNamespace.getFullName()).setDetail("mongo 未配置对应影子表4:" + busMongoNamespace.getFullName());
error.closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS);
error.report();
throw new PressureMeasureError("mongo 未配置对应影子表4:" + busMongoNamespace.getFullName());
}
MongoNamespace ptMongoNamespace = new MongoNamespace(busMongoNamespace.getDatabaseName(), shadowTableName);
operationAccessor.setMongoNamespace(operation, ptMongoNamespace);
}
use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.
the class BeforeTraceInterceptor method startClientInvoke.
/**
* 开始客户端调用
*
* @param advice
*/
private void startClientInvoke(Advice advice) {
boolean traceEnabled = true;
SpanRecord record = null;
try {
record = beforeTrace(advice);
if (record == null) {
traceEnabled = false;
return;
}
Pradar.startClientInvoke(record.getService(), record.getMethod());
advice.mark(BEFORE_TRACE_SUCCESS);
InvokeContext invokeContext = Pradar.getInvokeContext();
if (invokeContext == null) {
return;
}
if (record.getRequestSize() != 0) {
invokeContext.setRequestSize(record.getRequestSize());
}
if (Pradar.isRequestOn()) {
invokeContext.setRequest(record.getRequest());
}
if (StringUtils.isNotBlank(record.getRemoteIp())) {
invokeContext.setRemoteIp(record.getRemoteIp());
}
if (StringUtils.isNotBlank(record.getPort())) {
invokeContext.setPort(record.getPort());
}
if (record.getCallbackMsg() != null) {
invokeContext.setCallBackMsg(record.getCallbackMsg());
}
if (advice.getThrowable() != null) {
invokeContext.setResponse(advice.getThrowable());
Pradar.setError(true);
}
if (record.getMiddlewareName() == null) {
invokeContext.setMiddlewareName(getPluginName());
} else {
invokeContext.setMiddlewareName(record.getMiddlewareName());
}
} finally {
if (traceEnabled) {
try {
ContextTransfer contextTransfer = getContextTransfer(advice);
if (contextTransfer != null) {
Map<String, String> contextMap = Pradar.getInvokeContextTransformMap();
for (Map.Entry<String, String> entry : contextMap.entrySet()) {
contextTransfer.transfer(entry.getKey(), entry.getValue());
}
}
} catch (Throwable e) {
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(e);
}
LOGGER.error("AGENT: {} trace context transfer err, trace context may be lost.", getClass().getName(), e);
}
if (record != null && record.getContextInject() != null) {
Map<String, String> ctx = Pradar.getInvokeContextMap();
advice.attach(ctx);
record.getContextInject().injectContext(ctx);
}
}
}
}
use of com.pamirs.pradar.exception.PressureMeasureError 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;
}
}
Aggregations