mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 12:31:07 +01:00
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 <valyala@victoriametrics.com>
This commit is contained in:
parent
22107421eb
commit
75bd1831bb
@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user