MCPcopy Create free account
hub / github.com/cortexproject/cortex / ScanUsers

Method ScanUsers

pkg/util/users/scanner.go:152–177  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

150}
151
152func (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.
180type shardedScanner struct {

Callers

nothing calls this directly

Calls 10

ReadUserIndexFunction · 0.85
BeforeMethod · 0.80
ScanUsersMethod · 0.65
SetMethod · 0.65
IsMethod · 0.45
LogMethod · 0.45
IncMethod · 0.45
ErrorMethod · 0.45
GetUpdatedAtMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected