Search in sources :

Example 76 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 = (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 77 with PressureMeasureError

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 ");
    }
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) MongoNamespace(com.mongodb.MongoNamespace)

Example 78 with PressureMeasureError

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);
}
Also used : ErrorReporter(com.pamirs.pradar.pressurement.agent.shared.service.ErrorReporter) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) MongoNamespace(com.mongodb.MongoNamespace)

Example 79 with PressureMeasureError

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);
            }
        }
    }
}
Also used : InvokeContext(com.pamirs.pradar.InvokeContext) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) Map(java.util.Map)

Example 80 with PressureMeasureError

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;
    }
}
Also used : PradarException(com.pamirs.pradar.exception.PradarException) 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