Browse Source

REPORT-106669 报表埋点补充开发文档 收集异常埋点信息

feature/x
Destiny.Lin 1 year ago
parent
commit
10a47e0252
  1. 22
      designer-base/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java
  2. 4
      designer-base/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java
  3. 20
      designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java
  4. 46
      designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java

22
designer-base/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfo.java

@ -33,6 +33,10 @@ public class ErrorInfo {
private String log; private String log;
private String stackTrace; private String stackTrace;
private boolean starting;
private boolean remote;
public ErrorInfo(String username, String uuid, String activekey) { public ErrorInfo(String username, String uuid, String activekey) {
this.username = username; this.username = username;
this.uuid = uuid; this.uuid = uuid;
@ -51,6 +55,22 @@ public class ErrorInfo {
this.username = username; this.username = username;
} }
public boolean isStarting() {
return starting;
}
public void setStarting(boolean starting) {
this.starting = starting;
}
public boolean isRemote() {
return remote;
}
public void setRemote(boolean remote) {
this.remote = remote;
}
public String getUuid() { public String getUuid() {
return uuid; return uuid;
} }
@ -126,6 +146,8 @@ public class ErrorInfo {
jo.put("logid", logid); jo.put("logid", logid);
jo.put("log", log); jo.put("log", log);
jo.put("stacktrace", stackTrace); jo.put("stacktrace", stackTrace);
jo.put("starting", starting);
jo.put("remote", remote);
saveFileToCache(jo); saveFileToCache(jo);
} }

4
designer-base/src/main/java/com/fr/design/mainframe/messagecollect/StartErrorMessageCollector.java

@ -4,6 +4,8 @@ import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.errorinfo.ErrorInfo; import com.fr.design.mainframe.errorinfo.ErrorInfo;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.start.common.DesignerStartupContext;
import com.fr.workspace.WorkContext;
/** /**
* *
@ -35,6 +37,8 @@ public class StartErrorMessageCollector {
errorInfo.setLogid(id); errorInfo.setLogid(id);
errorInfo.setLog(msg); errorInfo.setLog(msg);
errorInfo.setStackTrace(detail); errorInfo.setStackTrace(detail);
errorInfo.setStarting(DesignerStartupContext.getInstance().isOnStartup());
errorInfo.setRemote(!WorkContext.getCurrent().isLocal());
errorInfo.saveAsJSON(); errorInfo.saveAsJSON();
} }

20
designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

@ -57,6 +57,10 @@ public class InformationCollector implements XMLReadable, XMLWriter {
*/ */
private static final long DELTA = 24 * 3600 * 1000L; private static final long DELTA = 24 * 3600 * 1000L;
private static final long SEND_DELAY = 300 * 1000L; private static final long SEND_DELAY = 300 * 1000L;
/**
* 10分钟后再收集信息
*/
private static final long SEND_DELAY_4_ERROR_INFO = 300 * 1000L * 2;
private static final String FILE_NAME = "fr.info"; private static final String FILE_NAME = "fr.info";
private static final String XML_START_STOP_LIST = "StartStopList"; private static final String XML_START_STOP_LIST = "StartStopList";
private static final String XML_START_STOP = "StartStop"; private static final String XML_START_STOP = "StartStop";
@ -64,6 +68,8 @@ public class InformationCollector implements XMLReadable, XMLWriter {
private static final String ATTR_START = "start"; private static final String ATTR_START = "start";
private static final String ATTR_STOP = "stop"; private static final String ATTR_STOP = "stop";
private static final String THREAD_NAME = "ErrorInfoCollector";
private static InformationCollector collector; private static InformationCollector collector;
/** /**
@ -143,9 +149,22 @@ public class InformationCollector implements XMLReadable, XMLWriter {
*/ */
public void collectStartTime() { public void collectStartTime() {
this.current.setStartDate(dateToString()); this.current.setStartDate(dateToString());
dealWithErrorInfo();
sendInfo(); sendInfo();
} }
private void dealWithErrorInfo() {
ScheduledExecutorService service = Executors
.newSingleThreadScheduledExecutor(new NamedThreadFactory(THREAD_NAME));
service.schedule(() -> {
ErrorInfoUploader.getInstance().dealErrorInfo(false);
}, SEND_DELAY_4_ERROR_INFO, TimeUnit.MILLISECONDS);
service.shutdown();
}
/**
* 目前来看这些数据好像没啥用了但是还是先留着吧单独把错误信息拿出来用云端运维统一提交
*/
private void sendInfo() { private void sendInfo() {
if (!DesignerEnvManager.getEnvManager().isJoinProductImprove() || !FRContext.isChineseEnv()) { if (!DesignerEnvManager.getEnvManager().isJoinProductImprove() || !FRContext.isChineseEnv()) {
return; return;
@ -157,7 +176,6 @@ public class InformationCollector implements XMLReadable, XMLWriter {
SolidCollector.getInstance().sendToCloudCenterAndDeleteFile(); SolidCollector.getInstance().sendToCloudCenterAndDeleteFile();
FocusPointMessageUploader.getInstance().sendToCloudCenter(); FocusPointMessageUploader.getInstance().sendToCloudCenter();
ChartInfoCollector.getInstance().sendPointInfo(); ChartInfoCollector.getInstance().sendPointInfo();
ErrorInfoUploader.getInstance().sendErrorInfo();
sendInfoSuccessCallback(); sendInfoSuccessCallback();
}, SEND_DELAY, TimeUnit.MILLISECONDS); }, SEND_DELAY, TimeUnit.MILLISECONDS);
service.shutdown(); service.shutdown();

46
designer-realize/src/main/java/com/fr/design/mainframe/errorinfo/ErrorInfoUploader.java

@ -20,9 +20,10 @@ import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -148,6 +149,15 @@ public class ErrorInfoUploader {
// 判断更新解决方案缓存. // 判断更新解决方案缓存.
checkUpdateSolution(); checkUpdateSolution();
dealErrorInfo(true);
}
/**
* 处理错误信息
*
* @param needSend2Cloud 是否需要上传到云中心
*/
public void dealErrorInfo(boolean needSend2Cloud) {
//读取文件夹里的json, 加入上传队列中. //读取文件夹里的json, 加入上传队列中.
File folder = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FOLDER_NAME)); File folder = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FOLDER_NAME));
if (!folder.exists()) { if (!folder.exists()) {
@ -164,6 +174,13 @@ public class ErrorInfoUploader {
} }
try { try {
dealFiles(files, needSend2Cloud);
} catch (Exception ignore) {
}
}
private void dealFiles(File[] files, boolean needSend2Cloud) throws IOException {
if (ArrayUtils.isNotEmpty(files)) { if (ArrayUtils.isNotEmpty(files)) {
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
List<File> tempFiles = new ArrayList<>(); List<File> tempFiles = new ArrayList<>();
@ -174,7 +191,7 @@ public class ErrorInfoUploader {
String suffix = filePath.substring(filePath.lastIndexOf(".")); String suffix = filePath.substring(filePath.lastIndexOf("."));
if (suffix.endsWith(SUFFIX)) { if (suffix.endsWith(SUFFIX)) {
String content = IOUtils.inputStream2String(new FileInputStream(file)); String content = IOUtils.inputStream2String(Files.newInputStream(file.toPath()));
if (content.length() > MAX_ERROR_SIZE) { if (content.length() > MAX_ERROR_SIZE) {
CommonIOUtils.deleteFile(file); CommonIOUtils.deleteFile(file);
continue; continue;
@ -182,6 +199,15 @@ public class ErrorInfoUploader {
jsonArray.put(new JSONObject(content)); jsonArray.put(new JSONObject(content));
tempFiles.add(file); tempFiles.add(file);
if (jsonArray.length() == MAX_ITEMS || count == files.length) { if (jsonArray.length() == MAX_ITEMS || count == files.length) {
processInfos(jsonArray, needSend2Cloud, tempFiles);
}
}
}
}
}
private void processInfos(JSONArray jsonArray, boolean needSend2Cloud, List<File> tempFiles) {
if (needSend2Cloud) {
String url = CloudCenter.getInstance().acquireUrlByKind("design.error"); String url = CloudCenter.getInstance().acquireUrlByKind("design.error");
if (StringUtils.isBlank(url)) { if (StringUtils.isBlank(url)) {
return; return;
@ -190,14 +216,22 @@ public class ErrorInfoUploader {
deleteFiles(tempFiles); deleteFiles(tempFiles);
} }
jsonArray = new JSONArray(); jsonArray = new JSONArray();
} else {
sendInfos4AnalysisAndClearFiles(jsonArray, tempFiles);
} }
} }
}
}
} catch (Exception ignore) {
/**
* 提供给云端运维监听的方法(beforeExecute)
*
* @param jsonArray 要提交的信息
* @param tempFiles 要删除的文件
*/
private void sendInfos4AnalysisAndClearFiles(JSONArray jsonArray, List<File> tempFiles) {
deleteFiles(tempFiles);
} }
}
private void deleteFiles(List<File> files) { private void deleteFiles(List<File> files) {
for (File file : files) { for (File file : files) {

Loading…
Cancel
Save