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

Method userIndexUpdateLoop

pkg/ruler/ruler.go:743–773  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

741}
742
743func (r *Ruler) userIndexUpdateLoop(ctx context.Context) {
744 // Hardcode ID to check which ruler owns updating user index.
745 userID := users.UserIndexCompressedFilename
746 // Align with clean up interval.
747 ticker := time.NewTicker(util.DurationWithJitter(r.store.GetUserIndexUpdater().GetUpdateInterval(), 0.1))
748 defer ticker.Stop()
749
750 for {
751 select {
752 case <-ctx.Done():
753 level.Error(r.logger).Log("msg", "context timeout, exit user index update loop", "err", ctx.Err())
754 return
755 case <-ticker.C:
756 owned, err := r.isUserOwned(userID)
757 if err != nil {
758 level.Error(r.logger).Log("msg", "failed to check if ruler owns updating user index", "err", err)
759 continue
760 }
761 if !owned {
762 continue
763 }
764 start := time.Now()
765 if err := r.userIndexUpdater.UpdateUserIndex(ctx); err != nil {
766 level.Error(r.logger).Log("msg", "failed to update user index", "err", err)
767 // Wait for next interval. Worst case, the user index scanner will fallback to list strategy.
768 continue
769 }
770 level.Info(r.logger).Log("msg", "successfully updated user index", "duration_ms", time.Since(start).Milliseconds())
771 }
772 }
773}
774
775func (r *Ruler) isUserOwned(userID string) (bool, error) {
776 if !r.allowedTenants.IsAllowed(userID) {

Callers 1

runMethod · 0.95

Calls 10

isUserOwnedMethod · 0.95
DurationWithJitterFunction · 0.92
GetUpdateIntervalMethod · 0.80
DoneMethod · 0.80
UpdateUserIndexMethod · 0.80
GetUserIndexUpdaterMethod · 0.65
StopMethod · 0.65
ErrMethod · 0.65
LogMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected