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);
}
}
}
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);
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
Aggregations