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

handlers: add eni info to instrospection endpoint #1271

Merged
merged 3 commits into from
Mar 2, 2018
Merged

Conversation

adnxn
Copy link
Contributor

@adnxn adnxn commented Mar 1, 2018

Summary

adding eni info to instrospection endpoint, addresses #1247

in awsvpc mode:

$ curl localhost:51678/v1/tasks | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   433  100   433    0     0   270k      0 --:--:-- --:--:-- --:--:--  422k
  {
      "Arn": "arn:aws:ecs:us-west-2:410584942969:task/c1bc8e40-35d9-4e1e-ba36-3e366fd8c97c",
      "DesiredStatus": "RUNNING",
      "KnownStatus": "RUNNING",
      "Family": "sleep300",
      "Version": "6",
      "Containers": [
        {
          "DockerId": "fc43f49749cfa09fba02ccf7cdf88c453604b05686b07b278de849466c32ec1f",
          "DockerName": "ecs-sleep300-6-sleep-aef3d2fbb494a5e08201",
          "Name": "sleep",
          "Ports": [],
          "Networks": [
            {
              "NetworkMode": "awsvpc",
              "IPv4Addresses": [
                "172.31.23.89"
              ]
            }
          ]
        }
      ]
    }

in bridge mode:

  {
      "Arn": "arn:aws:ecs:us-west-2:410584942969:task/5a54d2c3-9a13-42a0-82aa-4ffbe0570de1",
      "DesiredStatus": "RUNNING",
      "KnownStatus": "RUNNING",
      "Family": "sleep300",
      "Version": "8",
      "Containers": [
        {
          "DockerId": "58a5d93e855286c6d5557b2acc2aec9ef932e7da7c7004c73cfedb1f24bd8be2",
          "DockerName": "ecs-sleep300-8-sleep-beabc8d5aaf593ff0c00",
          "Name": "sleep",
          "Ports": [
            {
              "ContainerPort": 80,
              "Protocol": "tcp",
              "HostPort": 80
            },
            {
              "ContainerPort": 88,
              "Protocol": "tcp",
              "HostPort": 32769
            },
            {
              "ContainerPort": 90,
              "Protocol": "tcp",
              "HostPort": 32768
            }
          ],
          "Networks": null
        }
      ]
    }

in host mode:

  {
  "Tasks": [
    {
      "Arn": "arn:aws:ecs:us-west-2:410584942969:task/93a01f80-25c2-4517-9e5f-c302a8228623",
      "DesiredStatus": "RUNNING",
      "KnownStatus": "RUNNING",
      "Family": "sleep300",
      "Version": "7",
      "Containers": [
        {
          "DockerId": "cf8d7dc7532e0fc0b84605af13ecd6fb6822a38e50e1cb1fe774782d88a963b2",
          "DockerName": "ecs-sleep300-7-sleep-ceeaf4c78ea281ac3000",
          "Name": "sleep",
          "Ports": [
            {
              "ContainerPort": 80,
              "Protocol": "tcp",
              "HostPort": 80
            },
            {
              "ContainerPort": 90,
              "Protocol": "udp",
              "HostPort": 90
            }
          ],
          "Networks": null
        }
      ]
    }
  ]
}

Implementation details

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:

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.

@adnxn adnxn requested review from aaithal and richardpen March 1, 2018 01:05
@@ -28,6 +28,7 @@ type TaskResponse struct {
Family string
Version string
Containers []ContainerResponse
Networks []NetworkResponse
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to

Networks []containermetadata.Network `json:",omitempty"`
, this should be part of the ContainerResponse struct.

@adnxn adnxn added this to the 1.17.2 milestone Mar 1, 2018
}

// NetworkResponse is the schema for the network response JSON object
type NetworkResponse struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should just reuse this

. I don't think you need to create a new struct

resp.DockerId = container.DockerID
resp.DockerName = container.DockerName

if eni != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should also populate resp.Networks when eni == nil , with whatever value we can get from container's metadata

containers := []v1.ContainerResponse{}
for containerName, container := range containerMap {
if container.Container.IsInternal() {
continue
}
containers = append(containers, v1.ContainerResponse{DockerId: container.DockerID, DockerName: container.DockerName, Name: containerName})
containerResponse := newContainerResponse(containerName, container, task.GetTaskENI())
containers = append(containers, containerResponse)

Choose a reason for hiding this comment

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

nit: would it be more readable to use containerResponses instead of containers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i decided against changing this because containerResponse and containerResponses are very similar

@adnxn adnxn changed the title [wip] handlers: add eni info to instrospection endpoint handlers: add eni info to instrospection endpoint Mar 1, 2018
@adnxn adnxn force-pushed the eni-metadata branch 2 times, most recently from e777310 to 3b39656 Compare March 1, 2018 22:33
DockerName: dockerContainer.DockerName,
}

for _, binding := range container.Ports {

Choose a reason for hiding this comment

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

Can you add a getter in the container struct to return the Ports and use the getter instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make the change. Just wondering why we should use a getter if Ports is an exported field. I think we make it an exported field so we can serialize it.

Choose a reason for hiding this comment

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

yes, some other fields like KnowStatus is exported for the same purpose.

if eni != nil {
resp.Networks = []containermetadata.Network{
{
NetworkMode: "awsvpc",
Copy link
Contributor

Choose a reason for hiding this comment

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

minor, const this. there must be a const somewhere with that string.

c.lock.RLock()
defer c.lock.RUnlock()

return c.Ports
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rename Ports to PortsUnsafe?

@@ -493,6 +493,22 @@ func (c *Container) GetLabels() map[string]string {
return c.labels
}

// SetKnownPortBindings gets the ports for a container
func (c *Container) SetKnownPortBindings(ports []PortBinding) {
c.lock.RLock()

Choose a reason for hiding this comment

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

This should be a write lock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, good catch.

@@ -493,6 +493,22 @@ func (c *Container) GetLabels() map[string]string {
return c.labels
}

// SetKnownPortBindings gets the ports for a container

Choose a reason for hiding this comment

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

minor s/get/set/


if eni == nil {
port.HostPort = binding.HostPort
} else {

Choose a reason for hiding this comment

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

If the container does use ENI, the binding should be empty, you should read the port information from container.Port. So I think you can do this:

bindings := container.GetKnownPortBindings()
if len(bindings) == 0{
// Put the port information from task definition
}else{
// put the information from bindings
}


// if KnownPortBindings list is empty, then we use the port mapping
// information that was passed down from ACS.
if len(bindings) == 0 {

Choose a reason for hiding this comment

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

Can you update the test to cover this?

@@ -40,4 +45,6 @@ type ContainerResponse struct {
DockerId string
DockerName string
Name string
Ports []v2.PortResponse
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 needs an omitempty tag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ya you're right. added.

@adnxn adnxn force-pushed the eni-metadata branch 2 times, most recently from a02f0bf to 374b08b Compare March 2, 2018 20:15
@adnxn adnxn merged commit 64a0760 into aws:dev Mar 2, 2018
adnxn added a commit that referenced this pull request Mar 2, 2018
@adnxn adnxn deleted the eni-metadata branch October 19, 2018 17:35
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.

3 participants