Merge pull request #1917 from prometheus/beorn7/promql

promql: Fix (and simplify) populating iterators
This commit is contained in:
Björn Rabenstein 2016-08-26 08:42:44 +02:00 committed by GitHub
commit 0ac2dbe6aa
4 changed files with 13 additions and 21 deletions

View File

@ -39,7 +39,9 @@ func (b *Benchmark) Run() {
b.b.ReportAllocs() b.b.ReportAllocs()
b.b.ResetTimer() b.b.ResetTimer()
for i := 0; i < b.b.N; i++ { 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++ b.iterCount++
} }
} }

View File

@ -481,41 +481,31 @@ func (ng *Engine) populateIterators(s *EvalStmt) error {
Inspect(s.Expr, func(node Node) bool { Inspect(s.Expr, func(node Node) bool {
switch n := node.(type) { switch n := node.(type) {
case *VectorSelector: case *VectorSelector:
var iterators []local.SeriesIterator
var err error
if s.Start.Equal(s.End) { if s.Start.Equal(s.End) {
iterators, err = ng.querier.QueryInstant( n.iterators, queryErr = ng.querier.QueryInstant(
s.Start.Add(-n.Offset), s.Start.Add(-n.Offset),
StalenessDelta, StalenessDelta,
n.LabelMatchers..., n.LabelMatchers...,
) )
} else { } else {
iterators, err = ng.querier.QueryRange( n.iterators, queryErr = ng.querier.QueryRange(
s.Start.Add(-n.Offset-StalenessDelta), s.Start.Add(-n.Offset-StalenessDelta),
s.End.Add(-n.Offset), s.End.Add(-n.Offset),
n.LabelMatchers..., n.LabelMatchers...,
) )
} }
if err != nil { if queryErr != nil {
queryErr = err
return false return false
} }
for _, it := range iterators {
n.iterators = append(n.iterators, it)
}
case *MatrixSelector: case *MatrixSelector:
iterators, err := ng.querier.QueryRange( n.iterators, queryErr = ng.querier.QueryRange(
s.Start.Add(-n.Offset-n.Range), s.Start.Add(-n.Offset-n.Range),
s.End.Add(-n.Offset), s.End.Add(-n.Offset),
n.LabelMatchers..., n.LabelMatchers...,
) )
if err != nil { if queryErr != nil {
queryErr = err
return false return false
} }
for _, it := range iterators {
n.iterators = append(n.iterators, it)
}
} }
return true return true
}) })

View File

@ -522,7 +522,7 @@ func funcStddevOverTime(ev *evaluator, args Expressions) model.Value {
for _, v := range values { for _, v := range values {
sum += v.Value sum += v.Value
squaredSum += v.Value * v.Value squaredSum += v.Value * v.Value
count += 1 count++
} }
avg := sum / count avg := sum / count
return model.SampleValue(math.Sqrt(float64(squaredSum/count - avg*avg))) 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 { for _, v := range values {
sum += v.Value sum += v.Value
squaredSum += v.Value * v.Value squaredSum += v.Value * v.Value
count += 1 count++
} }
avg := sum / count avg := sum / count
return squaredSum/count - avg*avg return squaredSum/count - avg*avg

View File

@ -22,7 +22,7 @@ load 5m
http_requests{path="/foo"} 0+10x8064 http_requests{path="/foo"} 0+10x8064
eval instant at 4w holt_winters(http_requests[4w], 0.3, 0.3) eval instant at 4w holt_winters(http_requests[4w], 0.3, 0.3)
{path="/foo"} 20160 {path="/foo"} 80640
` `
bench := NewBenchmark(b, input) bench := NewBenchmark(b, input)
@ -51,7 +51,7 @@ load 1m
http_requests{path="/foo"} 0+10x1440 http_requests{path="/foo"} 0+10x1440
eval instant at 1d holt_winters(http_requests[1d], 0.3, 0.3) eval instant at 1d holt_winters(http_requests[1d], 0.3, 0.3)
{path="/foo"} 20160 {path="/foo"} 14400
` `
bench := NewBenchmark(b, input) bench := NewBenchmark(b, input)
@ -65,7 +65,7 @@ load 1m
http_requests{path="/foo"} 0+10x1440 http_requests{path="/foo"} 0+10x1440
eval instant at 1d changes(http_requests[1d]) eval instant at 1d changes(http_requests[1d])
{path="/foo"} 20160 {path="/foo"} 1440
` `
bench := NewBenchmark(b, input) bench := NewBenchmark(b, input)