(ctx context.Context)
| 741 | } |
| 742 | |
| 743 | func (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 | |
| 775 | func (r *Ruler) isUserOwned(userID string) (bool, error) { |
| 776 | if !r.allowedTenants.IsAllowed(userID) { |
no test coverage detected