use of com.pamirs.attach.plugin.mongodb.utils.OperationAccessor in project LinkAgent by shulieTech.
the class DelegateOperationExecutorTraceInterceptor method beforeTrace.
@Override
public SpanRecord beforeTrace(Advice advice) {
Object[] args = advice.getParameterArray();
SpanRecord spanRecord = new SpanRecord();
spanRecord.setMiddlewareName("mongodb");
Class operationClass = args[0].getClass();
spanRecord.setMethod(operationClass.getSimpleName());
spanRecord.setService("unknown");
OperationAccessor operationAccessor = OperationAccessorFactory.getOperationAccessor(operationClass);
if (operationAccessor != null) {
try {
spanRecord.setService((operationAccessor.getMongoNamespace(args[0]).getFullName()));
} catch (Exception e) {
LOGGER.error("not support operation class is {} ", args[0].getClass().getName());
}
}
try {
Object mongoClientDelegate = Caches.getMongoClientDelegate(advice.getTarget());
String addressesStr = StringUtils.join(((Cluster) (ReflectionUtils.getFieldValue(mongoClientDelegate, "cluster"))).getSettings().getHosts(), ",");
spanRecord.setRemoteIp(addressesStr);
} catch (Exception e) {
LOGGER.error("can not get mongoClientDelegate");
}
return spanRecord;
}
use of com.pamirs.attach.plugin.mongodb.utils.OperationAccessor in project LinkAgent by shulieTech.
the class DelegateOperationExecutorInterceptor method cutoff0.
@Override
public CutOffResult cutoff0(Advice advice) throws Throwable {
if (!Pradar.isClusterTest()) {
return CutOffResult.passed();
}
// 影子库重入
if (manager.getDynamicField(advice.getTarget(), "isCluster") != null) {
return CutOffResult.passed();
}
Object[] args = advice.getParameterArray();
Class operationClass = args[0].getClass();
Object operation = args[0];
OperationAccessor operationAccessor = OperationAccessorFactory.getOperationAccessor(operationClass);
if (operationAccessor == null) {
LOGGER.error("not support operation class is {} ", args[0].getClass().getName());
throw new PressureMeasureError("mongo not support pressure operation class is " + args[0].getClass().getName());
}
Object mongoClientDelegate = Caches.getMongoClientDelegate(advice.getTarget());
ShadowDatabaseConfig shadowDatabaseConfig = getShadowDatabaseConfig(mongoClientDelegate);
if (shadowDatabaseConfig == null) {
if (operationAccessor.isRead()) {
return CutOffResult.passed();
} else {
MongoNamespace busMongoNamespace = operationAccessor.getMongoNamespace(operation);
ErrorReporter.Error error = ErrorReporter.buildError().setErrorType(ErrorTypeEnum.DataSource).setErrorCode("datasource-0005").setMessage("mongodb 不存在对应影子表或影子库:" + busMongoNamespace.getFullName()).setDetail("mongodb " + StringUtils.join(((Cluster) (ReflectionUtils.getFieldValue(mongoClientDelegate, "cluster"))).getSettings().getHosts(), ",") + "不存在对应影子表或影子库:" + busMongoNamespace.getFullName());
error.closePradar(ConfigNames.SHADOW_DATABASE_CONFIGS);
error.report();
throw new PressureMeasureError("mongo 对应影子表或影子库:" + busMongoNamespace.getFullName());
}
}
if (shadowDatabaseConfig.isShadowTable()) {
doShadowTable(operation, operationAccessor, shadowDatabaseConfig);
return CutOffResult.passed();
} else {
return CutOffResult.cutoff(doShadowDb(args, operationAccessor, shadowDatabaseConfig));
}
}
Aggregations