@@ -166,7 +166,7 @@ func TestExperimentalPromQLFuncsWithPrometheus(t *testing.T) {
166
166
}
167
167
ps := promqlsmith .New (rnd , lbls , opts ... )
168
168
169
- runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 )
169
+ runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 , false )
170
170
}
171
171
172
172
func TestDisableChunkTrimmingFuzz (t * testing.T ) {
@@ -289,7 +289,7 @@ func TestDisableChunkTrimmingFuzz(t *testing.T) {
289
289
expr = ps .WalkRangeQuery ()
290
290
query = expr .Pretty (0 )
291
291
// timestamp is a known function that break with disable chunk trimming.
292
- if isValidQuery (expr , 5 ) && ! strings .Contains (query , "timestamp" ) {
292
+ if isValidQuery (expr , 5 , false ) && ! strings .Contains (query , "timestamp" ) {
293
293
break
294
294
}
295
295
}
@@ -454,17 +454,19 @@ func TestExpandedPostingsCacheFuzz(t *testing.T) {
454
454
455
455
// Create the queries with the original labels
456
456
testRun := 300
457
- queries := make ([]string , testRun )
458
- matchers := make ([]string , testRun )
457
+ queries := make ([]string , 0 , testRun )
458
+ matchers := make ([]string , 0 , testRun )
459
459
for i := 0 ; i < testRun ; i ++ {
460
460
expr := ps .WalkRangeQuery ()
461
- queries [i ] = expr .Pretty (0 )
462
- matchers [i ] = storepb .PromMatchersToString (
461
+ if isValidQuery (expr , 5 , true ) {
462
+ break
463
+ }
464
+ queries = append (queries , expr .Pretty (0 ))
465
+ matchers = append (matchers , storepb .PromMatchersToString (
463
466
append (
464
467
ps .WalkSelectors (),
465
468
labels .MustNewMatcher (labels .MatchEqual , "__name__" , fmt .Sprintf ("test_series_%d" , i % numSeries )),
466
- )... ,
467
- )
469
+ )... ))
468
470
}
469
471
470
472
// Lets run multiples iterations and create new series every iteration
@@ -680,7 +682,7 @@ func TestVerticalShardingFuzz(t *testing.T) {
680
682
}
681
683
ps := promqlsmith .New (rnd , lbls , opts ... )
682
684
683
- runQueryFuzzTestCases (t , ps , c1 , c2 , now , start , end , scrapeInterval , 1000 )
685
+ runQueryFuzzTestCases (t , ps , c1 , c2 , now , start , end , scrapeInterval , 1000 , false )
684
686
}
685
687
686
688
func TestProtobufCodecFuzz (t * testing.T ) {
@@ -796,7 +798,7 @@ func TestProtobufCodecFuzz(t *testing.T) {
796
798
}
797
799
ps := promqlsmith .New (rnd , lbls , opts ... )
798
800
799
- runQueryFuzzTestCases (t , ps , c1 , c2 , now , start , end , scrapeInterval , 1000 )
801
+ runQueryFuzzTestCases (t , ps , c1 , c2 , now , start , end , scrapeInterval , 1000 , false )
800
802
}
801
803
802
804
var sampleNumComparer = cmp .Comparer (func (x , y model.Value ) bool {
@@ -1416,7 +1418,7 @@ func TestBackwardCompatibilityQueryFuzz(t *testing.T) {
1416
1418
}
1417
1419
ps := promqlsmith .New (rnd , lbls , opts ... )
1418
1420
1419
- runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 )
1421
+ runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 , true )
1420
1422
}
1421
1423
1422
1424
// TestPrometheusCompatibilityQueryFuzz compares Cortex with latest Prometheus release.
@@ -1529,7 +1531,7 @@ func TestPrometheusCompatibilityQueryFuzz(t *testing.T) {
1529
1531
}
1530
1532
ps := promqlsmith .New (rnd , lbls , opts ... )
1531
1533
1532
- runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 )
1534
+ runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 , false )
1533
1535
}
1534
1536
1535
1537
// waitUntilReady is a helper function to wait and check if both servers to test load the expected data.
@@ -1567,7 +1569,7 @@ func waitUntilReady(t *testing.T, ctx context.Context, c1, c2 *e2ecortex.Client,
1567
1569
}
1568
1570
1569
1571
// runQueryFuzzTestCases executes the fuzz test for the specified number of runs for both instant and range queries.
1570
- func runQueryFuzzTestCases (t * testing.T , ps * promqlsmith.PromQLSmith , c1 , c2 * e2ecortex.Client , queryTime , start , end time.Time , step time.Duration , run int ) {
1572
+ func runQueryFuzzTestCases (t * testing.T , ps * promqlsmith.PromQLSmith , c1 , c2 * e2ecortex.Client , queryTime , start , end time.Time , step time.Duration , run int , skipStdAggregations bool ) {
1571
1573
type testCase struct {
1572
1574
query string
1573
1575
res1 , res2 model.Value
@@ -1583,7 +1585,7 @@ func runQueryFuzzTestCases(t *testing.T, ps *promqlsmith.PromQLSmith, c1, c2 *e2
1583
1585
for i := 0 ; i < run ; i ++ {
1584
1586
for {
1585
1587
expr = ps .WalkInstantQuery ()
1586
- if isValidQuery (expr , 5 ) {
1588
+ if isValidQuery (expr , 5 , skipStdAggregations ) {
1587
1589
query = expr .Pretty (0 )
1588
1590
break
1589
1591
}
@@ -1604,7 +1606,7 @@ func runQueryFuzzTestCases(t *testing.T, ps *promqlsmith.PromQLSmith, c1, c2 *e2
1604
1606
for i := 0 ; i < run ; i ++ {
1605
1607
for {
1606
1608
expr = ps .WalkRangeQuery ()
1607
- if isValidQuery (expr , 5 ) {
1609
+ if isValidQuery (expr , 5 , skipStdAggregations ) {
1608
1610
query = expr .Pretty (0 )
1609
1611
break
1610
1612
}
@@ -1655,7 +1657,7 @@ func shouldUseSampleNumComparer(query string) bool {
1655
1657
return false
1656
1658
}
1657
1659
1658
- func isValidQuery (generatedQuery parser.Expr , maxDepth int ) bool {
1660
+ func isValidQuery (generatedQuery parser.Expr , maxDepth int , skipStdAggregations bool ) bool {
1659
1661
isValid := true
1660
1662
currentDepth := 0
1661
1663
// TODO(SungJin1212): Test limitk, limit_ratio
@@ -1667,6 +1669,11 @@ func isValidQuery(generatedQuery parser.Expr, maxDepth int) bool {
1667
1669
// current skip the limit_ratio
1668
1670
return false
1669
1671
}
1672
+ if skipStdAggregations && (strings .Contains (generatedQuery .String (), "stddev" ) || strings .Contains (generatedQuery .String (), "stdvar" )) {
1673
+ // The behavior of stdvar and stddev changes in https://github.com/prometheus/prometheus/pull/14941
1674
+ // If skipStdAggregations enabled, we skip to evaluate for stddev and stdvar aggregations.
1675
+ return false
1676
+ }
1670
1677
parser .Inspect (generatedQuery , func (node parser.Node , path []parser.Node ) error {
1671
1678
if currentDepth > maxDepth {
1672
1679
isValid = false
0 commit comments