@@ -71,6 +71,14 @@ const (
71
71
recordingRuleFilter string = "record"
72
72
)
73
73
74
+ type DisabledRuleGroupErr struct {
75
+ Message string
76
+ }
77
+
78
+ func (e * DisabledRuleGroupErr ) Error () string {
79
+ return e .Message
80
+ }
81
+
74
82
// Config is the configuration for the recording rules server.
75
83
type Config struct {
76
84
// This is used for template expansion in alerts; must be a valid URL.
@@ -415,9 +423,19 @@ func tokenForGroup(g *rulespb.RuleGroupDesc) uint32 {
415
423
return ringHasher .Sum32 ()
416
424
}
417
425
418
- func instanceOwnsRuleGroup (r ring.ReadRing , g * rulespb.RuleGroupDesc , instanceAddr string ) (bool , error ) {
426
+ func instanceOwnsRuleGroup (r ring.ReadRing , g * rulespb.RuleGroupDesc , disabledRuleGroups validation. DisabledRuleGroups , instanceAddr string ) (bool , error ) {
419
427
hash := tokenForGroup (g )
420
428
429
+ for _ , disabledGroup := range disabledRuleGroups {
430
+
431
+ if hash == tokenForGroup (& rulespb.RuleGroupDesc {
432
+ Name : disabledGroup .Name ,
433
+ Namespace : disabledGroup .Namespace ,
434
+ User : disabledGroup .User ,
435
+ }) {
436
+ return false , & DisabledRuleGroupErr {Message : fmt .Sprintf ("skipping rule group %s, within namespace %s, owned by %s" , g .Name , g .Namespace , g .User )}
437
+ }
438
+ }
421
439
rlrs , err := r .Get (hash , RingOp , nil , nil , nil )
422
440
if err != nil {
423
441
return false , errors .Wrap (err , "error reading ring to verify rule group ownership" )
@@ -544,7 +562,7 @@ func (r *Ruler) listRulesShardingDefault(ctx context.Context) (map[string]rulesp
544
562
545
563
filteredConfigs := make (map [string ]rulespb.RuleGroupList )
546
564
for userID , groups := range configs {
547
- filtered := filterRuleGroups (userID , groups , r .ring , r .lifecycler .GetInstanceAddr (), r .logger , r .ringCheckErrors )
565
+ filtered := filterRuleGroups (userID , groups , r .limits . DisabledRuleGroups ( userID ), r . ring , r .lifecycler .GetInstanceAddr (), r .logger , r .ringCheckErrors )
548
566
if len (filtered ) > 0 {
549
567
filteredConfigs [userID ] = filtered
550
568
}
@@ -602,7 +620,7 @@ func (r *Ruler) listRulesShuffleSharding(ctx context.Context) (map[string]rulesp
602
620
return errors .Wrapf (err , "failed to fetch rule groups for user %s" , userID )
603
621
}
604
622
605
- filtered := filterRuleGroups (userID , groups , userRings [userID ], r .lifecycler .GetInstanceAddr (), r .logger , r .ringCheckErrors )
623
+ filtered := filterRuleGroups (userID , groups , r . limits . DisabledRuleGroups ( userID ), userRings [userID ], r .lifecycler .GetInstanceAddr (), r .logger , r .ringCheckErrors )
606
624
if len (filtered ) == 0 {
607
625
continue
608
626
}
@@ -624,15 +642,21 @@ func (r *Ruler) listRulesShuffleSharding(ctx context.Context) (map[string]rulesp
624
642
//
625
643
// Reason why this function is not a method on Ruler is to make sure we don't accidentally use r.ring,
626
644
// but only ring passed as parameter.
627
- func filterRuleGroups (userID string , ruleGroups []* rulespb.RuleGroupDesc , ring ring.ReadRing , instanceAddr string , log log.Logger , ringCheckErrors prometheus.Counter ) []* rulespb.RuleGroupDesc {
645
+ func filterRuleGroups (userID string , ruleGroups []* rulespb.RuleGroupDesc , disabledRuleGroups validation. DisabledRuleGroups , ring ring.ReadRing , instanceAddr string , log log.Logger , ringCheckErrors prometheus.Counter ) []* rulespb.RuleGroupDesc {
628
646
// Prune the rule group to only contain rules that this ruler is responsible for, based on ring.
629
647
var result []* rulespb.RuleGroupDesc
630
648
for _ , g := range ruleGroups {
631
- owned , err := instanceOwnsRuleGroup (ring , g , instanceAddr )
649
+ owned , err := instanceOwnsRuleGroup (ring , g , disabledRuleGroups , instanceAddr )
632
650
if err != nil {
633
- ringCheckErrors .Inc ()
634
- level .Error (log ).Log ("msg" , "failed to check if the ruler replica owns the rule group" , "user" , userID , "namespace" , g .Namespace , "group" , g .Name , "err" , err )
635
- continue
651
+ switch e := err .(type ) {
652
+ case * DisabledRuleGroupErr :
653
+ level .Info (log ).Log ("msg" , e .Message )
654
+ continue
655
+ default :
656
+ ringCheckErrors .Inc ()
657
+ level .Error (log ).Log ("msg" , "failed to check if the ruler replica owns the rule group" , "user" , userID , "namespace" , g .Namespace , "group" , g .Name , "err" , err )
658
+ continue
659
+ }
636
660
}
637
661
638
662
if owned {
0 commit comments