Browse Source

Pull request #8837: REPORT-71028 部分execute 埋点获取不到额外的session相关信息

Merge in DESIGN/design from ~YAOH.WU/design:release/11.0 to release/11.0

* commit 'f79b56c2532dd0d82fae8115cd5213f853568512':
  REPORT-71028 部分execute 埋点获取不到额外的session相关信息
newui
yaoh.wu 3 years ago
parent
commit
235a29e7ca
  1. 36
      designer-base/src/main/java/com/fr/design/record/analyzer/advice/MonitorAdvice.java

36
designer-base/src/main/java/com/fr/design/record/analyzer/advice/MonitorAdvice.java

@ -5,22 +5,18 @@ import com.fr.general.GeneralUtils;
import com.fr.intelli.measure.Estimator; import com.fr.intelli.measure.Estimator;
import com.fr.intelli.metrics.Compute; import com.fr.intelli.metrics.Compute;
import com.fr.intelli.metrics.MessageRecorderFactory; import com.fr.intelli.metrics.MessageRecorderFactory;
import com.fr.intelli.metrics.SessionBinder;
import com.fr.intelli.metrics.SupervisoryConfig; import com.fr.intelli.metrics.SupervisoryConfig;
import com.fr.intelli.record.Measurable; import com.fr.intelli.record.Measurable;
import com.fr.intelli.record.MeasureObject; import com.fr.intelli.record.MeasureObject;
import com.fr.intelli.record.MeasureUnit; import com.fr.intelli.record.MeasureUnit;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.measure.DBMeterFactory; import com.fr.measure.DBMeterFactory;
import com.fr.stable.ArrayUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.web.Session;
import com.fr.stable.web.SessionProvider;
import com.fr.third.net.bytebuddy.asm.Advice; import com.fr.third.net.bytebuddy.asm.Advice;
import com.fr.third.net.bytebuddy.implementation.bytecode.assign.Assigner; import com.fr.third.net.bytebuddy.implementation.bytecode.assign.Assigner;
import com.fr.web.core.SessionPoolManager;
import com.fr.web.session.SessionLocalManager; import com.fr.web.session.SessionLocalManager;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -41,10 +37,11 @@ public class MonitorAdvice implements DesignerAnalyzerAdvice {
public static void onMethodEnter(@Advice.Origin Method method, public static void onMethodEnter(@Advice.Origin Method method,
@Advice.AllArguments(typing = Assigner.Typing.DYNAMIC) Object[] args, @Advice.AllArguments(typing = Assigner.Typing.DYNAMIC) Object[] args,
@Advice.Local("startTime") Long startTime, @Advice.Local("startTime") Long startTime,
@Advice.Local("registeredSession") Boolean registeredSession) { @Advice.Local("sessionBinder") SessionBinder sessionBinder) {
startTime = (System.currentTimeMillis()); startTime = (System.currentTimeMillis());
registeredSession = (findSessionAnnotation(method, args)); sessionBinder = new SessionBinder();
sessionBinder.attachSession(method, args);
} }
@Advice.OnMethodExit(onThrowable = Exception.class) @Advice.OnMethodExit(onThrowable = Exception.class)
@ -53,12 +50,10 @@ public class MonitorAdvice implements DesignerAnalyzerAdvice {
@Advice.AllArguments(typing = Assigner.Typing.DYNAMIC) Object[] args, @Advice.AllArguments(typing = Assigner.Typing.DYNAMIC) Object[] args,
@Advice.Thrown(typing = Assigner.Typing.DYNAMIC) Exception e, @Advice.Thrown(typing = Assigner.Typing.DYNAMIC) Exception e,
@Advice.Local("startTime") Long startTime, @Advice.Local("startTime") Long startTime,
@Advice.Local("registeredSession") Boolean registeredSession) throws Exception { @Advice.Local("sessionBinder") SessionBinder sessionBinder) throws Exception {
String error = StringUtils.EMPTY; String error = StringUtils.EMPTY;
try { try {
if (e != null) { if (e != null) {
try { try {
error = getErrorContent(e); error = getErrorContent(e);
@ -95,10 +90,7 @@ public class MonitorAdvice implements DesignerAnalyzerAdvice {
} catch (Exception ignore) { } catch (Exception ignore) {
//埋点信息入库失败应该不能影响业务流程 //埋点信息入库失败应该不能影响业务流程
} finally { } finally {
if (registeredSession) { sessionBinder.detachSession();
// 如果上面记录了,这里就要释放
SessionLocalManager.releaseSession();
}
} }
} }
} }
@ -136,20 +128,4 @@ public class MonitorAdvice implements DesignerAnalyzerAdvice {
measureObject.memory(unit.measureMemory()); measureObject.memory(unit.measureMemory());
} }
} }
public static boolean findSessionAnnotation(Method method, Object[] args) {
Annotation[][] all = method.getParameterAnnotations();
int len = ArrayUtils.getLength(args);
for (int i = 0; i < len; i++) {
Annotation[] current = all[i];
for (Annotation annotation : current) {
if (annotation.annotationType().equals(Session.class)) {
SessionLocalManager.setSession(
SessionPoolManager.getSessionIDInfor(GeneralUtils.objectToString(args[i]), SessionProvider.class));
return true;
}
}
}
return false;
}
} }

Loading…
Cancel
Save