diff --git a/promql/bench.go b/promql/bench.go index a60091e31..b628aa2a8 100644 --- a/promql/bench.go +++ b/promql/bench.go @@ -39,7 +39,9 @@ func (b *Benchmark) Run() { b.b.ReportAllocs() b.b.ResetTimer() for i := 0; i < b.b.N; i++ { - b.t.RunAsBenchmark(b) + if err := b.t.RunAsBenchmark(b); err != nil { + b.b.Error(err) + } b.iterCount++ } } diff --git a/promql/engine.go b/promql/engine.go index bb566850e..d9c33d413 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -481,41 +481,31 @@ func (ng *Engine) populateIterators(s *EvalStmt) error { Inspect(s.Expr, func(node Node) bool { switch n := node.(type) { case *VectorSelector: - var iterators []local.SeriesIterator - var err error if s.Start.Equal(s.End) { - iterators, err = ng.querier.QueryInstant( + n.iterators, queryErr = ng.querier.QueryInstant( s.Start.Add(-n.Offset), StalenessDelta, n.LabelMatchers..., ) } else { - iterators, err = ng.querier.QueryRange( + n.iterators, queryErr = ng.querier.QueryRange( s.Start.Add(-n.Offset-StalenessDelta), s.End.Add(-n.Offset), n.LabelMatchers..., ) } - if err != nil { - queryErr = err + if queryErr != nil { return false } - for _, it := range iterators { - n.iterators = append(n.iterators, it) - } case *MatrixSelector: - iterators, err := ng.querier.QueryRange( + n.iterators, queryErr = ng.querier.QueryRange( s.Start.Add(-n.Offset-n.Range), s.End.Add(-n.Offset), n.LabelMatchers..., ) - if err != nil { - queryErr = err + if queryErr != nil { return false } - for _, it := range iterators { - n.iterators = append(n.iterators, it) - } } return true }) diff --git a/promql/functions.go b/promql/functions.go index e4d896e23..9e49dc360 100644 --- a/promql/functions.go +++ b/promql/functions.go @@ -522,7 +522,7 @@ func funcStddevOverTime(ev *evaluator, args Expressions) model.Value { for _, v := range values { sum += v.Value squaredSum += v.Value * v.Value - count += 1 + count++ } avg := sum / count return model.SampleValue(math.Sqrt(float64(squaredSum/count - avg*avg))) @@ -536,7 +536,7 @@ func funcStdvarOverTime(ev *evaluator, args Expressions) model.Value { for _, v := range values { sum += v.Value squaredSum += v.Value * v.Value - count += 1 + count++ } avg := sum / count return squaredSum/count - avg*avg diff --git a/promql/functions_test.go b/promql/functions_test.go index bbb51df37..41a5d3216 100644 --- a/promql/functions_test.go +++ b/promql/functions_test.go @@ -22,7 +22,7 @@ load 5m http_requests{path="/foo"} 0+10x8064 eval instant at 4w holt_winters(http_requests[4w], 0.3, 0.3) - {path="/foo"} 20160 + {path="/foo"} 80640 ` bench := NewBenchmark(b, input) @@ -51,7 +51,7 @@ load 1m http_requests{path="/foo"} 0+10x1440 eval instant at 1d holt_winters(http_requests[1d], 0.3, 0.3) - {path="/foo"} 20160 + {path="/foo"} 14400 ` bench := NewBenchmark(b, input) @@ -65,7 +65,7 @@ load 1m http_requests{path="/foo"} 0+10x1440 eval instant at 1d changes(http_requests[1d]) - {path="/foo"} 20160 + {path="/foo"} 1440 ` bench := NewBenchmark(b, input)