From 75bd1831bb694e9c598ea34bab2afe91ccdf13f4 Mon Sep 17 00:00:00 2001 From: Yury Molodov Date: Wed, 22 May 2024 21:44:13 +0200 Subject: [PATCH] vmui/logs: fix parsing long `_msg` values (#6310) This PR fixes an issue where parsing long `_msg` values caused errors, resulting in some log records not being displayed. The error occurred due to partial processing of strings. In some cases, a long record could be split into multiple chunks, causing only part of the record to be processed instead of the entire entry. #6281 Co-authored-by: Aliaksandr Valialkin --- .../pages/ExploreLogs/hooks/useFetchLogs.ts | 38 +++---------------- docs/VictoriaLogs/CHANGELOG.md | 1 + 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/app/vmui/packages/vmui/src/pages/ExploreLogs/hooks/useFetchLogs.ts b/app/vmui/packages/vmui/src/pages/ExploreLogs/hooks/useFetchLogs.ts index a9b8eaca7..21f63449c 100644 --- a/app/vmui/packages/vmui/src/pages/ExploreLogs/hooks/useFetchLogs.ts +++ b/app/vmui/packages/vmui/src/pages/ExploreLogs/hooks/useFetchLogs.ts @@ -35,49 +35,22 @@ export const useFetchLogs = (server: string, query: string, limit: number) => { }; const fetchLogs = useCallback(async () => { - const limit = Number(options.body.get("limit")) + 1; + const limit = Number(options.body.get("limit")); setIsLoading(true); setError(undefined); try { const response = await fetch(url, options); + const text = await response.text(); if (!response.ok || !response.body) { - const errorText = await response.text(); - setError(errorText); + setError(text); setLogs([]); setIsLoading(false); return; } - const reader = response.body.getReader(); - const decoder = new TextDecoder("utf-8"); - const result = []; - - while (reader) { - const { done, value } = await reader.read(); - - if (done) { - // "Stream finished, no more data." - break; - } - - const lines = decoder.decode(value, { stream: true }).split("\n"); - result.push(...lines); - - // Trim result to limit - // This will lose its meaning with these changes: - // https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5778 - if (result.length > limit) { - result.splice(0, result.length - limit); - } - - if (result.length >= limit) { - // Reached the maximum line limit - reader.cancel(); - break; - } - } - const data = result.map(parseLineToJSON).filter(line => line) as Logs[]; + const lines = text.split("\n").filter(line => line).slice(0, limit); + const data = lines.map(parseLineToJSON).filter(line => line) as Logs[]; setLogs(data); } catch (e) { console.error(e); @@ -96,4 +69,3 @@ export const useFetchLogs = (server: string, query: string, limit: number) => { fetchLogs, }; }; - diff --git a/docs/VictoriaLogs/CHANGELOG.md b/docs/VictoriaLogs/CHANGELOG.md index 9f0a8f49f..2fcab1a4d 100644 --- a/docs/VictoriaLogs/CHANGELOG.md +++ b/docs/VictoriaLogs/CHANGELOG.md @@ -33,6 +33,7 @@ according to [these docs](https://docs.victoriametrics.com/VictoriaLogs/QuickSta * FEATURE: [web UI](https://docs.victoriametrics.com/VictoriaLogs/querying/#web-ui): change time range limitation from `_time` in the expression to `start` and `end` query args. * BUGFIX: fix `invalid memory address or nil pointer dereference` panic when using [`extract`](https://docs.victoriametrics.com/victorialogs/logsql/#extract-pipe), [`unpack_json`](https://docs.victoriametrics.com/victorialogs/logsql/#unpack_json-pipe) or [`unpack_logfmt`](https://docs.victoriametrics.com/victorialogs/logsql/#unpack_logfmt-pipe) pipes. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6306). +* BUGFIX: [web UI](https://docs.victoriametrics.com/VictoriaLogs/querying/#web-ui): fix an issue where logs with long `_msg` values might not display. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6281). ## [v0.8.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.8.0-victorialogs)