-
Notifications
You must be signed in to change notification settings - Fork 616
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
containermetadata: Metadata task definition fields #1295
Conversation
return Metadata{ | ||
cluster: manager.cluster, | ||
taskMetadata: TaskMetadata{containerName: containerName, taskARN: taskARN}, | ||
taskMetadata: TaskMetadata{containerName: containerName, | ||
taskARN: task.Arn, taskDefinitionFamily: task.Family, |
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.
please split this into multiple lines.
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.
OK
return Metadata{ | ||
cluster: manager.cluster, | ||
taskMetadata: TaskMetadata{containerName: containerName, taskARN: taskARN}, | ||
taskMetadata: TaskMetadata{containerName: containerName, | ||
taskARN: task.Arn, taskDefinitionFamily: task.Family, |
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.
please split this into multiple lines.
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.
OK
agent/containermetadata/types.go
Outdated
ContainerInstanceARN string `json:"ContainerInstanceARN,omitempty"` | ||
TaskARN string `json:"TaskARN,omitempty"` | ||
TaskDefinitionFamily string `json:"TaskDefinitionFamily,omitempty"` | ||
TaskDefinitionRevision int `json:"TaskDefinitionRevision,omitempty"` |
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.
0
is not the same as the field not being set. You'd need to make this *int
for "omitempty"
to be effective.
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.
OK, I was thinking if the task.Version is empty or it's not a number, strconv.Atoi will return a 0, note that the task version starts at 1, so 0 is not a valid task version. And according to https://golang.org/pkg/encoding/json/, "omitempty" will omit the fields with 0, nil, etc, so in this way int will work.
I'll make it *int for better readability.
// https://docs.aws.amazon.com/cli/latest/reference/ecs/describe-task-definition.html | ||
// if anything bad happens, then 0 is returned (0 is not a valid task definition revision number), | ||
// so you must omitempty to omit this from the metadata JSON output. | ||
func parseTaskDefinitionRevision(task *api.Task, containerName string) int { |
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.
Why do you need this method? Why not just use
amazon-ecs-agent/agent/api/task.go
Line 76 in edc3e26
Version string |
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.
Because the type of the task.Version is a string, and the type in our CLI is an integer
(https://docs.aws.amazon.com/cli/latest/reference/ecs/describe-task-definition.html).
So to be consistent with the CLI, I make it a number here.
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.
Will make taskDefinitionRevision a string after further discussion.
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.
code lgtm. If you could update the copyright year in the files' header, that would be great.
metadata = newManager.parseMetadata(nil, mockTask, mockContainerName) | ||
assert.Equal(t, metadata.taskMetadata.taskDefinitionFamily, mockTaskDefinitionFamily, "Expected task definition family "+mockTaskDefinitionFamily) | ||
assert.Equal(t, metadata.taskMetadata.taskDefinitionRevision, mockTaskDefinitionRevision, "Expected task definition revision "+mockTaskDefinitionRevision) | ||
} |
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: empty line at the eof
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.
OK
can you please make sure modify the |
CHANGELOG.md
Outdated
@@ -1,6 +1,7 @@ | |||
# Changelog | |||
|
|||
## 1.17.2 | |||
* Enhancement - Expose two more metadata fields, task definition family and task definition revision [#1295](https://github.com/aws/amazon-ecs-agent/pull/1295) |
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.
This should be under 1.17.3-dev
. You'll see it if you rebase it.
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.
OK, thanks for pointing out, I just rebased and updated the change log again
ecf642a
to
8fc0c1d
Compare
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.
please make sure that you update the changelog entry as per comments. lgtm otherwise!
CHANGELOG.md
Outdated
@@ -1,6 +1,7 @@ | |||
# Changelog | |||
|
|||
## 1.17.3-dev | |||
* Enhancement - Expose two more metadata fields, task definition family and task definition revision [#1295](https://github.com/aws/amazon-ecs-agent/pull/1295) |
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.
Because we have multiple ways to get metadata, can you also specify that this is for 'container metadata file'? Example:Enhancement - Expose task definition family and task definition revision in container metadata file...
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.
OK, I will change it accordingly.
…data fields The task struct already has this information, so it's just a matter of plumbing it through. This commit also fixes some typos.
8fc0c1d
to
c600d69
Compare
Summary
This is to pick up and finish pr #1122 to fix #1295.
Expose two more metadata fields, task definition family and task definition revision.
It also fixes some typos.
Implementation details
Retrieve the fields from the existing task struct, and copy them into the metadata JSON.
Testing
make release
)go build -out amazon-ecs-agent.exe ./agent
)make test
) passgo test -timeout=25s ./agent/...
) passmake run-integ-tests
) pass.\scripts\run-integ-tests.ps1
) passmake run-functional-tests
) pass.\scripts\run-functional-tests.ps1
) passNew tests cover the changes: yes
Description for the changelog
Enhancement - Expose two more metadata fields, task definition family and task definition revision
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.