Merge pull request #1917 from prometheus/beorn7/promql
promql: Fix (and simplify) populating iterators
This commit is contained in:
commit
0ac2dbe6aa
|
@ -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++
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue