refactor(web): 优化日志查看

This commit is contained in:
2023-05-29 15:09:22 +08:00
parent 1dc9d69310
commit 8e9b04acab
4 changed files with 67 additions and 10 deletions

View File

@@ -48,7 +48,7 @@ public class LokiQueryApplication {
private final LokiQueryService lokiQueryService;
@GetMapping("query_range")
public ImmutableList<LokiLogLine> queryRange(@RequestParam Map<String, String> queryMap) throws Exception {
return lokiQueryService.queryRange(Maps.immutable.ofAll(queryMap));
public ImmutableList<LokiLogLine> queryRange(@RequestParam Map<String, String> queryMap, @RequestParam(value = "limit", defaultValue = "200") Integer limit) throws Exception {
return lokiQueryService.queryRange(Maps.immutable.ofAll(queryMap), limit);
}
}

View File

@@ -47,9 +47,9 @@ public class LokiQueryService {
}
@Retryable(Throwable.class)
public ImmutableList<LokiLogLine> queryRange(ImmutableMap<String, String> queryMap) throws Exception {
public ImmutableList<LokiLogLine> queryRange(ImmutableMap<String, String> queryMap, Integer limit) throws Exception {
String query = URLUtil.encodeQuery(buildLokiQuery(queryMap));
String queryUrl = StrUtil.format("{}/loki/api/v1/query_range?query={}&limit=200", lokiConfiguration.getHost(), query);
String queryUrl = StrUtil.format("{}/loki/api/v1/query_range?query={}&limit={}", lokiConfiguration.getHost(), query, limit);
HttpResponse response = HttpUtil.createGet(queryUrl).execute();
if (response.isOk()) {
LokiQueryRangeResponse queryRangeResponse = mapper.readValue(response.body(), LokiQueryRangeResponse.class);

View File

@@ -29,17 +29,22 @@ public class LogController extends BaseController {
this.lokiService = lokiService;
}
private String preHandle(String line) {
return line
.replaceAll("\\n$", "")
.replaceAll("^\\s*(.+?)\\s*#@# :\\s*(.+?)\\s*$", "$1: $2");
}
@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())
.put("limit", "1000")
.build())
.collect(LokiLogLine::getData)
.collect(line -> line.replaceAll(":\\n", ""))
.collect(line -> line.replaceAll("\\n$", ""))
.collect(line -> line.replaceAll("^\\s*(.+)\\s*#@#\\s*(.+)\\s*$", "$1: $2"))
.collect(this::preHandle)
.makeString("\n"));
}
@@ -50,11 +55,21 @@ public class LogController extends BaseController {
.put("run_type", "compaction")
.put("flink_job_id", flinkJobId.toString())
.put("alias", alias)
.put("limit", "1000")
.build())
.collect(LokiLogLine::getData)
.collect(line -> line.replaceAll(":\\n", ""))
.collect(line -> line.replaceAll("\\n$", ""))
.collect(line -> line.replaceAll("^\\s*(.+?)\\s*#@#\\s*(.+?)\\s*$", "$1: $2"))
.collect(this::preHandle)
.makeString("\n"));
}
@GetMapping("query_application_log")
public AmisResponse queryApplicationLog(@RequestParam("application_id") String applicationId) {
return responseDetail(lokiService.queryRange(MapUtil.<String, String>builder()
.put("app", "hudi-sync")
.put("app_id", applicationId)
.build())
.collect(LokiLogLine::getData)
.collect(this::preHandle)
.makeString("\n"));
}
}

View File

@@ -6,6 +6,44 @@ function timeAndFrom(field, fromNow, emptyText = '未停止', showSource = true)
return tpl
}
function applicationLogDialog() {
return {
type: 'action',
level: 'link',
actionType: 'dialog',
dialog: {
title: '应用日志',
size: 'xl',
actions: [],
body: [
{
type: 'service',
api: {
method: 'GET',
url: '${base}/log/query_application_log',
data: {
application_id: '${id}',
}
},
body: [
{
disabled: true,
type: 'editor',
name: 'detail',
label: '应用日志',
size: 'xxl',
placeholder: '没有内容',
options: {
wordWrap: 'on',
}
}
]
},
]
}
}
}
function yarnCrudColumns() {
return [
{
@@ -163,6 +201,10 @@ function yarnCrudColumns() {
actionType: 'url',
url: '${trackingUrl}',
blank: true,
},
{
label: '日志',
...applicationLogDialog(),
}
]
}