Browse Source

Pull request #13108: feat: REPORT-106669 报表埋点补充

Merge in DESIGN/design from ~HARRISON/design:feature/x to feature/x

* commit 'ab2aec1b5f0144f9bcaf5c74e66abc1e916803d7':
  feat: REPORT-106669 报表埋点补充 - 考虑插件延迟加载的情况,换一种方式记录信息。
  feat: REPORT-106669 报表埋点补充 - 将切换操作包上一层,然后在外层进行记录和触发操作。不然插件有可能记录不到埋点信息。
  feat: REPORT-106669 报表埋点补充 - 代码质量修复
  feat: REPORT-106669 报表埋点补充 【远程部分埋点补充。】 - 添加切换过程、切换数据统计 - 模块关闭时间细化 - 提供 PerformancePoint 作为性能诊断辅助类。提供 PerformancePointTest 作为 DEMO
feature/x
Harrison-刘珂 1 year ago
parent
commit
c63e13fc03
  1. 140
      designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java
  2. 63
      designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java

140
designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java

@ -1,9 +1,6 @@
package com.fr.design;
import com.fr.common.report.ReportState;
import com.fr.design.env.processor.RemoteDesignerWorkspaceInfoProcessor;
import com.fr.design.mainframe.manager.clip.TemplateTreeClipboard;
import com.fr.design.plugin.remind.PluginErrorDesignReminder;
import com.fr.design.data.DesignTableDataManager;
import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter;
@ -14,13 +11,16 @@ import com.fr.design.env.DesignerWorkspaceInfoContext;
import com.fr.design.env.DesignerWorkspaceType;
import com.fr.design.env.RemoteDesignerWorkspaceInfo;
import com.fr.design.env.RemoteWorkspace;
import com.fr.design.env.processor.RemoteDesignerWorkspaceInfoProcessor;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.file.SaveSomeTemplatePane;
import com.fr.design.file.TemplateTreePane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.manager.clip.TemplateTreeClipboard;
import com.fr.design.notification.NotificationCenter;
import com.fr.design.plugin.remind.PluginErrorDesignReminder;
import com.fr.design.utils.DesignUtils;
import com.fr.design.versioncheck.VersionCheckUtils;
import com.fr.env.EnvListPane;
@ -31,6 +31,7 @@ import com.fr.invoke.Reflect;
import com.fr.json.JSONArray;
import com.fr.locale.InterProviderFactory;
import com.fr.log.FineLoggerFactory;
import com.fr.performance.profile.PerformancePoint;
import com.fr.process.ProcessEventPipe;
import com.fr.process.engine.core.CarryMessageEvent;
import com.fr.process.engine.core.FineProcessContext;
@ -41,12 +42,14 @@ import com.fr.start.server.ServerTray;
import com.fr.workspace.WorkContext;
import com.fr.workspace.WorkContextCallback;
import com.fr.workspace.Workspace;
import com.fr.workspace.WorkspaceSwitchProcess;
import com.fr.workspace.base.WorkspaceAPI;
import com.fr.workspace.connect.WorkspaceConnectionInfo;
import com.fr.workspace.engine.base.FineObjectPool;
import com.fr.workspace.engine.channel.http.FunctionalHttpRequest;
import com.fr.workspace.engine.exception.WorkspaceConnectionException;
import com.fr.workspace.engine.rpc.WorkspaceProxyPool;
import static javax.swing.JOptionPane.QUESTION_MESSAGE;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
@ -58,12 +61,11 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.HashSet;
import static javax.swing.JOptionPane.QUESTION_MESSAGE;
public class EnvChangeEntrance {
private static final String BRANCH_TAG = "#";
@ -125,48 +127,111 @@ public class EnvChangeEntrance {
}
}
/**
* 切换到新环境
*
* @param envName 新工作环境名称
* @param strategy 提示策略
* @return 是否成功
*/
private boolean switch2Env(final String envName, PopTipStrategy strategy) {
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
DesignerWorkspaceInfo selectedEnv = customUserName(envManager.getWorkspaceInfo(envName));
DesignerWorkspaceInfoContext.setWorkspaceInfo(selectedEnv);
WorkspaceConnectionInfo connectionInfo = selectedEnv.getConnection();
WorkspaceSwitchProcess lastProcess = WorkContext.getSwitcher().getProcess();
PerformancePoint performancePoint = PerformancePoint.create();
boolean switchStatus = doSwitch2Env(envName, strategy);
WorkspaceSwitchProcess currentProcess = WorkContext.getSwitcher().getProcess();
// 如果相同,代表根本没切换 ==
if (lastProcess != currentProcess) {
// 记录切换耗时
recordSwitchInfos(performancePoint, switchStatus);
// 触发切换埋点
triggerSwitchMetric();
}
return switchStatus;
}
/**
* 由云端运维触发切换埋点
* 内部空实现
* <a href="https://kms.fineres.com/pages/viewpage.action?pageId=945327503">实现</a>
*/
private void triggerSwitchMetric() {
}
/**
* 切换到新环境
* 1. 先获取选中的环境
* 2. 生成工作目录
* 3. 验证工作目录
* 4. 触发切换操作
* 5. 触发可能存在异常的切换后动作
* 6. 触发切换后动作
*
* @param envName 新工作环境名称
* @return 是否成功
*/
private boolean doSwitch2Env(final String envName, PopTipStrategy strategy) {
DesignerWorkspaceInfo selectedEnv = getSelectedEnv(envName);
try {
Workspace workspace = DesignerWorkspaceGenerator.generate(selectedEnv);
boolean checkValid = workspace != null && selectedEnv.checkValid();
if (!checkValid) {
if (notValid(workspace, selectedEnv)) {
return false;
}
//如果是相同环境
if (isSameEnv(workspace)) {
//目前切换到相同环境需要更新一下名字,后续如果有别的操作直接往里面加就行了
switch2SameEnv(envName);
} else {
//切换到新环境,做下封装
switch2OtherEnv(workspace, envName);
}
// REPORT-25688如果是war包部署的服务器,给与提示
if (WorkContext.getCurrent().isWarDeploy()) {
FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Basic_War_Deploy_Tip"),
Toolkit.i18nText("Fine-Design_Basic_Message"), JOptionPane.INFORMATION_MESSAGE);
}
//REPORT-13810如果只是添加了工作目录,没有切换,这里ToolArea也是要显示新建的工作目录
JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (JTemplate.isValid(template)) {
template.refreshToolArea();
}
PluginErrorDesignReminder.getInstance().remindStartFailedPlugins();
doSwitchAction(envName, workspace);
afterSwitchWithEx();
} catch (Exception exception) {
// 失败的处理
WorkspaceExceptionHandler.getInstance().handleInSwitch(exception, selectedEnv);
return false;
}
afterSwitch();
return true;
}
private DesignerWorkspaceInfo getSelectedEnv(String envName) {
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
DesignerWorkspaceInfo selectedEnv = customUserName(envManager.getWorkspaceInfo(envName));
DesignerWorkspaceInfoContext.setWorkspaceInfo(selectedEnv);
return selectedEnv;
}
private static boolean notValid(Workspace workspace, DesignerWorkspaceInfo selectedEnv) throws Exception {
boolean checkValid = workspace != null && selectedEnv.checkValid();
return !checkValid;
}
private void doSwitchAction(String envName, Workspace workspace) {
//如果是相同环境
if (isSameEnv(workspace)) {
//目前切换到相同环境需要更新一下名字,后续如果有别的操作直接往里面加就行了
switch2SameEnv(envName);
} else {
//切换到新环境,做下封装
switch2OtherEnv(workspace, envName);
}
}
private static void afterSwitchWithEx() {
// REPORT-25688如果是war包部署的服务器,给与提示
if (WorkContext.getCurrent().isWarDeploy()) {
FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Basic_War_Deploy_Tip"),
Toolkit.i18nText("Fine-Design_Basic_Message"), JOptionPane.INFORMATION_MESSAGE);
}
//REPORT-13810如果只是添加了工作目录,没有切换,这里ToolArea也是要显示新建的工作目录
JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (JTemplate.isValid(template)) {
template.refreshToolArea();
}
PluginErrorDesignReminder.getInstance().remindStartFailedPlugins();
}
private static void afterSwitch() {
TemplateTreePane.getInstance().refreshDockingView();
DesignModelAdapter<?, ?> model = DesignModelAdapter.getCurrentModelAdapter();
if (model != null) {
@ -175,7 +240,18 @@ public class EnvChangeEntrance {
NotificationCenter.getInstance().clearAllNotifications();
//切换环境后,清空粘贴板里面的内容
TemplateTreeClipboard.getInstance().reset();
return true;
}
private static void recordSwitchInfos(PerformancePoint performancePoint, boolean switchSuccess) {
performancePoint.end(elapsed -> {
WorkspaceSwitchProcess process = WorkContext.getSwitcher().getProcess();
Optional.ofNullable(process)
.ifPresent((e) -> {
e.recordSwitchElapsed(elapsed);
e.setSwitchSuccess(switchSuccess);
});
});
}
/**

63
designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java

@ -6,10 +6,15 @@ import com.fr.design.file.HistoryTemplateListCache;
import com.fr.event.Event;
import com.fr.event.Listener;
import com.fr.module.Activator;
import com.fr.module.ModuleContext;
import com.fr.module.engine.FineModule;
import com.fr.start.server.FineEmbedServer;
import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace;
import com.fr.workspace.WorkspaceEvent;
import com.fr.workspace.WorkspaceSwitchProcess;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
/**
@ -17,6 +22,46 @@ import java.util.concurrent.ExecutorService;
*/
public class DesignerWorkspaceActivator extends Activator {
private final Listener<Workspace> stopModuleAction = new Listener<Workspace>(Integer.MIN_VALUE) {
@Override
public void on(Event event, Workspace current) {
stopSub(EnvBasedModule.class);
recordModuleStop();
}
private void recordModuleStop() {
WorkspaceSwitchProcess process = WorkContext.getSwitcher().getProcess();
Optional.ofNullable(process)
.ifPresent((e) -> e.recordModuleStopUsed(() -> {
FineModule module = (FineModule) ModuleContext.getModule(EnvBasedModule.class);
return module.profileStop();
}));
}
};
private final Listener<Workspace> startModuleAction = new Listener<Workspace>(Integer.MAX_VALUE) {
@Override
public void on(Event event, Workspace current) {
startSub(EnvBasedModule.class);
recordModuleStart();
}
private void recordModuleStart() {
WorkspaceSwitchProcess process = WorkContext.getSwitcher().getProcess();
Optional.ofNullable(process)
.ifPresent((e) -> e.recordModuleStartUsed(() -> {
FineModule module = (FineModule) ModuleContext.getModule(EnvBasedModule.class);
return module.profile();
}));
}
};
@Override
public void start() {
@ -29,23 +74,9 @@ public class DesignerWorkspaceActivator extends Activator {
private void registerEnvListener() {
/*切换环境前,关闭所有相关模块,最后执行*/
listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MIN_VALUE) {
@Override
public void on(Event event, Workspace current) {
stopSub(EnvBasedModule.class);
}
});
listenEvent(WorkspaceEvent.BeforeSwitch, stopModuleAction);
/*切换环境后,重新启动所有相关模块,最先执行*/
listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MAX_VALUE) {
@Override
public void on(Event event, Workspace current) {
startSub(EnvBasedModule.class);
}
});
listenEvent(WorkspaceEvent.AfterSwitch, startModuleAction);
/*切换环境前,存储一下打开的所有文件对象,要先于 关闭相关模块部分 被触发*/
listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MAX_VALUE) {

Loading…
Cancel
Save