@@ -166,7 +166,7 @@ func TestExperimentalPromQLFuncsWithPrometheus(t *testing.T) {
166166 }
167167 ps := promqlsmith .New (rnd , lbls , opts ... )
168168
169- runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 )
169+ runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 , false )
170170}
171171
172172func TestDisableChunkTrimmingFuzz (t * testing.T ) {
@@ -289,7 +289,7 @@ func TestDisableChunkTrimmingFuzz(t *testing.T) {
289289 expr = ps .WalkRangeQuery ()
290290 query = expr .Pretty (0 )
291291 // 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" ) {
293293 break
294294 }
295295 }
@@ -454,17 +454,19 @@ func TestExpandedPostingsCacheFuzz(t *testing.T) {
454454
455455 // Create the queries with the original labels
456456 testRun := 300
457- queries := make ([]string , testRun )
458- matchers := make ([]string , testRun )
457+ queries := make ([]string , 0 , testRun )
458+ matchers := make ([]string , 0 , testRun )
459459 for i := 0 ; i < testRun ; i ++ {
460460 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 (
463466 append (
464467 ps .WalkSelectors (),
465468 labels .MustNewMatcher (labels .MatchEqual , "__name__" , fmt .Sprintf ("test_series_%d" , i % numSeries )),
466- )... ,
467- )
469+ )... ))
468470 }
469471
470472 // Lets run multiples iterations and create new series every iteration
@@ -680,7 +682,7 @@ func TestVerticalShardingFuzz(t *testing.T) {
680682 }
681683 ps := promqlsmith .New (rnd , lbls , opts ... )
682684
683- runQueryFuzzTestCases (t , ps , c1 , c2 , now , start , end , scrapeInterval , 1000 )
685+ runQueryFuzzTestCases (t , ps , c1 , c2 , now , start , end , scrapeInterval , 1000 , false )
684686}
685687
686688func TestProtobufCodecFuzz (t * testing.T ) {
@@ -796,7 +798,7 @@ func TestProtobufCodecFuzz(t *testing.T) {
796798 }
797799 ps := promqlsmith .New (rnd , lbls , opts ... )
798800
799- runQueryFuzzTestCases (t , ps , c1 , c2 , now , start , end , scrapeInterval , 1000 )
801+ runQueryFuzzTestCases (t , ps , c1 , c2 , now , start , end , scrapeInterval , 1000 , false )
800802}
801803
802804var sampleNumComparer = cmp .Comparer (func (x , y model.Value ) bool {
@@ -1416,7 +1418,7 @@ func TestBackwardCompatibilityQueryFuzz(t *testing.T) {
14161418 }
14171419 ps := promqlsmith .New (rnd , lbls , opts ... )
14181420
1419- runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 )
1421+ runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 , true )
14201422}
14211423
14221424// TestPrometheusCompatibilityQueryFuzz compares Cortex with latest Prometheus release.
@@ -1529,7 +1531,7 @@ func TestPrometheusCompatibilityQueryFuzz(t *testing.T) {
15291531 }
15301532 ps := promqlsmith .New (rnd , lbls , opts ... )
15311533
1532- runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 )
1534+ runQueryFuzzTestCases (t , ps , c1 , c2 , end , start , end , scrapeInterval , 1000 , false )
15331535}
15341536
15351537// 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,
15671569}
15681570
15691571// 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 ) {
15711573 type testCase struct {
15721574 query string
15731575 res1 , res2 model.Value
@@ -1583,7 +1585,7 @@ func runQueryFuzzTestCases(t *testing.T, ps *promqlsmith.PromQLSmith, c1, c2 *e2
15831585 for i := 0 ; i < run ; i ++ {
15841586 for {
15851587 expr = ps .WalkInstantQuery ()
1586- if isValidQuery (expr , 5 ) {
1588+ if isValidQuery (expr , 5 , skipStdAggregations ) {
15871589 query = expr .Pretty (0 )
15881590 break
15891591 }
@@ -1604,7 +1606,7 @@ func runQueryFuzzTestCases(t *testing.T, ps *promqlsmith.PromQLSmith, c1, c2 *e2
16041606 for i := 0 ; i < run ; i ++ {
16051607 for {
16061608 expr = ps .WalkRangeQuery ()
1607- if isValidQuery (expr , 5 ) {
1609+ if isValidQuery (expr , 5 , skipStdAggregations ) {
16081610 query = expr .Pretty (0 )
16091611 break
16101612 }
@@ -1655,7 +1657,7 @@ func shouldUseSampleNumComparer(query string) bool {
16551657 return false
16561658}
16571659
1658- func isValidQuery (generatedQuery parser.Expr , maxDepth int ) bool {
1660+ func isValidQuery (generatedQuery parser.Expr , maxDepth int , skipStdAggregations bool ) bool {
16591661 isValid := true
16601662 currentDepth := 0
16611663 // TODO(SungJin1212): Test limitk, limit_ratio
@@ -1667,6 +1669,11 @@ func isValidQuery(generatedQuery parser.Expr, maxDepth int) bool {
16671669 // current skip the limit_ratio
16681670 return false
16691671 }
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+ }
16701677 parser .Inspect (generatedQuery , func (node parser.Node , path []parser.Node ) error {
16711678 if currentDepth > maxDepth {
16721679 isValid = false
0 commit comments