MCPcopy Index your code
hub / github.com/cortexproject/cortex / syncRules

Method syncRules

pkg/ruler/ruler.go:809–836  ·  view source on GitHub ↗
(ctx context.Context, reason string)

Source from the content-addressed store, hash-verified

807}
808
809func (r *Ruler) syncRules(ctx context.Context, reason string) error {
810 level.Info(r.logger).Log("msg", "syncing rules", "reason", reason)
811 r.rulerSync.WithLabelValues(reason).Inc()
812 timer := prometheus.NewTimer(nil)
813
814 defer func() {
815 ruleGroupSyncDuration := timer.ObserveDuration().Seconds()
816 r.ruleGroupSyncDuration.Set(ruleGroupSyncDuration)
817 }()
818
819 loadedConfigs, backupConfigs, err := r.loadRuleGroups(ctx)
820 if err != nil {
821 return err
822 }
823
824 if ctx.Err() != nil {
825 level.Info(r.logger).Log("msg", "context is canceled. not syncing rules")
826 return err
827 }
828 // This will also delete local group files for users that are no longer in 'configs' map.
829 r.manager.SyncRuleGroups(ctx, loadedConfigs)
830
831 if r.cfg.RulesBackupEnabled() {
832 r.manager.BackUpRuleGroups(ctx, backupConfigs)
833 }
834
835 return nil
836}
837
838func (r *Ruler) loadRuleGroups(ctx context.Context) (map[string]rulespb.RuleGroupList, map[string]rulespb.RuleGroupList, error) {
839 timer := prometheus.NewTimer(nil)

Callers 6

runMethod · 0.95
TestGetRulesFunction · 0.80
TestGetRulesFromBackupFunction · 0.80
getRulesHATestFunction · 0.80
TestGetShardSizeForUserFunction · 0.80

Calls 8

loadRuleGroupsMethod · 0.95
RulesBackupEnabledMethod · 0.80
SetMethod · 0.65
ErrMethod · 0.65
SyncRuleGroupsMethod · 0.65
BackUpRuleGroupsMethod · 0.65
LogMethod · 0.45
IncMethod · 0.45

Tested by 5

TestGetRulesFunction · 0.64
TestGetRulesFromBackupFunction · 0.64
getRulesHATestFunction · 0.64
TestGetShardSizeForUserFunction · 0.64