Fix panic when aggregator param is not a literal.

The return value for checkForSeriesSetExpansion
is always nil, simplify.

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
This commit is contained in:
Brian Brazil 2019-03-01 12:00:14 +00:00
parent d8c06bb2b7
commit 858c363e94
3 changed files with 24 additions and 14 deletions

View file

@ -260,6 +260,11 @@ func Walk(v Visitor, node Node, path []Node) error {
} }
} }
case *AggregateExpr: case *AggregateExpr:
if n.Param != nil {
if err := Walk(v, n.Param, path); err != nil {
return err
}
}
if err := Walk(v, n.Expr, path); err != nil { if err := Walk(v, n.Expr, path); err != nil {
return err return err
} }

View file

@ -614,7 +614,7 @@ func extractFuncFromPath(p []Node) string {
return extractFuncFromPath(p[:len(p)-1]) return extractFuncFromPath(p[:len(p)-1])
} }
func checkForSeriesSetExpansion(ctx context.Context, expr Expr) error { func checkForSeriesSetExpansion(ctx context.Context, expr Expr) {
switch e := expr.(type) { switch e := expr.(type) {
case *MatrixSelector: case *MatrixSelector:
if e.series == nil { if e.series == nil {
@ -635,7 +635,6 @@ func checkForSeriesSetExpansion(ctx context.Context, expr Expr) error {
} }
} }
} }
return nil
} }
func expandSeriesSet(ctx context.Context, it storage.SeriesSet) (res []storage.Series, err error) { func expandSeriesSet(ctx context.Context, it storage.SeriesSet) (res []storage.Series, err error) {
@ -966,9 +965,7 @@ func (ev *evaluator) eval(expr Expr) Value {
} }
sel := e.Args[matrixArgIndex].(*MatrixSelector) sel := e.Args[matrixArgIndex].(*MatrixSelector)
if err := checkForSeriesSetExpansion(ev.ctx, sel); err != nil { checkForSeriesSetExpansion(ev.ctx, sel)
ev.error(err)
}
mat := make(Matrix, 0, len(sel.series)) // Output matrix. mat := make(Matrix, 0, len(sel.series)) // Output matrix.
offset := durationMilliseconds(sel.Offset) offset := durationMilliseconds(sel.Offset)
selRange := durationMilliseconds(sel.Range) selRange := durationMilliseconds(sel.Range)
@ -1100,9 +1097,7 @@ func (ev *evaluator) eval(expr Expr) Value {
}) })
case *VectorSelector: case *VectorSelector:
if err := checkForSeriesSetExpansion(ev.ctx, e); err != nil { checkForSeriesSetExpansion(ev.ctx, e)
ev.error(err)
}
mat := make(Matrix, 0, len(e.series)) mat := make(Matrix, 0, len(e.series))
it := storage.NewBuffer(durationMilliseconds(LookbackDelta)) it := storage.NewBuffer(durationMilliseconds(LookbackDelta))
for i, s := range e.series { for i, s := range e.series {
@ -1175,9 +1170,7 @@ func durationToInt64Millis(d time.Duration) int64 {
// vectorSelector evaluates a *VectorSelector expression. // vectorSelector evaluates a *VectorSelector expression.
func (ev *evaluator) vectorSelector(node *VectorSelector, ts int64) Vector { func (ev *evaluator) vectorSelector(node *VectorSelector, ts int64) Vector {
if err := checkForSeriesSetExpansion(ev.ctx, node); err != nil { checkForSeriesSetExpansion(ev.ctx, node)
ev.error(err)
}
var ( var (
vec = make(Vector, 0, len(node.series)) vec = make(Vector, 0, len(node.series))
@ -1249,9 +1242,7 @@ func putPointSlice(p []Point) {
// matrixSelector evaluates a *MatrixSelector expression. // matrixSelector evaluates a *MatrixSelector expression.
func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix { func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix {
if err := checkForSeriesSetExpansion(ev.ctx, node); err != nil { checkForSeriesSetExpansion(ev.ctx, node)
ev.error(err)
}
var ( var (
offset = durationMilliseconds(node.Offset) offset = durationMilliseconds(node.Offset)

View file

@ -153,6 +153,7 @@ load 5m
http_requests{job="app-server", instance="1", group="production"} 0+60x10 http_requests{job="app-server", instance="1", group="production"} 0+60x10
http_requests{job="app-server", instance="0", group="canary"} 0+70x10 http_requests{job="app-server", instance="0", group="canary"} 0+70x10
http_requests{job="app-server", instance="1", group="canary"} 0+80x10 http_requests{job="app-server", instance="1", group="canary"} 0+80x10
foo 3+0x10
eval_ordered instant at 50m topk(3, http_requests) eval_ordered instant at 50m topk(3, http_requests)
http_requests{group="canary", instance="1", job="app-server"} 800 http_requests{group="canary", instance="1", job="app-server"} 800
@ -207,6 +208,12 @@ eval_ordered instant at 50m topk(9999999999, http_requests{job="api-server",grou
http_requests{job="api-server", instance="0", group="production"} 100 http_requests{job="api-server", instance="0", group="production"} 100
http_requests{job="api-server", instance="2", group="production"} NaN http_requests{job="api-server", instance="2", group="production"} NaN
# Bug #5276.
eval_ordered instant at 50m topk(scalar(foo), http_requests)
http_requests{group="canary", instance="1", job="app-server"} 800
http_requests{group="canary", instance="0", job="app-server"} 700
http_requests{group="production", instance="1", job="app-server"} 600
clear clear
# Tests for count_values. # Tests for count_values.
@ -257,8 +264,15 @@ load 10s
data{test="uneven samples",point="a"} 0 data{test="uneven samples",point="a"} 0
data{test="uneven samples",point="b"} 1 data{test="uneven samples",point="b"} 1
data{test="uneven samples",point="c"} 4 data{test="uneven samples",point="c"} 4
foo .8
eval instant at 1m quantile without(point)(0.8, data) eval instant at 1m quantile without(point)(0.8, data)
{test="two samples"} 0.8 {test="two samples"} 0.8
{test="three samples"} 1.6 {test="three samples"} 1.6
{test="uneven samples"} 2.8 {test="uneven samples"} 2.8
# Bug #5276.
eval instant at 1m quantile without(point)(scalar(foo), data)
{test="two samples"} 0.8
{test="three samples"} 1.6
{test="uneven samples"} 2.8