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

Move introspection server to ecs-agent #4470

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

willmyrs
Copy link

Summary

As part of the effort to bring the Agent Introspection Server to the Fargate Agent, this change moves the server's implementation to the shared ecs-agent library.

Implementation details

The http server logic for the introspection server is moved to the shared ecs-agent library. This refactored server is responsible for handling http requests and generating responses. The server defines an AgentState interface which will be implemented in the ECS and Fargate agents. The AgentState implementations will supply the server with the data it needs to construct responses. This change also includes the ECS agent's implementation of AgentState.

Testing

Unit and integration tests

New unit and integration tests were added to the introspection package in ecs-agent. Where applicable, existing tests were updated. Existing unit tests for introspection_server in agent/handlers/v1 were moved to an integration test file with the intent to:

  1. Not lose test coverage and,
  2. Verify that the behavior on the client-end is not affected by the refactored server implementation.

Manual tests

Outputs from the Agent introspection server were recorded from two test clusters: one using the current version of the ECS agent, and the other using a modified build with the shared introspection server implementation. E.g.,

/v1/metadata

Current implementation

curl -s http://localhost:51678/v1/metadata | python3 -mjson.tool
{
    "Cluster": "ecs",
    "ContainerInstanceArn": "arn:aws:ecs:us-west-2:337909766174:container-instance/ecs/9d800cebdaba4380a21de1ec90add214",
    "Version": "Amazon ECS Agent - v1.89.2 (*41d593c6)"
}

Shared implementation

curl -s http://localhost:51678/v1/metadata | python3 -mjson.tool
{
    "Cluster": "ecs-test",
    "ContainerInstanceArn": "arn:aws:ecs:us-west-2:337909766174:container-instance/ecs-test/0f8883751d474a62aefbc3e945ad857a",
    "Version": "Amazon ECS Agent - v1.89.3 (*c46c0f4d)"
}

New tests cover the changes: yes

Description for the changelog

Feature - Move agent introspection server to shared library

Additional Information

Does this PR include breaking model changes? If so, Have you added transformation functions?
No

Does this PR include the addition of new environment variables in the README?
No

Licensing

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

To make the Agent Introspection Server available to the Fargate agent,
the introspection server is now implemented in the shared ecs-agent
library. The ECS agent introspection server is refactored to use this
shared implementation.

mockStateResolver := mock_utils.NewMockDockerStateResolver(ctrl)

server, _ := introspection.NewServer(&v1.AgentStateImpl{
Copy link
Contributor

Choose a reason for hiding this comment

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

multiple occurrences - why do we ignore the error returned from this method?


server := introspectionServerSetup(containerInstanceArn, dockerTaskEngine, cfg)
server, _ := introspection.NewServer(
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to deal with the error returned here.

for ndx, task := range allTasks {
containerMap, ok := agentState.ContainerMapByArn(task.Arn)
if !ok {
return nil, introspection.NewErrorNotFound(fmt.Sprintf("Container map for task %s not found", task.Arn))
Copy link
Contributor

Choose a reason for hiding this comment

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

multiple occurrences - error strings should begin with lower case letters. See https://google.github.io/styleguide/go/decisions.html#error-strings

func (as *AgentStateImpl) GetTaskMetadataByShortID(shortDockerID string) (*introspection.TaskResponse, error) {
agentState := as.TaskEngine.State()
tasks, _ := agentState.TaskByShortID(shortDockerID)
if len(tasks) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need this check. you just need to use the bool that

func (state *DockerTaskEngineState) TaskByShortID(cid string) ([]*apitask.Task, bool) {
returns.

tasks, _ := agentState.TaskByShortID(shortDockerID)
if len(tasks) == 0 {
return nil, introspection.NewErrorNotFound(fmt.Sprintf("Task %s not found", shortDockerID))
} else if len(tasks) > 1 {
Copy link
Contributor

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 check?

}

// getErrorResponse returns an appropriate HTTP response status code and body for the error.
func getErrorResponse(err error) (int, string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this as getHTTPErrorCode()? getErrorResponse is way too generic for what this method is doing.

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.

6 participants