(ctx context.Context)
| 150 | } |
| 151 | |
| 152 | func (s *userIndexScanner) ScanUsers(ctx context.Context) ([]string, []string, []string, error) { |
| 153 | userIndex, err := ReadUserIndex(ctx, s.bkt, s.logger) |
| 154 | if err != nil { |
| 155 | if errors.Is(err, ErrIndexNotFound) { |
| 156 | level.Info(s.logger).Log("msg", "user index not found, fallback to base scanner") |
| 157 | s.fallbackScans.WithLabelValues("not-found").Inc() |
| 158 | } else if !errors.Is(err, context.Canceled) { |
| 159 | // Always fallback to the list scanner if failed to read the user index. |
| 160 | level.Error(s.logger).Log("msg", "failed to read user index, fallback to base scanner", "error", err) |
| 161 | s.fallbackScans.WithLabelValues("corrupted").Inc() |
| 162 | } |
| 163 | return s.baseScanner.ScanUsers(ctx) |
| 164 | } |
| 165 | |
| 166 | now := time.Now() |
| 167 | updatedAt := userIndex.GetUpdatedAt() |
| 168 | s.userIndexUpdateDelay.Set(time.Since(updatedAt).Seconds()) |
| 169 | if updatedAt.Before(now.Add(-s.maxStalePeriod)) { |
| 170 | level.Warn(s.logger).Log("msg", "user index is stale, fallback to base scanner", "updated_at", userIndex.GetUpdatedAt(), "max_stale_period", s.maxStalePeriod) |
| 171 | s.fallbackScans.WithLabelValues("too_old").Inc() |
| 172 | return s.baseScanner.ScanUsers(ctx) |
| 173 | } |
| 174 | |
| 175 | s.succeededScans.Inc() |
| 176 | return userIndex.ActiveUsers, userIndex.DeletingUsers, userIndex.DeletedUsers, nil |
| 177 | } |
| 178 | |
| 179 | // shardedScanner is a user scanner but applies a filter to the users to check ownership. |
| 180 | type shardedScanner struct { |
nothing calls this directly
no test coverage detected