-
Notifications
You must be signed in to change notification settings - Fork 619
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
Introduce ErrorResponse to TMDEv4 taskWithTags responses #2789
Conversation
agent/handlers/v2/response.go
Outdated
// metadataErrorHandling writes an error to the logger, and append an error response | ||
// to V4 metadata endpoint task response | ||
func metadataErrorHandling(resp *TaskResponse, err error, field, resourceARN string, includeV4Metadata bool) { | ||
seelog.Errorf("V2 response: unable to get '%s' for '%s': %s", field, resourceARN, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: since this function is used by v3 and v4 task metadata endpoints, it might be confusing to prepend the log with "V2 response". Maybe something more accurate like "Task Metadata error:"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the error log message as suggested. Thanks!
level=info time=xxx msg="V4 taskMetadata handler: Writing response for task 'taskARN'" module=task_metadata_handler.go
level=error time=xxx msg="Task Metadata error: unable to get 'ContainerInstanceTags' for 'containerInstanceARN': AccessDeniedException: User: iamARN is not authorized to perform: ecs:ListTagsForResource on resource: containerInstanceARN" module=response.go
level=error time=xxx msg="Task Metadata error: unable to get 'TaskTags' for 'taskARN': AccessDeniedException: User: iamARN is not authorized to perform: ecs:ListTagsForResource on resource: taskARN" module=response.go
agent/handlers/v2/response.go
Outdated
func newErrorResponse(err error, field, resourceARN string) (*ErrorResponse, error) { | ||
if awsErr, ok := err.(awserr.Error); ok { | ||
if reqErr, ok := err.(awserr.RequestFailure); ok { | ||
errResp := &ErrorResponse{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need for the errResp
variable, you can return &ErrorResponse{...}
directly
agent/handlers/v2/response.go
Outdated
} | ||
} | ||
|
||
return nil, errors.Errorf("Unable to get an error response for resource '%s'", resourceARN) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we return something like below if the error is not awserr.Error
?
return &ErrorResponse{
ErrorField: field,
ErrorMessage: err.Error(),
ResourceARN: resourceARN,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should. Update function newErrorResponse with a base ErrorResponse as code snippets below.
// newErrorResponse creates a new error response
func newErrorResponse(err error, field, resourceARN string) *ErrorResponse {
errResp := &ErrorResponse{
ErrorField: field,
ErrorMessage: err.Error(),
ResourceARN: resourceARN,
}
if awsErr, ok := err.(awserr.Error); ok {
errResp.ErrorCode = awsErr.Code()
errResp.ErrorMessage = awsErr.Message()
if reqErr, ok := err.(awserr.RequestFailure); ok {
errResp.StatusCode = reqErr.StatusCode()
errResp.RequestId = reqErr.RequestID()
}
}
return errResp
}
A mock non-awserr Error is tested, and the corresponding responses are shown as follows.
TMDE v4
{
"Cluster":"default",
"TaskARN":"xxx",
...
"ContainerInstanceTags":{
"tag_key":"tag_value"
},
"LaunchType":"EC2",
"Errors":[
{
"ErrorField":"TaskTags",
"ErrorMessage":"This is a non-awserr for testing: unable to find TaskTags for 'taskARN'",
"ResourceARN":"taskARN"
}
],
"Containers":[{...}]
}
TMDE v3
level=info time=xxx msg="V3 task metadata handler: writing response for task 'taskARN'" module=task_metadata_handler.go
level=error time=xxx msg="Task Metadata error: unable to get 'TaskTags' for 'taskARN': This is a non-awserr for testing: unable to find TaskTags for 'taskARN'" module=response.go
Thanks!
0ff627b
to
f1cbea5
Compare
Summary
This PR adds a new type
ErrorResponse
into the task metadata endpoint version 4 (TMDEv4) taskWithTags responses. When the path{ECS_CONTAINER_METADATA_URI_V4}/taskWithTag
is queried, Agent writes a json response with task metadata, task and container instance tags that can be retrieved fromECS ListTagsForResource API
, and errors returned from the ECS API.To date, Agent shows a partial/no list of tags in TMDEv2/v3/v4 taskWithTags responses if it cannot get a complete list of tags from ECS. As no error code, error message or status code is mentioned in responses, it hinders customers from differentiating whether there is no task/container tag, or an exception has been encountered. To resolve this issue, An ErrorResponse with an error field, an error code, an error message, a status code, a request ID and a resources ARN is introduced to TMDEv4 taskWithTags responses.
Implementation details
includeV4Metadata
to functionpropagateTagsToMetadata
includeV4Metadata
is true and an ErrorResponse existsnewErrorResponse
to return a new ErrorResponse object based on the error and the resource ARNmetadataErrorHandling
to format errors for ecs-agent.log, and call functionnewErrorResponse
for TMDEv4Testing
Unit tests
New tests cover the changes: yes
A new unit test TestTaskResponseWithV4TagsError is added to cover this change.
Manual tests
TMDEv4 taskWithTags
ThrottlingException
is encountered forTaskTags
ecs-agent.log
AccessDeniedException
is encountered for bothContainerInstanceTags
andTaskTags
ecs-agent.log
InvalidParameterException
is encountered forTaskTags
ecs-agent.log
non-awserr
is encounteredecs-agent.log
TMDEv3 taskWithTags
ThrottlingException
is encountered forContainerInstanceTags
AccessDeniedException
is encountered for bothContainerInstanceTags
andTaskTags
InvalidParameterException
is encountered forTaskTags
non-awserr
is encounteredDescription for the changelog
Enhancement - Add error responses into TMDEv4 taskWithTags responses
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.