Skip to content

Commit

Permalink
Improve log readability
Browse files Browse the repository at this point in the history
  • Loading branch information
angelcar committed Feb 23, 2022
1 parent 4de4d49 commit dcd4f7f
Show file tree
Hide file tree
Showing 33 changed files with 1,127 additions and 496 deletions.
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",
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{
"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

0 comments on commit dcd4f7f

Please sign in to comment.