mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
vmui/logs: add support for head|limit in expressions
This commit is contained in:
parent
249a467ea4
commit
1e17eac2bd
2 changed files with 11 additions and 1 deletions
|
@ -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]);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue