daemon/images: ImageService.manifestMatchesPlatform: optimize logger
We constructed a "function level" logger, which was used once "as-is", but also added additional Fields in a loop (for each resource), effectively overwriting the previous one for each iteration. Adding additional fields can result in some overhead, so let's construct a "logger" only for inside the loop. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
5581efe7cd
commit
7c1914411f
1 changed files with 11 additions and 4 deletions
|
@ -52,14 +52,16 @@ func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentIma
|
|||
}
|
||||
|
||||
func (i *ImageService) manifestMatchesPlatform(ctx context.Context, img *image.Image, platform ocispec.Platform) (bool, error) {
|
||||
logger := log.G(ctx).WithField("image", img.ID).WithField("desiredPlatform", platforms.Format(platform))
|
||||
|
||||
ls, err := i.leases.ListResources(ctx, leases.Lease{ID: imageKey(img.ID().String())})
|
||||
if err != nil {
|
||||
if cerrdefs.IsNotFound(err) {
|
||||
return false, nil
|
||||
}
|
||||
logger.WithError(err).Error("Error looking up image leases")
|
||||
log.G(ctx).WithFields(log.Fields{
|
||||
"error": err,
|
||||
"image": img.ID,
|
||||
"desiredPlatform": platforms.Format(platform),
|
||||
}).Error("Error looking up image leases")
|
||||
return false, err
|
||||
}
|
||||
|
||||
|
@ -77,7 +79,12 @@ func (i *ImageService) manifestMatchesPlatform(ctx context.Context, img *image.I
|
|||
}
|
||||
|
||||
for _, r := range ls {
|
||||
logger := logger.WithField("resourceID", r.ID).WithField("resourceType", r.Type)
|
||||
logger := log.G(ctx).WithFields(log.Fields{
|
||||
"image": img.ID,
|
||||
"desiredPlatform": platforms.Format(platform),
|
||||
"resourceID": r.ID,
|
||||
"resourceType": r.Type,
|
||||
})
|
||||
logger.Debug("Checking lease resource for platform match")
|
||||
if r.Type != "content" {
|
||||
continue
|
||||
|
|
Loading…
Add table
Reference in a new issue