feature(web): 增加日志查看组件

This commit is contained in:
2023-05-25 14:14:42 +08:00
parent ac2bdbc2df
commit 1dc9d69310
3 changed files with 91 additions and 0 deletions

View File

@@ -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.<String, String>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.<String, String>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"));
}
}

View File

@@ -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',
}
}
]
},
],
}
}

View File

@@ -40,6 +40,7 @@
<script src="components/cloud-tab.js"></script>
<script src="components/queue-tab.js"></script>
<script src="components/running-tab.js"></script>
<script src="components/log-tab.js"></script>
<script type="text/javascript">
(function () {
let amis = amisRequire('amis/embed')
@@ -53,6 +54,7 @@
unmountOnExit: true,
tabsMode: 'strong',
tabs: [
// logTab(),
// runningTab(),
tableTab(),
queueTab(),