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

[wip] Metadata task definition fields #1122

Closed
wants to merge 1 commit into from

Conversation

jtoberon
Copy link
Contributor

@jtoberon jtoberon commented Nov 30, 2017

Summary

Expose two more metadata fields, task definition family and task definition

Implementation details

Retrieve the fields from the existing task struct, and copy them into the
metadata JSON.

Testing

  • Builds on Linux (make release)
  • Builds on Windows (go build -out amazon-ecs-agent.exe ./agent)
  • Unit tests on Linux (make test) pass
  • Unit tests on Windows (go test -timeout=25s ./agent/...) pass
  • Integration tests on Linux (make run-integ-tests) pass
  • Integration tests on Windows (.\scripts\run-integ-tests.ps1) pass
  • Functional tests on Linux (make run-functional-tests) pass
  • Functional tests on Windows (.\scripts\run-functional-tests.ps1) pass

New tests cover the changes: yes

Description for the changelog

Enhancement -Expose two more metadata fields, task definition family and task definition

Licensing

This contribution is under the terms of the Apache 2.0 License: yes

@jtoberon jtoberon changed the base branch from master to dev November 30, 2017 23:25
dockerContainerMetadata: dockerMD,
containerInstanceARN: manager.containerInstanceARN,
metadataStatus: MetadataReady,
}
}

func parseTaskDefinitionRevision(task *api.Task, containerName string) int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a comment describing what it does. It is also probably worth mentioning that when strconv.Atoi fails with an error, taskDefinitionRevision will be set to the int 0.

@@ -151,6 +155,8 @@ func (m Metadata) MarshalJSON() ([]byte, error) {
Cluster: m.cluster,
ContainerInstanceARN: m.containerInstanceARN,
TaskARN: m.taskMetadata.taskARN,
TaskDefinitionFamily: m.taskMetadata.taskDefinitionFamily,
TaskDefinitionRevision: m.taskMetadata.taskDefinitionRevision,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the spacing for all the other elements in the map should match this line.

The task struct already has this information, so it's just a matter
of plumbing it through. Note that the type of the revision field in
the struct 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).
This change is consistent with the CLI.

(cherry picked from commit fdf1810)
Signed-off-by: Josh Oberwetter <oberj@amazon.com>
@jtoberon jtoberon force-pushed the metadata-task-definition-fields branch from 8a139f2 to 26d09da Compare December 1, 2017 00:37
return Metadata{
cluster: manager.cluster,
taskMetadata: TaskMetadata{containerName: containerName, taskARN: taskARN},
taskMetadata: TaskMetadata{containerName: containerName, taskARN: task.Arn, taskDefinitionFamily: task.Family, taskDefinitionRevision: taskDefinitionRevision},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: can you split these into multiple lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I couldn't figure out what the line length convention for this repo is. I'll do something reasonable.

return Metadata{
cluster: manager.cluster,
taskMetadata: TaskMetadata{containerName: containerName, taskARN: taskARN},
taskMetadata: TaskMetadata{containerName: containerName, taskARN: task.Arn, taskDefinitionFamily: task.Family, taskDefinitionRevision: taskDefinitionRevision},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. please split these into multiple lines (helps with readability)

ContainerInstanceARN string `json:"ContainerInstanceARN,omitempty"`
TaskARN string `json:"TaskARN,omitempty"`
TaskDefinitionFamily string `json:"TaskDefinitionFamily,omitempty"`
TaskDefinitionRevision int `json:"TaskDefinitionRevision,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has to be *int. 0 is still a valid int and omitempty would not apply to it.

// https://docs.aws.amazon.com/cli/latest/reference/ecs/describe-task-definition.html
// if anything bad happens, then 0 is returned, so you must omitempty to omit this from
// the metadata JSON output.
func parseTaskDefinitionRevision(task *api.Task, containerName string) int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per my comment in containermetadata/types.go, i think this has to return (*int, error). If there's an error, the pointer would not be set and omitempty will kick in.

@@ -21,6 +21,7 @@ import (

go_dockerclient "github.com/fsouza/go-dockerclient"
gomock "github.com/golang/mock/gomock"
"github.com/aws/amazon-ecs-agent/agent/api"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the convention is to order import statements as: 1) native go packages, 2) packages from the same repo, 3) other packages, with an empty line between each group. So this new line should be in 21?

@jhaynes jhaynes added this to the 1.17.0 milestone Dec 4, 2017
@aaithal aaithal modified the milestones: 1.17.0, 1.17.1 Dec 13, 2017
@adnxn
Copy link
Contributor

adnxn commented Jan 19, 2018

ping @jtoberon: what's going on with this PR? do we still need this merged?

@jtoberon
Copy link
Contributor Author

I'll probably pick this back up in 2 weeks or so.

@adnxn adnxn changed the title Metadata task definition fields [wip] Metadata task definition fields Jan 30, 2018
@jhaynes jhaynes removed this from the 1.17.1 milestone Feb 19, 2018
@adnxn
Copy link
Contributor

adnxn commented Mar 20, 2018

closing in favor of #1295

@adnxn adnxn closed this Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants