promql: Fix (and simplify) populating iterators

This was only relevant so far for the benchmark suite as it would
recycle Expr for repetitions. However, the append is unnecessary as
each node is only inspected once when populating iterators, and
population must always start from scratch.

This also introduces error checking during benchmarks and fixes the so
far undetected test errors during benchmarking.

Also, remove a style nit (two golint warnings less…).
pull/1917/head
beorn7 2016-08-24 18:37:09 +02:00
parent 4b8f963847
commit 71571a8ec4
4 changed files with 13 additions and 21 deletions

View File

@ -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++
}
}

View File

@ -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
})

View File

@ -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

View File

@ -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)