mirror of
https://github.com/prometheus/prometheus.git
synced 2025-12-16 15:01:02 +01:00
[PERF] PromQL: Don't wrap matrix selectors as time-invariant
Matrix selectors have a Timestamp which indicates they are time-invariant, so we don't need to wrap and then unwrap them when we come to use them. Fix up tests that check this level of detail. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
b290e0ec17
commit
94d3cac4ea
@ -1781,8 +1781,7 @@ func (ev *evaluator) eval(ctx context.Context, expr parser.Expr) (parser.Value,
|
||||
}
|
||||
|
||||
unwrapParenExpr(&e.Args[matrixArgIndex])
|
||||
arg := unwrapStepInvariantExpr(e.Args[matrixArgIndex])
|
||||
unwrapParenExpr(&arg)
|
||||
arg := e.Args[matrixArgIndex]
|
||||
sel := arg.(*parser.MatrixSelector)
|
||||
selVS := sel.VectorSelector.(*parser.VectorSelector)
|
||||
|
||||
@ -3794,7 +3793,9 @@ func preprocessExprHelper(expr parser.Expr, start, end time.Time) (isStepInvaria
|
||||
return false, false
|
||||
|
||||
case *parser.MatrixSelector:
|
||||
return preprocessExprHelper(n.VectorSelector, start, end)
|
||||
// We don't need to wrap a MatrixSelector because functions over range vectors evaluate those directly.
|
||||
isStepInvariant, _ := preprocessExprHelper(n.VectorSelector, start, end)
|
||||
return isStepInvariant, false
|
||||
|
||||
case *parser.SubqueryExpr:
|
||||
// Since we adjust offset for the @ modifier evaluation,
|
||||
|
||||
@ -2423,8 +2423,7 @@ func TestPreprocessAndWrapWithStepInvariantExpr(t *testing.T) {
|
||||
},
|
||||
{
|
||||
input: `test{a="b"}[5y] @ 1603774699`,
|
||||
expected: &parser.StepInvariantExpr{
|
||||
Expr: &parser.MatrixSelector{
|
||||
expected: &parser.MatrixSelector{
|
||||
VectorSelector: &parser.VectorSelector{
|
||||
Name: "test",
|
||||
Timestamp: makeInt64Pointer(1603774699000),
|
||||
@ -2441,7 +2440,6 @@ func TestPreprocessAndWrapWithStepInvariantExpr(t *testing.T) {
|
||||
EndPos: 28,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
input: "sum by (foo)(some_metric)",
|
||||
expected: &parser.AggregateExpr{
|
||||
@ -2938,9 +2936,16 @@ func TestPreprocessAndWrapWithStepInvariantExpr(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `test[5y] @ start()`,
|
||||
input: `sum_over_time(test[5y] @ start())`,
|
||||
expected: &parser.StepInvariantExpr{
|
||||
Expr: &parser.MatrixSelector{
|
||||
Expr: &parser.Call{
|
||||
Func: &parser.Function{
|
||||
Name: "sum_over_time",
|
||||
ArgTypes: []parser.ValueType{parser.ValueTypeMatrix},
|
||||
ReturnType: parser.ValueTypeVector,
|
||||
},
|
||||
Args: parser.Expressions{
|
||||
&parser.MatrixSelector{
|
||||
VectorSelector: &parser.VectorSelector{
|
||||
Name: "test",
|
||||
Timestamp: makeInt64Pointer(timestamp.FromTime(startTime)),
|
||||
@ -2949,19 +2954,21 @@ func TestPreprocessAndWrapWithStepInvariantExpr(t *testing.T) {
|
||||
parser.MustLabelMatcher(labels.MatchEqual, "__name__", "test"),
|
||||
},
|
||||
PosRange: posrange.PositionRange{
|
||||
Start: 0,
|
||||
End: 4,
|
||||
Start: 14,
|
||||
End: 18,
|
||||
},
|
||||
},
|
||||
Range: 5 * 365 * 24 * time.Hour,
|
||||
EndPos: 18,
|
||||
EndPos: 32,
|
||||
},
|
||||
},
|
||||
PosRange: posrange.PositionRange{Start: 0, End: 33},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `test[5y] @ end()`,
|
||||
expected: &parser.StepInvariantExpr{
|
||||
Expr: &parser.MatrixSelector{
|
||||
expected: &parser.MatrixSelector{
|
||||
VectorSelector: &parser.VectorSelector{
|
||||
Name: "test",
|
||||
Timestamp: makeInt64Pointer(timestamp.FromTime(endTime)),
|
||||
@ -2978,7 +2985,6 @@ func TestPreprocessAndWrapWithStepInvariantExpr(t *testing.T) {
|
||||
EndPos: 16,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
input: `some_metric[10m:5s] @ start()`,
|
||||
expected: &parser.StepInvariantExpr{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user