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

Function newRuler

pkg/ruler/ruler.go:363–427  ·  view source on GitHub ↗
(cfg Config, manager MultiTenantManager, reg prometheus.Registerer, logger log.Logger, ruleStore rulestore.RuleStore, limits RulesLimits, clientPool ClientsPool)

Source from the content-addressed store, hash-verified

361}
362
363func newRuler(cfg Config, manager MultiTenantManager, reg prometheus.Registerer, logger log.Logger, ruleStore rulestore.RuleStore, limits RulesLimits, clientPool ClientsPool) (*Ruler, error) {
364 ruler := &Ruler{
365 cfg: cfg,
366 userIndexUpdater: ruleStore.GetUserIndexUpdater(),
367 store: ruleStore,
368 manager: manager,
369 registry: reg,
370 logger: logger,
371 limits: limits,
372 clientsPool: clientPool,
373 allowedTenants: users.NewAllowedTenants(cfg.EnabledTenants, cfg.DisabledTenants),
374
375 ringCheckErrors: promauto.With(reg).NewCounter(prometheus.CounterOpts{
376 Name: "cortex_ruler_ring_check_errors_total",
377 Help: "Number of errors that have occurred when checking the ring for ownership",
378 }),
379
380 rulerSync: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
381 Name: "cortex_ruler_sync_rules_total",
382 Help: "Total number of times the ruler sync operation triggered.",
383 }, []string{"reason"}),
384
385 ruleGroupStoreLoadDuration: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
386 Name: "cortex_ruler_rule_group_load_duration_seconds",
387 Help: "Time taken to load rule groups from storage",
388 }),
389
390 ruleGroupSyncDuration: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
391 Name: "cortex_ruler_rule_group_sync_duration_seconds",
392 Help: "The duration in seconds required to sync and load rule groups from storage.",
393 }),
394
395 rulerGetRulesFailures: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
396 Name: "cortex_ruler_get_rules_failure_total",
397 Help: "The total number of failed rules request sent to rulers in getShardedRules.",
398 }, []string{"ruler"}),
399 }
400 ruler.ruleGroupMetrics = NewRuleGroupMetrics(reg, ruler.allowedTenants)
401
402 if len(cfg.EnabledTenants) > 0 {
403 level.Info(ruler.logger).Log("msg", "ruler using enabled users", "enabled", strings.Join(cfg.EnabledTenants, ", "))
404 }
405 if len(cfg.DisabledTenants) > 0 {
406 level.Info(ruler.logger).Log("msg", "ruler using disabled users", "disabled", strings.Join(cfg.DisabledTenants, ", "))
407 }
408
409 if cfg.EnableSharding {
410 ringStore, err := kv.NewClient(
411 cfg.Ring.KVStore,
412 ring.GetCodec(),
413 kv.RegistererWithKVName(prometheus.WrapRegistererWithPrefix("cortex_", reg), "ruler"),
414 logger,
415 )
416 if err != nil {
417 return nil, errors.Wrap(err, "create KV store client")
418 }
419
420 if err = enableSharding(ruler, ringStore); err != nil {

Callers 3

NewRulerFunction · 0.85
buildRulerFunction · 0.85
buildRulerWithIterFuncFunction · 0.85

Calls 11

NewAllowedTenantsFunction · 0.92
NewClientFunction · 0.92
GetCodecFunction · 0.92
RegistererWithKVNameFunction · 0.92
NewBasicServiceFunction · 0.92
NewRuleGroupMetricsFunction · 0.85
enableShardingFunction · 0.85
JoinMethod · 0.80
GetUserIndexUpdaterMethod · 0.65
WrapMethod · 0.65
LogMethod · 0.45

Tested by 2

buildRulerFunction · 0.68
buildRulerWithIterFuncFunction · 0.68