Search in sources :

Example 16 with PressureMeasureError

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

the class RedisDataCheckInterceptor method validateKeys.

private void validateKeys(List<String> keys, String methodName) {
    for (int i = 0, size = keys.size(); i < size; i++) {
        String key = keys.get(i);
        boolean isCluster = Pradar.isClusterTest();
        boolean withPt = Pradar.isClusterTestPrefix(key);
        if (isCluster && !withPt) {
            throw new PressureMeasureError("jedis:压测流量进入业务库...,key = " + key + ", methodName=" + methodName);
        } else if (!isCluster && withPt) {
            throw new PressureMeasureError("jedis:业务流量进入压测库,key = " + key + ", methodName=" + methodName);
        }
    }
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 17 with PressureMeasureError

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

the class ChannelNBasicGetInterceptor method doBefore.

@Override
public void doBefore(Advice advice) {
    Object[] args = advice.getParameterArray();
    String queue = (String) args[0];
    // 压测代码-
    try {
        if (PradarSwitcher.isClusterTestEnabled()) {
            validatePressureMeasurement(queue);
        }
    } catch (Throwable e) {
        throw new PressureMeasureError(e);
    }
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 18 with PressureMeasureError

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

the class ChannelNProcessDeliveryInterceptor method validatePressureMeasurement.

private void validatePressureMeasurement(String consumerTag) {
    try {
        Pradar.setClusterTest(false);
        consumerTag = StringUtils.trimToEmpty(consumerTag);
        if (Pradar.isClusterTestPrefix(consumerTag)) {
            Pradar.setClusterTest(true);
        }
    } catch (Throwable e) {
        logger.error("rabbitmq validate pressure request err!", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 19 with PressureMeasureError

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

the class ChannelNProcessDeliveryInterceptor method beforeFirst.

@Override
public void beforeFirst(Advice advice) {
    Object[] args = advice.getParameterArray();
    String methodName = advice.getBehaviorName();
    if (!PradarSwitcher.isClusterTestEnabled()) {
        logger.warn("PradarSwitcher isClusterTestEnabled false, {} to start shadow {} skip it", advice.getTargetClass().getName(), methodName);
        return;
    }
    AMQP.Basic.Deliver m = (AMQP.Basic.Deliver) args[1];
    validatePressureMeasurement(m.getConsumerTag());
    try {
        Command command = (Command) args[0];
        BasicProperties contentHeader = (BasicProperties) command.getContentHeader();
        Map<String, Object> headers = contentHeader.getHeaders();
        if (null != headers && headers.get(PradarService.PRADAR_CLUSTER_TEST_KEY) != null && ClusterTestUtils.isClusterTestRequest(headers.get(PradarService.PRADAR_CLUSTER_TEST_KEY).toString())) {
            Pradar.setClusterTest(true);
        }
        if (!Pradar.isClusterTest()) {
            String routingKey = m.getRoutingKey();
            if (StringUtils.isNotBlank(routingKey) && ClusterTestUtils.isClusterTestRequest(routingKey)) {
                Pradar.setClusterTest(true);
            }
            String exchange = m.getExchange();
            if (StringUtils.isNotBlank(exchange) && ClusterTestUtils.isClusterTestRequest(exchange)) {
                Pradar.setClusterTest(true);
            }
        }
    } catch (Throwable e) {
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : Deliver(com.rabbitmq.client.impl.AMQImpl.Basic.Deliver) AMQP(com.rabbitmq.client.AMQP) Command(com.rabbitmq.client.Command) BasicProperties(com.rabbitmq.client.BasicProperties) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Example 20 with PressureMeasureError

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

the class DataSourceGetConnectionArgsCutoffInterceptor method cutoff0.

@Override
public CutOffResult cutoff0(Advice advice) {
    attachment(advice);
    Object target = advice.getTarget();
    ComboPooledDataSource dataSource = (ComboPooledDataSource) target;
    DataSourceMeta<ComboPooledDataSource> dataSourceMeta = new DataSourceMeta<ComboPooledDataSource>(dataSource.getJdbcUrl(), dataSource.getUser(), dataSource);
    ClusterTestUtils.validateClusterTest();
    DataSourceWrapUtil.init(dataSourceMeta);
    Connection connection = null;
    /**
     * 所有的流量均切换到此逻辑上,防止业务有连接缓存后无法进入
     * 如果未找到配置情况下则当前流量为压测流量时返回null,非压测流量则执行业务连接池正常逻辑,此种情况可能由于数据源未配置的情况
     * 如果获取连接出错时如果流量为压测流量则返回null,非压测流量则执行业务连接池正常逻辑
     */
    if (DataSourceWrapUtil.pressureDataSources.containsKey(dataSourceMeta)) {
        C3p0MediaDataSource mediatorDataSource = DataSourceWrapUtil.pressureDataSources.get(dataSourceMeta);
        if (mediatorDataSource != null) {
            try {
                connection = mediatorDataSource.getConnection();
            } catch (SQLException e) {
                throw new PressureMeasureError(e);
            }
        } else {
            if (!Pradar.isClusterTest()) {
                return CutOffResult.passed();
            }
        }
        return CutOffResult.cutoff(connection);
    } else {
        if (!Pradar.isClusterTest()) {
            return CutOffResult.passed();
        }
        return CutOffResult.cutoff(null);
    }
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) SQLException(java.sql.SQLException) C3p0MediaDataSource(com.pamirs.attach.plugin.c3p0.utils.C3p0MediaDataSource) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) Connection(java.sql.Connection) DataSourceMeta(com.pamirs.pradar.pressurement.agent.shared.service.DataSourceMeta)

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