Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve log readability #3134

Merged
merged 1 commit into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
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
21 changes: 17 additions & 4 deletions agent/acs/handler/attach_eni_handler_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"fmt"
"time"

"github.com/aws/amazon-ecs-agent/agent/logger"
"github.com/aws/amazon-ecs-agent/agent/logger/field"

"github.com/aws/amazon-ecs-agent/agent/acs/model/ecsacs"
apieni "github.com/aws/amazon-ecs-agent/agent/api/eni"
"github.com/aws/amazon-ecs-agent/agent/data"
Expand Down Expand Up @@ -118,16 +121,26 @@ func addENIAttachmentToState(attachmentType, attachmentARN, taskARN, mac string,

switch attachmentType {
case apieni.ENIAttachmentTypeTaskENI:
seelog.Infof("Adding task eni attachment info for task '%s' to state, attachment=%s mac=%s",
taskARN, attachmentARN, mac)
taskId, _ := utils.TaskIdFromArn(taskARN)
logger.Info("Adding eni attachment info to state for task", logger.Fields{
field.TaskID: taskId,
"attachmentARN": attachmentARN,
"mac": mac,
})
case apieni.ENIAttachmentTypeInstanceENI:
seelog.Infof("Adding instance eni attachment info to state, attachment=%s mac=%s", attachmentARN, mac)
logger.Info("Adding instance eni attachment info to state", logger.Fields{
"attachmentARN": attachmentARN,
"mac": mac,
})
default:
return fmt.Errorf("unrecognized eni attachment type: %s", attachmentType)
}
state.AddENIAttachment(eniAttachment)
if err := dataClient.SaveENIAttachment(eniAttachment); err != nil {
seelog.Errorf("Failed to save data for eni attachment %s: %v", eniAttachment.AttachmentARN, err)
logger.Error("Failed to save data for eni attachment", logger.Fields{
"attachmentARN": attachmentARN,
field.Error: err,
})
}
return nil
}
14 changes: 13 additions & 1 deletion agent/acs/handler/payload_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"context"
"fmt"

"github.com/aws/amazon-ecs-agent/agent/logger"
"github.com/aws/amazon-ecs-agent/agent/logger/field"

"github.com/aws/amazon-ecs-agent/agent/acs/model/ecsacs"
"github.com/aws/amazon-ecs-agent/agent/api"
apiappmesh "github.com/aws/amazon-ecs-agent/agent/api/appmesh"
Expand Down Expand Up @@ -128,7 +131,10 @@ func (payloadHandler *payloadRequestHandler) ackMessageId(messageID string) {
MessageId: aws.String(messageID),
})
if err != nil {
seelog.Warnf("Error 'ack'ing request with messageID: %s, error: %v", messageID, err)
logger.Warn("Error ack'ing request", logger.Fields{
"messageID": messageID,
field.Error: err,
})
}
}

Expand Down Expand Up @@ -198,6 +204,12 @@ func (payloadHandler *payloadRequestHandler) addPayloadTasks(payload *ecsacs.Pay
continue
}

logger.Info("Received task payload from ACS", logger.Fields{
field.TaskARN: apiTask.Arn,
"version": apiTask.Version,
field.DesiredStatus: apiTask.GetDesiredStatus(),
})

if task.RoleCredentials != nil {
// The payload from ACS for the task has credentials for the
// task. Add those to the credentials manager and set the
Expand Down
16 changes: 12 additions & 4 deletions agent/api/ecsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"strings"
"time"

"github.com/aws/amazon-ecs-agent/agent/logger"

"github.com/aws/amazon-ecs-agent/agent/api"
apicontainerstatus "github.com/aws/amazon-ecs-agent/agent/api/container/status"
apierrors "github.com/aws/amazon-ecs-agent/agent/api/errors"
Expand Down Expand Up @@ -587,8 +589,11 @@ func (client *APIECSClient) discoverPollEndpoint(containerInstanceArn string) (*
if !expired && found {
// Cache hit and not expired. Return the output.
if output, ok := cachedEndpoint.(*ecs.DiscoverPollEndpointOutput); ok {
seelog.Infof("Using cached DiscoverPollEndpoint. endpoint=%s telemetryEndpoint=%s containerInstanceARN=%s",
singholt marked this conversation as resolved.
Show resolved Hide resolved
aws.StringValue(output.Endpoint), aws.StringValue(output.TelemetryEndpoint), containerInstanceArn)
logger.Info("Using cached DiscoverPollEndpoint", logger.Fields{
"endpoint": aws.StringValue(output.Endpoint),
"telemetryEndpoint": aws.StringValue(output.TelemetryEndpoint),
"containerInstanceARN": containerInstanceArn,
})
return output, nil
}
}
Expand All @@ -604,8 +609,11 @@ func (client *APIECSClient) discoverPollEndpoint(containerInstanceArn string) (*
// we have it.
if expired {
if output, ok := cachedEndpoint.(*ecs.DiscoverPollEndpointOutput); ok {
seelog.Infof("Error calling DiscoverPollEndpoint. Using cached but expired endpoint as a fallback. error=%s endpoint=%s telemetryEndpoint=%s containerInstanceARN=%s",
err, aws.StringValue(output.Endpoint), aws.StringValue(output.TelemetryEndpoint), containerInstanceArn)
logger.Info("Error calling DiscoverPollEndpoint. Using cached-but-expired endpoint as a fallback.", logger.Fields{
"endpoint": aws.StringValue(output.Endpoint),
"telemetryEndpoint": aws.StringValue(output.TelemetryEndpoint),
"containerInstanceARN": containerInstanceArn,
})
return output, nil
}
}
Expand Down
28 changes: 25 additions & 3 deletions agent/api/eni/eniattachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import (
"sync"
"time"

"github.com/aws/amazon-ecs-agent/agent/logger"
"github.com/aws/amazon-ecs-agent/agent/logger/field"
"github.com/aws/amazon-ecs-agent/agent/utils"

"github.com/aws/amazon-ecs-agent/agent/utils/ttime"
"github.com/cihub/seelog"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -55,6 +58,25 @@ type ENIAttachment struct {
guard sync.RWMutex
}

func getEniAttachmentLogFields(eni *ENIAttachment, duration time.Duration) logger.Fields {
fields := logger.Fields{
singholt marked this conversation as resolved.
Show resolved Hide resolved
"duration": duration.String(),
"attachmentARN": eni.AttachmentARN,
"attachmentType": eni.AttachmentType,
"attachmentSent": eni.AttachStatusSent,
"mac": eni.MACAddress,
"status": eni.Status.String(),
"expiresAt": eni.ExpiresAt.Format(time.RFC3339),
}

if eni.AttachmentType != ENIAttachmentTypeInstanceENI {
taskId, _ := utils.TaskIdFromArn(eni.TaskARN)
fields[field.TaskID] = taskId
}

return fields
}

// StartTimer starts the ack timer to record the expiration of ENI attachment
func (eni *ENIAttachment) StartTimer(timeoutFunc func()) error {
eni.guard.Lock()
Expand All @@ -70,7 +92,7 @@ func (eni *ENIAttachment) StartTimer(timeoutFunc func()) error {
return errors.Errorf("eni attachment: timer expiration is in the past; expiration [%s] < now [%s]",
eni.ExpiresAt.String(), now.String())
}
seelog.Infof("Starting ENI ack timer with duration=%s, %s", duration.String(), eni.stringUnsafe())
logger.Info("Starting ENI ack timer", getEniAttachmentLogFields(eni, duration))
eni.ackTimer = time.AfterFunc(duration, timeoutFunc)
return nil
}
Expand All @@ -92,7 +114,7 @@ func (eni *ENIAttachment) Initialize(timeoutFunc func()) error {
return errors.New("ENI attachment has already expired")
}

seelog.Infof("Starting ENI ack timer with duration=%s, %s", duration.String(), eni.stringUnsafe())
logger.Info("Starting ENI ack timer", getEniAttachmentLogFields(eni, duration))
eni.ackTimer = time.AfterFunc(duration, timeoutFunc)
return nil
}
Expand Down
Loading