Skip to content

Commit 2ec4376

Browse files
committed
Fix acceptance test failures
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
1 parent f0653e4 commit 2ec4376

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

logicalplan/logical_nodes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type VectorSelector struct {
7373
Filters []*labels.Matcher
7474
BatchSize int64
7575
SelectTimestamp bool
76+
Invariant bool
7677
Projection Projection
7778
// When set, histogram iterators can return objects which only have their
7879
// CounterResetHint, Count and Sum values populated. Histogram buckets and spans

logicalplan/plan.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,13 @@ func replacePrometheusNodes(plan parser.Expr) Node {
248248
// parents of matrixselector nodes are always expected to be functions, not step invariant
249249
// operators.
250250
if m, ok := t.Expr.(*parser.MatrixSelector); ok {
251-
return replacePrometheusNodes(m)
251+
n := replacePrometheusNodes(m)
252+
if ms, ok := n.(*MatrixSelector); ok {
253+
// For cases such as predict_linear(metric[5m] @start() , 0.3), we mark the
254+
// vector selector to be invariant. The scanner will only scan points once in such cases.
255+
ms.VectorSelector.Invariant = true
256+
}
257+
return n
252258
}
253259
return &StepInvariantExpr{Expr: replacePrometheusNodes(t.Expr)}
254260
case *parser.MatrixSelector:

storage/prometheus/scanners.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ func (p Scanners) NewMatrixSelector(
126126
selector = newHistogramStatsSelector(selector)
127127
}
128128

129+
var ts *int64
130+
if logicalNode.VectorSelector.Invariant {
131+
ts = logicalNode.VectorSelector.Timestamp
132+
}
133+
129134
operators := make([]model.VectorOperator, 0, opts.DecodingConcurrency)
130135
for i := 0; i < opts.DecodingConcurrency; i++ {
131136
operator, err := NewMatrixSelector(
@@ -134,7 +139,7 @@ func (p Scanners) NewMatrixSelector(
134139
call.Func.Name,
135140
arg,
136141
arg2,
137-
logicalNode.VectorSelector.Timestamp,
142+
ts,
138143
opts,
139144
logicalNode.Range,
140145
vs.Offset,

0 commit comments

Comments
 (0)