Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh09 committed Jun 2, 2023
1 parent da2f43d commit 2b69530
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
19 changes: 14 additions & 5 deletions agent/handlers/v4/tmdsstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (

"github.com/aws/amazon-ecs-agent/agent/api"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger/field"
tmdsv4 "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state"

"github.com/cihub/seelog"
)

// Implements AgentState interface for TMDS v4.
Expand Down Expand Up @@ -62,7 +62,10 @@ func (s *TMDSAgentState) GetContainerMetadata(v3EndpointID string) (tmdsv4.Conta

containerResponse, err := NewContainerResponse(containerID, s.state)
if err != nil {
seelog.Errorf("Unable to get container metadata for container '%s'", containerID)
logger.Error("Failed to get container metadata", logger.Fields{
field.Container: containerID,
field.Error: err,
})
return tmdsv4.ContainerResponse{}, tmdsv4.NewErrorMetadataFetchFailure(fmt.Sprintf(
"unable to generate metadata for container '%s'", containerID))
}
Expand Down Expand Up @@ -95,6 +98,10 @@ func (s *TMDSAgentState) GetTaskMetadata(v3EndpointID string) (tmdsv4.TaskRespon
taskResponse, err := NewTaskResponse(taskARN, s.state, s.ecsClient, s.cluster,
s.availabilityZone, s.vpcID, s.containerInstanceARN, task.ServiceName, false)
if err != nil {
logger.Error("Failed to get task metadata", logger.Fields{
field.TaskARN: taskARN,
field.Error: err,
})
return tmdsv4.TaskResponse{}, tmdsv4.NewErrorMetadataFetchFailure(fmt.Sprintf(
"Unable to generate metadata for v4 task: '%s'", taskARN))
}
Expand All @@ -106,8 +113,10 @@ func (s *TMDSAgentState) GetTaskMetadata(v3EndpointID string) (tmdsv4.TaskRespon
for _, containerResponse := range taskResponse.Containers {
networks, err := GetContainerNetworkMetadata(containerResponse.ID, s.state)
if err != nil {
seelog.Warnf("Error retrieving network metadata for container %s - %s",
containerResponse.ID, err)
logger.Warn("Error retrieving network metadata", logger.Fields{
field.Container: containerResponse.ID,
field.Error: err,
})
}
containerResponse.Networks = networks
responses = append(responses, containerResponse)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions ecs-agent/tmds/handlers/v4/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TaskMetadataHandler(
field.TMDSEndpointContainerID: endpointContainerID,
field.TaskARN: taskMetadata.TaskARN,
})
utils.WriteJSONResponse(w, http.StatusOK, taskMetadata, utils.RequestTypeContainerMetadata)
utils.WriteJSONResponse(w, http.StatusOK, taskMetadata, utils.RequestTypeTaskMetadata)
}
}

Expand All @@ -138,7 +138,8 @@ func getTaskErrorResponse(endpointContainerID string, err error) (int, string) {
return http.StatusInternalServerError, errFailedToGetContainerMetadata.ExternalReason()
}

logger.Error("Unknown error encountered when handling task metadata fetch failure",
logger.Fields{field.Error: err})
logger.Error("Unknown error encountered when handling task metadata fetch failure", logger.Fields{
field.Error: err,
})
return http.StatusInternalServerError, "failed to get task metadata"
}

0 comments on commit 2b69530

Please sign in to comment.