From 1dc9d6931074e2490cc71ba63dca45f2c6cda3ef Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 25 May 2023 14:14:42 +0800 Subject: [PATCH] =?UTF-8?q?feature(web):=20=E5=A2=9E=E5=8A=A0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=9F=A5=E7=9C=8B=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/web/controller/LogController.java | 60 +++++++++++++++++++ .../resources/static/components/log-tab.js | 29 +++++++++ .../src/main/resources/static/index.html | 2 + 3 files changed, 91 insertions(+) create mode 100644 service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/LogController.java create mode 100644 service-web/src/main/resources/static/components/log-tab.js diff --git a/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/LogController.java b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/LogController.java new file mode 100644 index 0000000..7caf8d9 --- /dev/null +++ b/service-web/src/main/java/com/lanyuanxiaoyao/service/web/controller/LogController.java @@ -0,0 +1,60 @@ +package com.lanyuanxiaoyao.service.web.controller; + +import cn.hutool.core.map.MapUtil; +import com.lanyuanxiaoyao.service.configuration.entity.AmisResponse; +import com.lanyuanxiaoyao.service.configuration.entity.loki.LokiLogLine; +import com.lanyuanxiaoyao.service.forest.service.LokiService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * 日志相关 + * + * @author lanyuanxiaoyao + * @date 2023-05-25 + */ +@RestController +@RequestMapping("log") +public class LogController extends BaseController { + private static final Logger logger = LoggerFactory.getLogger(LogController.class); + + private final LokiService lokiService; + + @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") + public LogController(LokiService lokiService) { + this.lokiService = lokiService; + } + + @GetMapping("query_sync_log") + public AmisResponse querySyncLog(@RequestParam("flink_job_id") Long flinkJobId) { + return responseDetail(lokiService.queryRange(MapUtil.builder() + .put("app", "hudi-sync") + .put("run_type", "sync") + .put("flink_job_id", flinkJobId.toString()) + .build()) + .collect(LokiLogLine::getData) + .collect(line -> line.replaceAll(":\\n", "")) + .collect(line -> line.replaceAll("\\n$", "")) + .collect(line -> line.replaceAll("^\\s*(.+)\\s*#@#\\s*(.+)\\s*$", "$1: $2")) + .makeString("\n")); + } + + @GetMapping("query_compaction_log") + public AmisResponse queryCompactionLog(@RequestParam("flink_job_id") Long flinkJobId, @RequestParam("alias") String alias) { + return responseDetail(lokiService.queryRange(MapUtil.builder() + .put("app", "hudi-sync") + .put("run_type", "compaction") + .put("flink_job_id", flinkJobId.toString()) + .put("alias", alias) + .build()) + .collect(LokiLogLine::getData) + .collect(line -> line.replaceAll(":\\n", "")) + .collect(line -> line.replaceAll("\\n$", "")) + .collect(line -> line.replaceAll("^\\s*(.+?)\\s*#@#\\s*(.+?)\\s*$", "$1: $2")) + .makeString("\n")); + } +} diff --git a/service-web/src/main/resources/static/components/log-tab.js b/service-web/src/main/resources/static/components/log-tab.js new file mode 100644 index 0000000..80fe0af --- /dev/null +++ b/service-web/src/main/resources/static/components/log-tab.js @@ -0,0 +1,29 @@ +function logTab() { + return { + title: '运行中', + tab: [ + { + type: 'service', + api: { + method: 'GET', + url: '${base}/log/query_compaction_log', + data: { + flink_job_id: '1646351885991305217', + alias: 'dz_mb_sys_login_log', + } + }, + body: [ + { + disabled: true, + type: 'editor', + name: 'detail', + label: '压缩日志', + options: { + wordWrap: 'on', + } + } + ] + }, + ], + } +} \ No newline at end of file diff --git a/service-web/src/main/resources/static/index.html b/service-web/src/main/resources/static/index.html index bd38247..1938b61 100644 --- a/service-web/src/main/resources/static/index.html +++ b/service-web/src/main/resources/static/index.html @@ -40,6 +40,7 @@ +