@@ -460,12 +460,45 @@ func (s *PromQLSmith) walkLabelMatchers() []*labels.Matcher {
460
460
lbls = append (lbls , l )
461
461
})
462
462
463
+ valF := func (v string ) string {
464
+ val := s .rnd .Float64 ()
465
+ switch {
466
+ case val > 0.95 :
467
+ return ""
468
+ case val > 0.90 :
469
+ return ".*"
470
+ case val > 0.85 :
471
+ return ".+"
472
+ case val > 0.75 :
473
+ return fmt .Sprintf (".*%v" , v [len (v )/ 2 :])
474
+ default :
475
+ return fmt .Sprintf ("%v.*" , v [:len (v )/ 2 ])
476
+ }
477
+ }
478
+
463
479
for i := 0 ; i < items ; i ++ {
464
480
481
+ var matcher * labels.Matcher
482
+
465
483
if lbls [orders [i ]].Name == labels .MetricName {
466
484
containsName = true
485
+ matcher = labels .MustNewMatcher (labels .MatchEqual , lbls [orders [i ]].Name , lbls [orders [i ]].Value )
486
+ } else {
487
+ res := s .rnd .Intn (4 )
488
+ matchType := labels .MatchType (res )
489
+ switch matchType {
490
+ case labels .MatchEqual :
491
+ matcher = labels .MustNewMatcher (labels .MatchEqual , lbls [orders [i ]].Name , lbls [orders [i ]].Value )
492
+ case labels .MatchNotEqual :
493
+ matcher = labels .MustNewMatcher (labels .MatchNotEqual , lbls [orders [i ]].Name , lbls [orders [i ]].Value )
494
+ case labels .MatchRegexp :
495
+ matcher = labels .MustNewMatcher (labels .MatchRegexp , lbls [orders [i ]].Name , valF (lbls [orders [i ]].Value ))
496
+ case labels .MatchNotRegexp :
497
+ matcher = labels .MustNewMatcher (labels .MatchNotRegexp , lbls [orders [i ]].Name , valF (lbls [orders [i ]].Value ))
498
+ }
467
499
}
468
- matchers = append (matchers , labels .MustNewMatcher (labels .MatchEqual , lbls [orders [i ]].Name , lbls [orders [i ]].Value ))
500
+
501
+ matchers = append (matchers , matcher )
469
502
}
470
503
471
504
if ! containsName {
@@ -482,8 +515,8 @@ func (s *PromQLSmith) walkLabelMatchers() []*labels.Matcher {
482
515
return matchers
483
516
}
484
517
485
- // walkSelectors is similar to walkLabelMatchers, but used for generating various
486
- // types of matchers more than simple equal matcher.
518
+ // walkSelectors is similar to walkLabelMatchers, but does not guarantee the equal
519
+ // matcher on the metric name
487
520
func (s * PromQLSmith ) walkSelectors () []* labels.Matcher {
488
521
if len (s .seriesSet ) == 0 {
489
522
return nil
0 commit comments