@@ -294,6 +294,7 @@ type Ruler struct {
294
294
ruleGroupStoreLoadDuration prometheus.Gauge
295
295
ruleGroupSyncDuration prometheus.Gauge
296
296
rulerGetRulesFailures * prometheus.CounterVec
297
+ ruleGroupMetrics * RuleGroupMetrics
297
298
298
299
allowedTenants * util.AllowedTenants
299
300
@@ -342,6 +343,7 @@ func newRuler(cfg Config, manager MultiTenantManager, reg prometheus.Registerer,
342
343
Help : "The total number of failed rules request sent to rulers in getShardedRules." ,
343
344
}, []string {"ruler" }),
344
345
}
346
+ ruler .ruleGroupMetrics = NewRuleGroupMetrics (reg , ruler .allowedTenants )
345
347
346
348
if len (cfg .EnabledTenants ) > 0 {
347
349
level .Info (ruler .logger ).Log ("msg" , "ruler using enabled users" , "enabled" , strings .Join (cfg .EnabledTenants , ", " ))
@@ -667,7 +669,9 @@ func (r *Ruler) listRulesNoSharding(ctx context.Context) (map[string]rulespb.Rul
667
669
if err != nil {
668
670
return nil , nil , err
669
671
}
672
+ ruleGroupCounts := make (map [string ]int , len (allRuleGroups ))
670
673
for userID , groups := range allRuleGroups {
674
+ ruleGroupCounts [userID ] = len (groups )
671
675
disabledRuleGroupsForUser := r .limits .DisabledRuleGroups (userID )
672
676
if len (disabledRuleGroupsForUser ) == 0 {
673
677
continue
@@ -682,6 +686,7 @@ func (r *Ruler) listRulesNoSharding(ctx context.Context) (map[string]rulespb.Rul
682
686
}
683
687
allRuleGroups [userID ] = filteredGroupsForUser
684
688
}
689
+ r .ruleGroupMetrics .UpdateRuleGroupsInStore (ruleGroupCounts )
685
690
return allRuleGroups , nil , nil
686
691
}
687
692
@@ -691,9 +696,11 @@ func (r *Ruler) listRulesShardingDefault(ctx context.Context) (map[string]rulesp
691
696
return nil , nil , err
692
697
}
693
698
699
+ ruleGroupCounts := make (map [string ]int , len (configs ))
694
700
ownedConfigs := make (map [string ]rulespb.RuleGroupList )
695
701
backedUpConfigs := make (map [string ]rulespb.RuleGroupList )
696
702
for userID , groups := range configs {
703
+ ruleGroupCounts [userID ] = len (groups )
697
704
owned := filterRuleGroups (userID , groups , r .limits .DisabledRuleGroups (userID ), r .ring , r .lifecycler .GetInstanceAddr (), r .logger , r .ringCheckErrors )
698
705
if len (owned ) > 0 {
699
706
ownedConfigs [userID ] = owned
@@ -705,6 +712,7 @@ func (r *Ruler) listRulesShardingDefault(ctx context.Context) (map[string]rulesp
705
712
}
706
713
}
707
714
}
715
+ r .ruleGroupMetrics .UpdateRuleGroupsInStore (ruleGroupCounts )
708
716
return ownedConfigs , backedUpConfigs , nil
709
717
}
710
718
@@ -732,6 +740,7 @@ func (r *Ruler) listRulesShuffleSharding(ctx context.Context) (map[string]rulesp
732
740
}
733
741
734
742
if len (userRings ) == 0 {
743
+ r .ruleGroupMetrics .UpdateRuleGroupsInStore (make (map [string ]int ))
735
744
return nil , nil , nil
736
745
}
737
746
@@ -744,6 +753,8 @@ func (r *Ruler) listRulesShuffleSharding(ctx context.Context) (map[string]rulesp
744
753
mu := sync.Mutex {}
745
754
owned := map [string ]rulespb.RuleGroupList {}
746
755
backedUp := map [string ]rulespb.RuleGroupList {}
756
+ gLock := sync.Mutex {}
757
+ ruleGroupCounts := make (map [string ]int , len (userRings ))
747
758
748
759
concurrency := loadRulesConcurrency
749
760
if len (userRings ) < concurrency {
@@ -758,6 +769,9 @@ func (r *Ruler) listRulesShuffleSharding(ctx context.Context) (map[string]rulesp
758
769
if err != nil {
759
770
return errors .Wrapf (err , "failed to fetch rule groups for user %s" , userID )
760
771
}
772
+ gLock .Lock ()
773
+ ruleGroupCounts [userID ] = len (groups )
774
+ gLock .Unlock ()
761
775
762
776
filterOwned := filterRuleGroups (userID , groups , r .limits .DisabledRuleGroups (userID ), userRings [userID ], r .lifecycler .GetInstanceAddr (), r .logger , r .ringCheckErrors )
763
777
var filterBackup []* rulespb.RuleGroupDesc
@@ -781,6 +795,7 @@ func (r *Ruler) listRulesShuffleSharding(ctx context.Context) (map[string]rulesp
781
795
}
782
796
783
797
err = g .Wait ()
798
+ r .ruleGroupMetrics .UpdateRuleGroupsInStore (ruleGroupCounts )
784
799
return owned , backedUp , err
785
800
}
786
801
0 commit comments