diff --git a/agent/api/container/container.go b/agent/api/container/container.go index d72094f1672..98d8f701c2f 100644 --- a/agent/api/container/container.go +++ b/agent/api/container/container.go @@ -27,6 +27,7 @@ import ( resourcestatus "github.com/aws/amazon-ecs-agent/agent/taskresource/status" "github.com/aws/amazon-ecs-agent/ecs-agent/credentials" "github.com/aws/amazon-ecs-agent/ecs-agent/logger" + "github.com/aws/amazon-ecs-agent/ecs-agent/logger/field" "github.com/aws/aws-sdk-go/aws" "github.com/cihub/seelog" @@ -516,11 +517,11 @@ func (c *Container) Fields() logger.Fields { exitCode = strconv.Itoa(*c.GetKnownExitCode()) } return logger.Fields{ - "containerName": c.Name, - "containerImage": c.Image, + field.ContainerName: c.Name, + field.ContainerImage: c.Image, "containerKnownStatus": c.GetKnownStatus().String(), "containerDesiredStatus": c.GetDesiredStatus().String(), - "containerExitCode": exitCode, + field.ContainerExitCode: exitCode, } } diff --git a/agent/engine/docker_image_manager.go b/agent/engine/docker_image_manager.go index 3daf4838dec..af61b66ea4c 100644 --- a/agent/engine/docker_image_manager.go +++ b/agent/engine/docker_image_manager.go @@ -152,7 +152,7 @@ func (imageManager *dockerImageManager) RecordContainerReference(container *apic imageInspected, err := imageManager.client.InspectImage(container.Image) if err != nil { fields := container.Fields() - fields["err"] = err + fields[field.Error] = err logger.Error("Error inspecting image", fields) return err } @@ -488,16 +488,16 @@ func (imageManager *dockerImageManager) removeNonECSImages(ctx context.Context, continue } fields := logger.Fields{ - "imageID": image.ImageID, - "imageSizeBytes": image.Size, - "repoTags": image.RepoTags, + field.ImageID: image.ImageID, + field.ImageSizeBytes: image.Size, + "repoTags": image.RepoTags, } if len(image.RepoTags) > 1 { logger.Debug("Non-ECS image has more than one tag", fields) for _, tag := range image.RepoTags { err := imageManager.client.RemoveImage(ctx, tag, dockerclient.RemoveImageTimeout) if err != nil { - logger.Error("Error removing non-ECS RepoTag", fields, logger.Fields{"err": err}) + logger.Error("Error removing non-ECS RepoTag", fields, logger.Fields{field.Error: err}) } else { logger.Info("Non-ECS image tag removed", fields, logger.Fields{"imageTag": tag}) numImagesAlreadyDeleted++ @@ -507,7 +507,7 @@ func (imageManager *dockerImageManager) removeNonECSImages(ctx context.Context, logger.Debug("Removing non-ECS image", fields) err := imageManager.client.RemoveImage(ctx, image.ImageID, dockerclient.RemoveImageTimeout) if err != nil { - logger.Error("Error removing non-ECS image", fields, logger.Fields{"err": err}) + logger.Error("Error removing non-ECS image", fields, logger.Fields{field.Error: err}) } else { logger.Info("Non-ECS image removed", fields) numImagesAlreadyDeleted++ @@ -524,14 +524,14 @@ func (imageManager *dockerImageManager) getNonECSImages(ctx context.Context) []I for _, imageID := range r.ImageIDs { resp, err := imageManager.client.InspectImage(imageID) if err != nil { - logger.Error("Error inspecting non-ECS image", logger.Fields{"imageID": imageID, "err": err}) + logger.Error("Error inspecting non-ECS image", logger.Fields{field.ImageID: imageID, field.Error: err}) continue } createTime := time.Time{} createTime, err = time.Parse(time.RFC3339, resp.Created) if err != nil { logger.Warn("Error parsing the inspected non-ECS image created time.", - logger.Fields{"imageID": imageID, "err": err}) + logger.Fields{field.ImageID: imageID, field.Error: err}) } allImages = append(allImages, ImageWithSizeID{ @@ -675,7 +675,7 @@ func (imageManager *dockerImageManager) deleteImage(ctx context.Context, imageID if strings.Contains(strings.ToLower(err.Error()), imageNotFoundForDeletionError) { logger.Error(fmt.Sprintf("Image already removed from the instance: %v", imageID), imageState.Fields()) } else { - logger.Error(fmt.Sprintf("Error removing Image %v", imageID), imageState.Fields(), logger.Fields{"err": err}) + logger.Error(fmt.Sprintf("Error removing Image %v", imageID), imageState.Fields(), logger.Fields{field.Error: err}) delete(imageManager.imageStatesConsideredForDeletion, imageState.Image.ImageID) return } diff --git a/agent/engine/image/types.go b/agent/engine/image/types.go index 2cb1a4eca84..46be2dd1721 100644 --- a/agent/engine/image/types.go +++ b/agent/engine/image/types.go @@ -203,12 +203,12 @@ func (imageState *ImageState) Fields() logger.Fields { } return logger.Fields{ - "imageID": imageID, - "imageNames": names, - "imageSizeBytes": size, - "referencedBy": len(imageState.Containers), - "imagePulledAt": imageState.PulledAt.UTC().Format(time.RFC3339), - "imageLastUsedAt": imageState.LastUsedAt.UTC().Format(time.RFC3339), - "imagePullSucceeded": imageState.PullSucceeded, + field.ImageID: imageID, + field.ImageNames: names, + field.ImageSizeBytes: size, + "referencedBy": len(imageState.Containers), + field.ImagePulledAt: imageState.PulledAt.UTC().Format(time.RFC3339), + field.ImageLastUsedAt: imageState.LastUsedAt.UTC().Format(time.RFC3339), + field.ImagePullSucceeded: imageState.PullSucceeded, } } diff --git a/ecs-agent/logger/field/constants.go b/ecs-agent/logger/field/constants.go index fbfd713ffe9..8b154e1dbec 100644 --- a/ecs-agent/logger/field/constants.go +++ b/ecs-agent/logger/field/constants.go @@ -14,29 +14,38 @@ package field const ( - TaskID = "task" - TaskARN = "taskARN" - Container = "container" - DockerId = "dockerId" - ManagedAgent = "managedAgent" - KnownStatus = "knownStatus" - KnownSent = "knownSent" - DesiredStatus = "desiredStatus" - SentStatus = "sentStatus" - FailedStatus = "failedStatus" - Sequence = "seqnum" - Reason = "reason" - Status = "status" - RuntimeID = "runtimeID" - Elapsed = "elapsed" - Resource = "resource" - Error = "error" - Event = "event" - Image = "image" - Volume = "volume" - Time = "time" - NetworkMode = "networkMode" - Cluster = "cluster" - ServiceName = "ServiceName" - TaskProtection = "TaskProtection" + TaskID = "task" + TaskARN = "taskARN" + Container = "container" + DockerId = "dockerId" + ManagedAgent = "managedAgent" + KnownStatus = "knownStatus" + KnownSent = "knownSent" + DesiredStatus = "desiredStatus" + SentStatus = "sentStatus" + FailedStatus = "failedStatus" + Sequence = "seqnum" + Reason = "reason" + Status = "status" + RuntimeID = "runtimeID" + Elapsed = "elapsed" + Resource = "resource" + Error = "error" + Event = "event" + Image = "image" + Volume = "volume" + Time = "time" + NetworkMode = "networkMode" + Cluster = "cluster" + ServiceName = "ServiceName" + TaskProtection = "TaskProtection" + ImageID = "imageID" + ImageNames = "imageNames" + ImageSizeBytes = "imageSizeBytes" + ImagePulledAt = "imagePulledAt" + ImageLastUsedAt = "imageLastUsedAt" + ImagePullSucceeded = "imagePullSucceeded" + ContainerName = "containerName" + ContainerImage = "containerImage" + ContainerExitCode = "containerExitCode" )