Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Reduce spam log generated by registry cache warmer #1538

Merged
merged 4 commits into from
Nov 21, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions registry/cache/warming.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,14 @@ func (w *Warmer) warm(ctx context.Context, now time.Time, logger log.Logger, id
awaitFetchers := &sync.WaitGroup{}
awaitFetchers.Add(len(toUpdate))

ctxc, cancel := context.WithCancel(ctx)
var once sync.Once
defer cancel()

updates:
for _, up := range toUpdate {
select {
case <-ctx.Done():
case <-ctxc.Done():
break updates
case fetchers <- struct{}{}:
}
Expand All @@ -291,13 +295,22 @@ func (w *Warmer) warm(ctx context.Context, now time.Time, logger log.Logger, id
}

// Get the image from the remote
entry, err := client.Manifest(ctx, imageID.Tag)
entry, err := client.Manifest(ctxc, imageID.Tag)
if err != nil {
if err, ok := errors.Cause(err).(net.Error); ok && err.Timeout() {
// This was due to a context timeout, don't bother logging
return
}
errorLogger.Log("err", err, "ref", imageID)

// abort the image tags fetching if we've been rate limited
if strings.Contains(err.Error(), "429") {
once.Do(func() {
errorLogger.Log("warn", "aborting image tag fetching due to rate limiting, will try again later")
})
cancel()
} else {
errorLogger.Log("err", err, "ref", imageID)
}
return
}

Expand Down