mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add type check on topk/bottomk parameter.
This commit is contained in:
parent
fa9cc15573
commit
7f23a4a099
|
@ -1049,6 +1049,9 @@ func (p *parser) checkType(node Node) (typ model.ValueType) {
|
||||||
p.errorf("aggregation operator expected in aggregation expression but got %q", n.Op)
|
p.errorf("aggregation operator expected in aggregation expression but got %q", n.Op)
|
||||||
}
|
}
|
||||||
p.expectType(n.Expr, model.ValVector, "aggregation expression")
|
p.expectType(n.Expr, model.ValVector, "aggregation expression")
|
||||||
|
if n.Op == itemTopK || n.Op == itemBottomK {
|
||||||
|
p.expectType(n.Param, model.ValScalar, "aggregation parameter")
|
||||||
|
}
|
||||||
|
|
||||||
case *BinaryExpr:
|
case *BinaryExpr:
|
||||||
lt := p.checkType(n.LHS)
|
lt := p.checkType(n.LHS)
|
||||||
|
|
|
@ -1253,6 +1253,10 @@ var testExpr = []struct {
|
||||||
input: `topk(some_metric)`,
|
input: `topk(some_metric)`,
|
||||||
fail: true,
|
fail: true,
|
||||||
errMsg: "parse error at char 17: unexpected \")\" in aggregation, expected \",\"",
|
errMsg: "parse error at char 17: unexpected \")\" in aggregation, expected \",\"",
|
||||||
|
}, {
|
||||||
|
input: `topk(some_metric, other_metric)`,
|
||||||
|
fail: true,
|
||||||
|
errMsg: "parse error at char 32: expected type scalar in aggregation parameter, got vector",
|
||||||
},
|
},
|
||||||
// Test function calls.
|
// Test function calls.
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue