Skip to content

Commit a14a0af

Browse files
authored
Merge pull request #151 from VictoriaMetrics/fix-stats-check
fix the check for the stats pipe
2 parents dc5acfb + 4dc0c28 commit a14a0af

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## tip
44

5+
* BUGFIX: fix the check for the stats pipe functions in expressions.
56
* BUGFIX: fix plugin loading issue in Grafana `v10.x.x`. See [this issue](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/149).
67

78
## v0.11.0

src/LogsQL/statsPipeFunctions.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const statsPipeFunctions = [
2+
"avg",
3+
"count",
4+
"count_empty",
5+
"count_uniq",
6+
"count_uniq_hash",
7+
"max",
8+
"median",
9+
"min",
10+
"quantile",
11+
"rate",
12+
"rate_sum",
13+
"row_any",
14+
"row_max",
15+
"row_min",
16+
"sum",
17+
"sum_len",
18+
"uniq_values",
19+
"values"
20+
];
21+
22+
export const isExprHasStatsPipeFunctions = (expr: string) => {
23+
const regex = new RegExp(`.*\\|.*\\b(${statsPipeFunctions.join("|")})\\b`, "mi");
24+
return regex.test(expr)
25+
}

src/components/QueryEditor/QueryEditor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React, { useCallback, useEffect, useState } from 'react';
55
import { CoreApp, GrafanaTheme2, LoadingState } from '@grafana/data';
66
import { Button, ConfirmModal, useStyles2 } from '@grafana/ui';
77

8+
import { isExprHasStatsPipeFunctions } from "../../LogsQL/statsPipeFunctions";
89
import { Query, QueryEditorMode, QueryType, VictoriaLogsQueryEditorProps } from "../../types";
910
import QueryEditorStatsWarn from "../QueryEditorStatsWarn";
1011

@@ -26,7 +27,7 @@ const QueryEditor = React.memo<VictoriaLogsQueryEditorProps>((props) => {
2627
const query = getQueryWithDefaults(props.query, app, data?.request?.panelPluginId);
2728
const editorMode = query.editorMode!;
2829
const isStatsQuery = query.queryType === QueryType.Stats || query.queryType === QueryType.StatsRange;
29-
const showStatsWarn = isStatsQuery && !query.expr.includes('stats');
30+
const showStatsWarn = isStatsQuery && !isExprHasStatsPipeFunctions(query.expr || '');
3031

3132
const onEditorModeChange = useCallback((newEditorMode: QueryEditorMode) => {
3233
if (newEditorMode === QueryEditorMode.Builder) {

0 commit comments

Comments
 (0)