refactor(web): 优化日志查看
This commit is contained in:
@@ -48,7 +48,7 @@ public class LokiQueryApplication {
|
|||||||
private final LokiQueryService lokiQueryService;
|
private final LokiQueryService lokiQueryService;
|
||||||
|
|
||||||
@GetMapping("query_range")
|
@GetMapping("query_range")
|
||||||
public ImmutableList<LokiLogLine> queryRange(@RequestParam Map<String, String> queryMap) throws Exception {
|
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));
|
return lokiQueryService.queryRange(Maps.immutable.ofAll(queryMap), limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ public class LokiQueryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Retryable(Throwable.class)
|
@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 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();
|
HttpResponse response = HttpUtil.createGet(queryUrl).execute();
|
||||||
if (response.isOk()) {
|
if (response.isOk()) {
|
||||||
LokiQueryRangeResponse queryRangeResponse = mapper.readValue(response.body(), LokiQueryRangeResponse.class);
|
LokiQueryRangeResponse queryRangeResponse = mapper.readValue(response.body(), LokiQueryRangeResponse.class);
|
||||||
|
|||||||
@@ -29,17 +29,22 @@ public class LogController extends BaseController {
|
|||||||
this.lokiService = lokiService;
|
this.lokiService = lokiService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String preHandle(String line) {
|
||||||
|
return line
|
||||||
|
.replaceAll("\\n$", "")
|
||||||
|
.replaceAll("^\\s*(.+?)\\s*#@# :\\s*(.+?)\\s*$", "$1: $2");
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("query_sync_log")
|
@GetMapping("query_sync_log")
|
||||||
public AmisResponse querySyncLog(@RequestParam("flink_job_id") Long flinkJobId) {
|
public AmisResponse querySyncLog(@RequestParam("flink_job_id") Long flinkJobId) {
|
||||||
return responseDetail(lokiService.queryRange(MapUtil.<String, String>builder()
|
return responseDetail(lokiService.queryRange(MapUtil.<String, String>builder()
|
||||||
.put("app", "hudi-sync")
|
.put("app", "hudi-sync")
|
||||||
.put("run_type", "sync")
|
.put("run_type", "sync")
|
||||||
.put("flink_job_id", flinkJobId.toString())
|
.put("flink_job_id", flinkJobId.toString())
|
||||||
|
.put("limit", "1000")
|
||||||
.build())
|
.build())
|
||||||
.collect(LokiLogLine::getData)
|
.collect(LokiLogLine::getData)
|
||||||
.collect(line -> line.replaceAll(":\\n", ""))
|
.collect(this::preHandle)
|
||||||
.collect(line -> line.replaceAll("\\n$", ""))
|
|
||||||
.collect(line -> line.replaceAll("^\\s*(.+)\\s*#@#\\s*(.+)\\s*$", "$1: $2"))
|
|
||||||
.makeString("\n"));
|
.makeString("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,11 +55,21 @@ public class LogController extends BaseController {
|
|||||||
.put("run_type", "compaction")
|
.put("run_type", "compaction")
|
||||||
.put("flink_job_id", flinkJobId.toString())
|
.put("flink_job_id", flinkJobId.toString())
|
||||||
.put("alias", alias)
|
.put("alias", alias)
|
||||||
|
.put("limit", "1000")
|
||||||
.build())
|
.build())
|
||||||
.collect(LokiLogLine::getData)
|
.collect(LokiLogLine::getData)
|
||||||
.collect(line -> line.replaceAll(":\\n", ""))
|
.collect(this::preHandle)
|
||||||
.collect(line -> line.replaceAll("\\n$", ""))
|
.makeString("\n"));
|
||||||
.collect(line -> line.replaceAll("^\\s*(.+?)\\s*#@#\\s*(.+?)\\s*$", "$1: $2"))
|
}
|
||||||
|
|
||||||
|
@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"));
|
.makeString("\n"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,44 @@ function timeAndFrom(field, fromNow, emptyText = '未停止', showSource = true)
|
|||||||
return tpl
|
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() {
|
function yarnCrudColumns() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -163,6 +201,10 @@ function yarnCrudColumns() {
|
|||||||
actionType: 'url',
|
actionType: 'url',
|
||||||
url: '${trackingUrl}',
|
url: '${trackingUrl}',
|
||||||
blank: true,
|
blank: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '日志',
|
||||||
|
...applicationLogDialog(),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user