From e13c28bd4afed29cdafbb9e9fea66d5d009275f0 Mon Sep 17 00:00:00 2001 From: zenador Date: Fri, 15 Nov 2024 22:09:50 +0800 Subject: [PATCH] Use a function to determine if an aggregation function is experimental (#15331) Signed-off-by: Jeanette Tan --- promql/parser/lex.go | 6 ++++++ promql/parser/parse.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/promql/parser/lex.go b/promql/parser/lex.go index 82bf0367b..7210d51b7 100644 --- a/promql/parser/lex.go +++ b/promql/parser/lex.go @@ -68,6 +68,12 @@ func (i ItemType) IsAggregatorWithParam() bool { return i == TOPK || i == BOTTOMK || i == COUNT_VALUES || i == QUANTILE || i == LIMITK || i == LIMIT_RATIO } +// IsExperimentalAggregator defines the experimental aggregation functions that are controlled +// with EnableExperimentalFunctions. +func (i ItemType) IsExperimentalAggregator() bool { + return i == LIMITK || i == LIMIT_RATIO +} + // IsKeyword returns true if the Item corresponds to a keyword. // Returns false otherwise. func (i ItemType) IsKeyword() bool { return i > keywordsStart && i < keywordsEnd } diff --git a/promql/parser/parse.go b/promql/parser/parse.go index 05549eaac..3113d18d5 100644 --- a/promql/parser/parse.go +++ b/promql/parser/parse.go @@ -447,8 +447,8 @@ func (p *parser) newAggregateExpr(op Item, modifier, args Node) (ret *AggregateE desiredArgs := 1 if ret.Op.IsAggregatorWithParam() { - if !EnableExperimentalFunctions && (ret.Op == LIMITK || ret.Op == LIMIT_RATIO) { - p.addParseErrf(ret.PositionRange(), "limitk() and limit_ratio() are experimental and must be enabled with --enable-feature=promql-experimental-functions") + if !EnableExperimentalFunctions && ret.Op.IsExperimentalAggregator() { + p.addParseErrf(ret.PositionRange(), "%s() is experimental and must be enabled with --enable-feature=promql-experimental-functions", ret.Op) return } desiredArgs = 2