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

test: add functional test for agent introspection endpoint #1485

Merged
merged 1 commit into from
Aug 10, 2018

Conversation

haikuoliu
Copy link
Contributor

@haikuoliu haikuoliu commented Jul 30, 2018

Summary

Add functional test for agent introspection endpoint.

Implementation details

The AgentIntrospectionValidator basically mimics TaskMetadataValidator:

  1. Start a container to query the agent introspection endpoint, the container is started with host mode, so it's similar to the case when you ssh into the container instance and query the introspection endpoint.
  2. In the container, the tasks metadata and task metadata path are queried, they are unmarshalled to v1 response struct, since the the value of the fields are dynamic, for the most of them we only check if they are empty.
  3. The Agent metadata is already checked when we start Agent in the functional test, so we don't check it in the container.

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

Description for the changelog

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@haikuoliu haikuoliu requested a review from a team July 30, 2018 04:58
Copy link
Contributor

@adnxn adnxn left a comment

Choose a reason for hiding this comment

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

just few questions, and thanks for writing such a thorough functional test.

"image": "amazon/amazon-ecs-agent-introspection-validator:make",
"name": "agent-introspection-validator",
"memory": 50,
"healthCheck": {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this test need to have a healthcheck?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is unnecessary, I will remove it.

"startPeriod": 1
},
"logConfiguration": {
"logDriver": "awslogs",
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we configuring this task to use awslogs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the logs in misc/agent-introspection-validator/agent-introspection-validator.go needs be to be uploaded to Cloud Watch.


// ContainerResponse is the schema for the container response JSON object
type ContainerResponse struct {
DockerID string
Copy link
Contributor

Choose a reason for hiding this comment

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

just making a note since i asked you offline, this should be DockerId to match the original API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I was planning to update it when the fix PR is rebased, will add a TODO in the PR description.

@haikuoliu haikuoliu force-pushed the branch_func_tests_agent_introspection branch 2 times, most recently from dda680a to 1097ea3 Compare August 1, 2018 03:38
Copy link
Contributor

@yhlee-aws yhlee-aws left a comment

Choose a reason for hiding this comment

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

minor comment, but lgtm

return nil, err
}

fmt.Printf("Received tasks metadata: %s \n", string(body))
Copy link
Contributor

Choose a reason for hiding this comment

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

should these fmt.Printfs be logging statements?

seelog.Infof("Received tasks metadata: %s \n", string(body))

var tasksMetadata TasksResponse
err = json.Unmarshal(body, &tasksMetadata)

Choose a reason for hiding this comment

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

Unmarshal could also work with case insensitive, this won't capture the bug, example: https://play.golang.org/p/iH8nsK-UJ_L

@haikuoliu haikuoliu force-pushed the branch_func_tests_agent_introspection branch 2 times, most recently from 4465113 to fbd2072 Compare August 7, 2018 23:43
@haikuoliu
Copy link
Contributor Author

@richardpen I have refactored accordingly.

Copy link

@richardpen richardpen left a comment

Choose a reason for hiding this comment

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

Mostly looks good, minor comments

func TestAgentIntrospectionValidator(t *testing.T) {
// The Docker version was 17.03.1-ce when we added changes to agent
// introspection endpoint feature for the last time.
RequireDockerVersion(t, ">=17.03.1-ce")

Choose a reason for hiding this comment

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

Why was this required? The introspection API shouldn't have dependency on the docker version.

require.NoError(t, err, "Error waiting for task to transition to STOPPED")
exitCode, _ := task.ContainerExitcode("agent-introspection-validator")

assert.Equal(t, 42, exitCode, fmt.Sprintf("Expected exit code of 42; got %d", exitCode))

Choose a reason for hiding this comment

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

Minor: you can just use assert.Equalf to get rid of the fmt.Sprintf.

containerName, actualContainerName)
}

if containerMetadataMap["DockerID"] == nil {

Choose a reason for hiding this comment

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

Shouldn't this be DockerId?

@haikuoliu haikuoliu force-pushed the branch_func_tests_agent_introspection branch 2 times, most recently from faa8ed8 to a15382f Compare August 9, 2018 22:03
Copy link

@richardpen richardpen left a comment

Choose a reason for hiding this comment

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

LGTM, please make sure all tests pass.

@haikuoliu haikuoliu force-pushed the branch_func_tests_agent_introspection branch from a15382f to 8fb0a25 Compare August 10, 2018 17:12
@haikuoliu haikuoliu merged commit 78f7105 into aws:dev Aug 10, 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.

4 participants