Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate matcher op for __name__ in promql #5191

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/query/src/promql/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/cases/standalone/common/tql/basic.result
Original file line number Diff line number Diff line change
Expand Up @@ -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"};

Expand Down
2 changes: 2 additions & 0 deletions tests/cases/standalone/common/tql/basic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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"};

Expand Down
Loading