Skip to content

Commit

Permalink
MQE: improve runtime of mixed metrics tests (#10678)
Browse files Browse the repository at this point in the history
* Make gauntlet tests ~3x faster by not using `t.Run()`

* Don't bother running functions that operate over single series at a time over multiple series at a time

* Don't run `sum` over functions that operate over range vector selectors, and only run with two series rather than up to four

* Restore one `sum` over range vector function test case
  • Loading branch information
charleskorn authored Feb 19, 2025
1 parent 6905b5d commit faec99e
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions pkg/streamingpromql/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2864,20 +2864,20 @@ func runMixedMetricsTests(t *testing.T, expressions []string, pointsPerSeries in
t.Cleanup(func() { require.NoError(t, storage.Close()) })

for _, expr := range expressions {
testName := fmt.Sprintf("Expr: %s, Start: %d, End: %d, Interval: %s", expr, start.Unix(), end.Unix(), tr.interval)
t.Run(testName, func(t *testing.T) {
q, err := prometheusEngine.NewRangeQuery(context.Background(), storage, nil, expr, start, end, tr.interval)
require.NoError(t, err)
defer q.Close()
prometheusResults := q.Exec(context.Background())
// We run so many combinations that calling t.Run() for each of them has a noticeable performance impact.
// So we instead just log the test case before we run it.
t.Logf("Expr: %s, Start: %d, End: %d, Interval: %s", expr, start.Unix(), end.Unix(), tr.interval)
q, err := prometheusEngine.NewRangeQuery(context.Background(), storage, nil, expr, start, end, tr.interval)
require.NoError(t, err)
defer q.Close()
prometheusResults := q.Exec(context.Background())

q, err = mimirEngine.NewRangeQuery(context.Background(), storage, nil, expr, start, end, tr.interval)
require.NoError(t, err)
defer q.Close()
mimirResults := q.Exec(context.Background())
q, err = mimirEngine.NewRangeQuery(context.Background(), storage, nil, expr, start, end, tr.interval)
require.NoError(t, err)
defer q.Close()
mimirResults := q.Exec(context.Background())

testutils.RequireEqualResults(t, expr, prometheusResults, mimirResults, skipAnnotationComparison)
})
testutils.RequireEqualResults(t, expr, prometheusResults, mimirResults, skipAnnotationComparison)
}
}
}
Expand All @@ -2889,10 +2889,8 @@ func TestCompareVariousMixedMetricsFunctions(t *testing.T) {

// Test each label individually to catch edge cases in with single series
labelCombinations := testutils.Combinations(labelsToUse, 1)
// Generate combinations of 2, 3, and 4 labels. (e.g., "a,b", "e,f", "c,d,e", "a,b,c,d", "c,d,e,f" etc)
// Generate combinations of 2 labels. (e.g., "a,b", "e,f" etc)
labelCombinations = append(labelCombinations, testutils.Combinations(labelsToUse, 2)...)
labelCombinations = append(labelCombinations, testutils.Combinations(labelsToUse, 3)...)
labelCombinations = append(labelCombinations, testutils.Combinations(labelsToUse, 4)...)

expressions := []string{}

Expand Down Expand Up @@ -3011,10 +3009,8 @@ func TestCompareVariousMixedMetricsVectorSelectors(t *testing.T) {

// Test each label individually to catch edge cases in with single series
labelCombinations := testutils.Combinations(labelsToUse, 1)
// Generate combinations of 2, 3, and 4 labels. (e.g., "a,b", "e,f", "c,d,e", "a,b,c,d", "c,d,e,f" etc)
// Generate combinations of 2 labels. (e.g., "a,b", "e,f" etc)
labelCombinations = append(labelCombinations, testutils.Combinations(labelsToUse, 2)...)
labelCombinations = append(labelCombinations, testutils.Combinations(labelsToUse, 3)...)
labelCombinations = append(labelCombinations, testutils.Combinations(labelsToUse, 4)...)

expressions := []string{}

Expand All @@ -3024,7 +3020,6 @@ func TestCompareVariousMixedMetricsVectorSelectors(t *testing.T) {
expressions = append(expressions, fmt.Sprintf(`%s(series{label=~"(%s)"}[45s])`, function, labelRegex))
expressions = append(expressions, fmt.Sprintf(`%s(series{label=~"(%s)"}[1m])`, function, labelRegex))
expressions = append(expressions, fmt.Sprintf(`sum(%s(series{label=~"(%s)"}[2m15s]))`, function, labelRegex))
expressions = append(expressions, fmt.Sprintf(`sum(%s(series{label=~"(%s)"}[5m]))`, function, labelRegex))
}

expressions = append(expressions, fmt.Sprintf(`predict_linear(series{label=~"(%s)"}[1m], 30)`, labelRegex))
Expand Down

0 comments on commit faec99e

Please sign in to comment.