Skip to content

Commit a43f047

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

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

engine/engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func TestQueriesAgainstOldEngine(t *testing.T) {
250250
load: `load 30s
251251
http_requests_total{pod="nginx-1"} 1+1.1x10
252252
http_requests_total{pod="nginx-2"} 2+2.3x50`,
253-
query: `predict_linear({__name__="http_requests_total", pod!~"nginx-1"}[5m] @ start(), -0.37690610678629094)`,
253+
query: `predict_linear({__name__="http_requests_total",pod!~"nginx-1"}[5m] @ start(), -0.37690610678629094)`,
254254
end: time.Unix(600, 0),
255255
start: time.Unix(300, 0),
256256
},

logicalplan/logical_nodes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func (f *VectorSelector) ReturnType() parser.ValueType { return parser.ValueType
115115
type MatrixSelector struct {
116116
VectorSelector *VectorSelector `json:"-"`
117117
Range time.Duration
118+
Timestamp *int64
118119

119120
// Needed because this operator is used in the distributed mode
120121
OriginalString string

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+
// matrix selector to be invariant. The scanner will only scan points once in such cases.
255+
ms.Timestamp = ms.VectorSelector.Timestamp
256+
}
257+
return n
252258
}
253259
return &StepInvariantExpr{Expr: replacePrometheusNodes(t.Expr)}
254260
case *parser.MatrixSelector:

storage/prometheus/scanners.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (p Scanners) NewMatrixSelector(
134134
call.Func.Name,
135135
arg,
136136
arg2,
137-
logicalNode.VectorSelector.Timestamp,
137+
logicalNode.Timestamp,
138138
opts,
139139
logicalNode.Range,
140140
vs.Offset,

0 commit comments

Comments
 (0)