-
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
Move introspection server to ecs-agent #4470
base: dev
Are you sure you want to change the base?
Conversation
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{ |
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.
multiple occurrences - why do we ignore the error returned from this method?
|
||
server := introspectionServerSetup(containerInstanceArn, dockerTaskEngine, cfg) | ||
server, _ := introspection.NewServer( |
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.
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)) |
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.
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 { |
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.
you don't need this check. you just need to use the bool that
func (state *DockerTaskEngineState) TaskByShortID(cid string) ([]*apitask.Task, bool) { |
tasks, _ := agentState.TaskByShortID(shortDockerID) | ||
if len(tasks) == 0 { | ||
return nil, introspection.NewErrorNotFound(fmt.Sprintf("Task %s not found", shortDockerID)) | ||
} else if len(tasks) > 1 { |
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 check?
} | ||
|
||
// getErrorResponse returns an appropriate HTTP response status code and body for the error. | ||
func getErrorResponse(err error) (int, 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.
Can we rename this as getHTTPErrorCode()
? getErrorResponse
is way too generic for what this method is doing.
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 anAgentState
interface which will be implemented in the ECS and Fargate agents. TheAgentState
implementations will supply the server with the data it needs to construct responses. This change also includes the ECS agent's implementation ofAgentState
.Testing
Unit and integration tests
New unit and integration tests were added to the
introspection
package inecs-agent
. Where applicable, existing tests were updated. Existingunit
tests forintrospection_server
inagent/handlers/v1
were moved to anintegration
test file with the intent to: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
Shared implementation
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.