Skip to content

Commit

Permalink
Merge pull request #151 from VictoriaMetrics/fix-stats-check
Browse files Browse the repository at this point in the history
fix the check for the stats pipe
  • Loading branch information
Loori-R authored Dec 10, 2024
2 parents dc5acfb + 4dc0c28 commit a14a0af
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## tip

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

## v0.11.0
Expand Down
25 changes: 25 additions & 0 deletions src/LogsQL/statsPipeFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const statsPipeFunctions = [
"avg",
"count",
"count_empty",
"count_uniq",
"count_uniq_hash",
"max",
"median",
"min",
"quantile",
"rate",
"rate_sum",
"row_any",
"row_max",
"row_min",
"sum",
"sum_len",
"uniq_values",
"values"
];

export const isExprHasStatsPipeFunctions = (expr: string) => {
const regex = new RegExp(`.*\\|.*\\b(${statsPipeFunctions.join("|")})\\b`, "mi");
return regex.test(expr)
}
3 changes: 2 additions & 1 deletion src/components/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { useCallback, useEffect, useState } from 'react';
import { CoreApp, GrafanaTheme2, LoadingState } from '@grafana/data';
import { Button, ConfirmModal, useStyles2 } from '@grafana/ui';

import { isExprHasStatsPipeFunctions } from "../../LogsQL/statsPipeFunctions";
import { Query, QueryEditorMode, QueryType, VictoriaLogsQueryEditorProps } from "../../types";
import QueryEditorStatsWarn from "../QueryEditorStatsWarn";

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

const onEditorModeChange = useCallback((newEditorMode: QueryEditorMode) => {
if (newEditorMode === QueryEditorMode.Builder) {
Expand Down

0 comments on commit a14a0af

Please sign in to comment.