Skip to content

Commit

Permalink
Merge pull request #10886 from thaJeztah/fix_retry_logs
Browse files Browse the repository at this point in the history
resolver/docker: fix confusing "trying next host" log
  • Loading branch information
samuelkarp authored Nov 1, 2024
2 parents 92b46e1 + 700b906 commit cb4ce9a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions core/remotes/docker/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,16 @@ func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocisp
firstErr error
firstErrPriority int
)

nextHostOrFail := func(i int) string {
if i < len(hosts)-1 {
return "trying next host"
}
return "fetch failed"
}

for _, u := range paths {
for _, host := range hosts {
for i, host := range hosts {
ctx := log.WithLogger(ctx, log.G(ctx).WithField("host", host.Host))

req := base.request(host, http.MethodHead, u...)
Expand All @@ -308,7 +316,7 @@ func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocisp
firstErr = err
firstErrPriority = 1
}
log.G(ctx).WithError(err).Info("trying next host")
log.G(ctx).WithError(err).Info(nextHostOrFail(i))
continue // try another host
}
resp.Body.Close() // don't care about body contents.
Expand All @@ -319,15 +327,15 @@ func (r *dockerResolver) Resolve(ctx context.Context, ref string) (string, ocisp
firstErr = fmt.Errorf("%s: %w", ref, errdefs.ErrNotFound)
firstErrPriority = 2
}
log.G(ctx).Info("trying next host - response was http.StatusNotFound")
log.G(ctx).Infof("%s after status: %s", nextHostOrFail(i), resp.Status)
continue
}
if resp.StatusCode > 399 {
if firstErrPriority < 3 {
firstErr = remoteerrors.NewUnexpectedStatusErr(resp)
firstErrPriority = 3
}
log.G(ctx).Infof("trying next host - response was %s", resp.Status)
log.G(ctx).Infof("%s after status: %s", nextHostOrFail(i), resp.Status)
continue // try another host
}
return "", ocispec.Descriptor{}, remoteerrors.NewUnexpectedStatusErr(resp)
Expand Down

0 comments on commit cb4ce9a

Please sign in to comment.