vmui/logs: add support for head|limit in expressions

This commit is contained in:
Yury Moladau 2024-04-19 15:49:05 +02:00
parent 249a467ea4
commit 1e17eac2bd
No known key found for this signature in database
GPG key ID: 79AD43149C47BDE7
2 changed files with 11 additions and 1 deletions

View file

@ -13,13 +13,21 @@ export const useFetchLogs = (server: string, query: string, limit: number) => {
const url = useMemo(() => getLogsUrl(server), [server]);
const prepareQuery = (query: string) => {
const limitRegex = /\|\s*(limit|head)\s*:?[\s-]*\d+/gm;
const matchHeadLimit = query.match(limitRegex);
if (!matchHeadLimit) return `(${query})`;
const cleanedQuery = query.replace(limitRegex, "").trim();
return `(${cleanedQuery}) ${matchHeadLimit.join(" ")}`;
};
// include time range in query if not already present
const queryWithTime = useMemo(() => {
if (!/_time/.test(query)) {
const start = dayjs(period.start * 1000).tz().toISOString();
const end = dayjs(period.end * 1000).tz().toISOString();
const timerange = `_time:[${start}, ${end}]`;
return `${timerange} AND (${query})`;
return `${timerange} AND ${prepareQuery(query)}`;
}
return query;
}, [query, period]);

View file

@ -19,6 +19,8 @@ according to [these docs](https://docs.victoriametrics.com/VictoriaLogs/QuickSta
## tip
* FEATURE: [web UI](https://docs.victoriametrics.com/VictoriaLogs/querying/#web-ui): add support for head|limit in expressions. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/6154).
## [v0.5.2](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.5.2-victorialogs)
Released at 2024-04-11