use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.
the class Neo4jSessionConstructorInterceptor method afterLast.
@Override
public void afterLast(Advice advice) {
Object[] args = advice.getParameterArray();
Object target = advice.getTarget();
/**
* 压测状态判断
* 影子session回调
*/
if (!PradarSwitcher.isClusterTestEnabled() || target instanceof Neo4JSessionExt) {
return;
}
try {
// 业务库session
Neo4jSession sourceSession = (Neo4jSession) target;
DriverConfiguration driverConfiguration = ((HttpDriver) args[1]).getConfiguration();
String s = driverConfiguration.getURI();
Credentials credentials = driverConfiguration.getCredentials();
String username = null;
if (credentials instanceof AuthTokenCredentials) {
username = ((AuthTokenCredentials) credentials).credentials();
} else if (credentials instanceof UsernamePasswordCredentials) {
username = ((UsernamePasswordCredentials) credentials).getUsername();
}
DataSourceMeta<Neo4jSession> neo4jSessionDataSourceMeta = new DataSourceMeta<Neo4jSession>(s, username, sourceSession);
if (DataSourceWrapUtil.pressureDataSources.containsKey(neo4jSessionDataSourceMeta) && DataSourceWrapUtil.pressureDataSources.get(neo4jSessionDataSourceMeta) != null) {
// 该业务库数据源已经初始化过影子库
return;
}
if (isPerformanceDataSource(driverConfiguration)) {
// 业务库配置是已初始化的影子库
return;
}
// 从应用的影子库配置中获取
String key = DbUrlUtils.getKey(neo4jSessionDataSourceMeta.getUrl(), neo4jSessionDataSourceMeta.getUsername());
if (!GlobalConfig.getInstance().containsShadowDatabaseConfig(key)) {
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子表或影子库!").setDetail("业务库配置:::url: " + s + "; 中间件类型:other").closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
return;
}
MetaData metaData = (MetaData) args[0];
DataSourceWrapUtil.metaDataMap.put(sourceSession, metaData);
DataSourceWrapUtil.wrap(neo4jSessionDataSourceMeta);
} catch (Throwable e) {
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0003").setMessage("影子库配置异常,无法由配置正确生成影子库!").setDetail("url: " + ((HttpDriver) args[1]).getConfiguration().getURI() + Throwables.getStackTraceAsString(e)).closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
throw new PressureMeasureError("Neo4J-002:影子库初始化失败:", e);
}
}
use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.
the class Neo4jSessionOperationCutOffInterceptor method cutoff0.
@Override
public CutOffResult cutoff0(Advice advice) {
Object[] args = advice.getParameterArray();
String methodName = advice.getBehaviorName();
Object target = advice.getTarget();
/**
* 压测状态为关闭,如果当前为压测流量则直接报错
*/
if (!PradarSwitcher.isClusterTestEnabled()) {
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(PradarSwitcher.PRADAR_SWITCHER_OFF + ":" + AppNameUtils.appName());
}
return CutOffResult.passed();
}
if (!Pradar.isClusterTest()) {
// 非压测流量
return CutOffResult.passed();
}
if (target instanceof Neo4JSessionExt) {
// 影子配置session回调
return CutOffResult.passed();
}
// 避免因配置重新生效而导致使用旧配置
Driver driver1 = Reflect.on(target).get(Neo4JConstants.DYNAMIC_FIELD_DRIVER);
DriverConfiguration configuration = driver1.getConfiguration();
String uri = configuration.getURI();
Credentials credentials = configuration.getCredentials();
String username = null;
if (credentials instanceof AuthTokenCredentials) {
username = ((AuthTokenCredentials) credentials).credentials();
} else if (credentials instanceof UsernamePasswordCredentials) {
username = ((UsernamePasswordCredentials) credentials).getUsername();
}
DataSourceMeta<Neo4jSession> neo4jSessionDataSourceMeta = new DataSourceMeta<Neo4jSession>(uri, username, (Neo4jSession) target);
DataSourceWrapUtil.wrap(neo4jSessionDataSourceMeta);
// 压测流量转发影子库
if (!DataSourceWrapUtil.pressureDataSources.containsKey(neo4jSessionDataSourceMeta) || null == DataSourceWrapUtil.pressureDataSources.get(neo4jSessionDataSourceMeta)) {
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0002").setMessage("没有配置对应的影子库!").setDetail("Neo4J").closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS).report();
throw new PressureMeasureError("Neo4J-002:影子库配置不存在!");
}
DbMediatorDataSource<?> dbMediatorDataSource = DataSourceWrapUtil.pressureDataSources.get(neo4jSessionDataSourceMeta);
Neo4JSessionExt dataSourcePerformanceTest = (Neo4JSessionExt) dbMediatorDataSource.getDataSourcePerformanceTest();
Operation operation = Neo4JSessionOperation.of(methodName);
PradarSwitcher.httpPassPrefix.set(dataSourcePerformanceTest.getDriver().getConfiguration().getURI());
return CutOffResult.cutoff(operation.invoke(dataSourcePerformanceTest, args));
}
use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.
the class JedisSentinelShadowServerInterceptor method cutoff0.
@Override
public CutOffResult cutoff0(Advice advice) {
if (!Pradar.isClusterTest()) {
return CutOffResult.PASSED;
}
if (!model.isSentinelMode(advice.getTarget())) {
return CutOffResult.PASSED;
}
Object target = advice.getTarget();
try {
final Object object = JedisSentinelFactory.getFactory().getClient(target);
if (!(object instanceof JedisSentinelPool)) {
return CutOffResult.PASSED;
}
JedisSentinelPool pool = (JedisSentinelPool) object;
Jedis client = pool.getResource();
return CutOffResult.cutoff(Reflect.on(client).call(advice.getBehavior().getName(), advice.getParameterArray()).get());
} catch (PressureMeasureError e) {
throw e;
} catch (Throwable e) {
LOGGER.error(e.getMessage(), e);
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(Throwables.getStackTraceAsString(e));
}
}
return CutOffResult.passed();
}
use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.
the class MJedisInterceptor method processEvalMethodName.
private Object[] processEvalMethodName(Object[] args, Collection<String> whiteList, boolean canMatchWhiteList) {
if (args.length != 3) {
return args;
}
if (args[1] instanceof Integer) {
int keyCount = (Integer) args[1];
Object[] params = (Object[]) args[2];
if (keyCount <= params.length) {
for (int i = 0; i < keyCount; i++) {
Object data = params[i];
String key;
if (data instanceof String) {
key = (String) data;
} else if (data instanceof byte[]) {
key = new String((byte[]) data);
} else {
throw new PressureMeasureError("redis lua not support type " + data.getClass().getName());
}
if (RedisUtils.IGNORE_NAME.contains(key)) {
continue;
}
boolean contains = false;
if (canMatchWhiteList) {
for (String white : whiteList) {
if (key.startsWith(white)) {
contains = true;
break;
}
}
}
if (contains) {
continue;
}
if (Pradar.isClusterTestPrefix(key)) {
continue;
}
if (params[i] instanceof String) {
params[i] = Pradar.addClusterTestPrefix(key);
} else {
params[i] = (Pradar.addClusterTestPrefix(key)).getBytes();
}
}
}
} else if (args[1] instanceof byte[]) {
int keyCount = 0;
try {
keyCount = Integer.valueOf(new String((byte[]) args[1]));
} catch (NumberFormatException e) {
return args;
}
byte[][] params = (byte[][]) args[2];
if (keyCount <= params.length) {
for (int i = 0; i < keyCount; i++) {
byte[] data = params[i];
String key = new String((byte[]) data);
if (RedisUtils.IGNORE_NAME.contains(key)) {
continue;
}
boolean contains = false;
if (canMatchWhiteList) {
for (String white : whiteList) {
if (key.startsWith(white)) {
contains = true;
break;
}
}
}
if (contains) {
continue;
}
if (Pradar.isClusterTestPrefix(key)) {
continue;
}
params[i] = (Pradar.addClusterTestPrefix(key)).getBytes();
}
}
} else if (args[1] instanceof java.util.List) {
List<Object> list = (List<Object>) args[1];
List<Object> ptList = new ArrayList<Object>();
for (Object o : list) {
String key;
if (o instanceof String) {
key = (String) o;
if (!key.startsWith(Pradar.CLUSTER_TEST_PREFIX)) {
ptList.add((Pradar.addClusterTestPrefix(key)));
} else {
ptList.add(key);
}
} else if (o instanceof byte[]) {
key = new String((byte[]) o);
if (!Pradar.isClusterTestPrefix(key)) {
ptList.add((Pradar.addClusterTestPrefix(key)).getBytes());
} else {
ptList.add(key.getBytes());
}
} else {
throw new PressureMeasureError("redis lua not support type " + o.getClass().getName());
}
}
args[1] = ptList;
}
return args;
}
use of com.pamirs.pradar.exception.PressureMeasureError in project LinkAgent by shulieTech.
the class RedisDataCheckInterceptor method processEvalMethodName.
private List<String> processEvalMethodName(Object[] args, Collection<String> whiteList) {
List<String> keys = new ArrayList<String>();
if (args.length != 3) {
return keys;
}
if (args[1] instanceof Integer) {
int keyCount = (Integer) args[1];
Object[] params = (Object[]) args[2];
if (keyCount <= params.length) {
for (int i = 0; i < keyCount; i++) {
Object data = params[i];
String key;
if (data instanceof String) {
key = (String) data;
} else if (data instanceof byte[]) {
key = new String((byte[]) data);
} else {
throw new PressureMeasureError("redis lua not support type " + data.getClass().getName());
}
if (RedisUtils.IGNORE_NAME.contains(key)) {
continue;
}
boolean contains = false;
for (String white : whiteList) {
if (key.startsWith(white)) {
contains = true;
break;
}
}
if (contains) {
continue;
}
if (Pradar.isClusterTestPrefix(key)) {
continue;
}
keys.add(key);
}
}
} else if (args[1] instanceof byte[]) {
int keyCount = 0;
try {
keyCount = Integer.valueOf(new String((byte[]) args[1]));
} catch (NumberFormatException e) {
return keys;
}
byte[][] params = (byte[][]) args[2];
if (keyCount <= params.length) {
for (int i = 0; i < keyCount; i++) {
byte[] data = params[i];
String key = new String((byte[]) data);
if (RedisUtils.IGNORE_NAME.contains(key)) {
continue;
}
boolean contains = false;
for (String white : whiteList) {
if (key.startsWith(white)) {
contains = true;
break;
}
}
if (contains) {
continue;
}
if (Pradar.isClusterTestPrefix(key)) {
continue;
}
keys.add(key);
}
}
} else if (args[1] instanceof java.util.List) {
List<Object> list = (List<Object>) args[1];
List<Object> ptList = new ArrayList<Object>();
for (Object o : list) {
String key;
if (o instanceof String) {
key = (String) o;
keys.add(key);
} else if (o instanceof byte[]) {
key = new String((byte[]) o);
keys.add(key);
} else {
throw new PressureMeasureError("redis lua not support type " + o.getClass().getName());
}
}
}
return keys;
}
Aggregations