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);