From f04d3802598aa049fdd93900e180df2dececf7e4 Mon Sep 17 00:00:00 2001 From: Ruihang Xia Date: Wed, 18 Dec 2024 16:51:46 +0800 Subject: [PATCH] fix: validate matcher op for __name__ in promql (#5191) Signed-off-by: Ruihang Xia --- src/query/src/promql/planner.rs | 7 +++++++ tests/cases/standalone/common/tql/basic.result | 4 ++++ tests/cases/standalone/common/tql/basic.sql | 2 ++ 3 files changed, 13 insertions(+) diff --git a/src/query/src/promql/planner.rs b/src/query/src/promql/planner.rs index 1e7bc27dab6a..bfdfb5981ae1 100644 --- a/src/query/src/promql/planner.rs +++ b/src/query/src/promql/planner.rs @@ -689,6 +689,13 @@ impl PromPlanner { let mut matches = label_matchers.find_matchers(METRIC_NAME); ensure!(!matches.is_empty(), NoMetricMatcherSnafu); ensure!(matches.len() == 1, MultipleMetricMatchersSnafu); + ensure!( + matches[0].op == MatchOp::Equal, + UnsupportedMatcherOpSnafu { + matcher_op: matches[0].op.to_string(), + matcher: METRIC_NAME + } + ); metric_name = matches.pop().map(|m| m.value); } diff --git a/tests/cases/standalone/common/tql/basic.result b/tests/cases/standalone/common/tql/basic.result index 5c6725dbcd07..3015101a5554 100644 --- a/tests/cases/standalone/common/tql/basic.result +++ b/tests/cases/standalone/common/tql/basic.result @@ -66,6 +66,10 @@ TQL EVAL (0, 10, '5s') {__name__!="test"}; Error: 2000(InvalidSyntax), vector selector must contain at least one non-empty matcher +TQL EVAL (0, 10, '5s') {__name__=~"test"}; + +Error: 1004(InvalidArguments), Matcher operator =~ is not supported for __name__ + -- the point at 1ms will be shadowed by the point at 2ms TQL EVAL (0, 10, '5s') test{k="a"}; diff --git a/tests/cases/standalone/common/tql/basic.sql b/tests/cases/standalone/common/tql/basic.sql index 85f29481486c..afca586ed8a1 100644 --- a/tests/cases/standalone/common/tql/basic.sql +++ b/tests/cases/standalone/common/tql/basic.sql @@ -22,6 +22,8 @@ TQL EVAL (0, 10, '5s') {__name__="test", __field__="i"}; -- NOT SUPPORTED: `__name__` matcher without equal condition TQL EVAL (0, 10, '5s') {__name__!="test"}; +TQL EVAL (0, 10, '5s') {__name__=~"test"}; + -- the point at 1ms will be shadowed by the point at 2ms TQL EVAL (0, 10, '5s') test{k="a"};