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 all 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
22 changes: 18 additions & 4 deletions registry/cache/warming.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,21 @@ func (w *Warmer) warm(ctx context.Context, now time.Time, logger log.Logger, id
// w.Burst, so limit the number of fetching goroutines to that.
fetchers := make(chan struct{}, w.burst)
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{}{}:
}

awaitFetchers.Add(1)

go func(update update) {
defer func() { awaitFetchers.Done(); <-fetchers }()

Expand All @@ -291,13 +296,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