From 4194d2ac7988a43c7324d69831c3e630360e35bc Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Thu, 13 Jul 2017 18:42:45 +0200 Subject: [PATCH] Call At() only if Next() is true Signed-off-by: Goutham Veeramachaneni --- promql/engine.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/promql/engine.go b/promql/engine.go index 0434a534c..eac4a4982 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -752,13 +752,19 @@ func (ev *evaluator) vectorSelector(node *VectorSelector) Vector { ) for i, it := range node.iterators { + var t int64 + var v float64 + ok := it.Seek(refTime) if !ok { if it.Err() != nil { ev.error(it.Err()) } } - t, v := it.Values() + + if ok { + t, v = it.Values() + } peek := 1 if !ok || t > refTime { @@ -851,7 +857,6 @@ func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix { ev.error(it.Err()) } } - t, v := it.Values() buf := it.Buffer() for buf.Next() { @@ -865,9 +870,11 @@ func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix { } } // The seeked sample might also be in the range. - t, v = it.Values() - if t == maxt && !value.IsStaleNaN(v) { - allPoints = append(allPoints, Point{T: t, V: v}) + if ok { + t, v := it.Values() + if t == maxt && !value.IsStaleNaN(v) { + allPoints = append(allPoints, Point{T: t, V: v}) + } } ss.Points = allPoints[start:]