From 0fd2754b5884e68618a5882e63c85c3a53050f68 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 10 Jun 2016 17:38:09 +0000 Subject: [PATCH 1/2] Gather IPs from all the container networks --- probe/docker/container.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/probe/docker/container.go b/probe/docker/container.go index a559ba4b9..eaeea8015 100644 --- a/probe/docker/container.go +++ b/probe/docker/container.go @@ -311,18 +311,21 @@ func (c *container) NetworkInfo(localAddrs []net.IP) report.Sets { c.RLock() defer c.RUnlock() + ips := c.container.NetworkSettings.SecondaryIPAddresses + if c.container.NetworkSettings.IPAddress != "" { + ips = append(ips, c.container.NetworkSettings.IPAddress) + } + // For now, for the proof-of-concept, we just add networks as a set of // names. For the next iteration, we will probably want to create a new // Network topology, populate the network nodes with all of the details // here, and provide foreign key links from nodes to networks. networks := make([]string, 0, len(c.container.NetworkSettings.Networks)) - for name := range c.container.NetworkSettings.Networks { + for name, settings := range c.container.NetworkSettings.Networks { networks = append(networks, name) - } - - ips := c.container.NetworkSettings.SecondaryIPAddresses - if c.container.NetworkSettings.IPAddress != "" { - ips = append(ips, c.container.NetworkSettings.IPAddress) + if settings.IPAddress != "" { + ips = append(ips, settings.IPAddress) + } } // Treat all Docker IPs as local scoped. From 47c57549234e4a442720287aa07038408beabe8e Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Mon, 13 Jun 2016 11:35:12 +0000 Subject: [PATCH 2/2] Add test --- probe/docker/container_test.go | 9 ++++++--- probe/docker/registry_test.go | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/probe/docker/container_test.go b/probe/docker/container_test.go index 0c8faad37..3ed5f78d8 100644 --- a/probe/docker/container_test.go +++ b/probe/docker/container_test.go @@ -114,7 +114,10 @@ func TestContainer(t *testing.T) { Add("docker_container_ports", report.MakeStringSet("1.2.3.4:80->80/tcp", "81/tcp")). Add("docker_container_networks", nil). Add("docker_container_ips", report.MakeStringSet("1.2.3.4")). - Add("docker_container_ips_with_scopes", report.MakeStringSet(";1.2.3.4")) + Add("docker_container_ips", report.MakeStringSet("5.6.7.8")). + Add("docker_container_ips_with_scopes", report.MakeStringSet(";1.2.3.4")). + Add("docker_container_ips_with_scopes", report.MakeStringSet(";5.6.7.8")). + Add("docker_container_networks", report.MakeStringSet("network1")) test.Poll(t, 100*time.Millisecond, want, func() interface{} { return c.NetworkInfo([]net.IP{}) @@ -128,7 +131,7 @@ func TestContainer(t *testing.T) { t.Errorf("%d != 2", c.PID()) } node := c.GetNode().WithSets(c.NetworkInfo([]net.IP{})) - if have := docker.ExtractContainerIPs(node); !reflect.DeepEqual(have, []string{"1.2.3.4"}) { - t.Errorf("%v != %v", have, []string{"1.2.3.4"}) + if have := docker.ExtractContainerIPs(node); !reflect.DeepEqual(have, []string{"1.2.3.4", "5.6.7.8"}) { + t.Errorf("%v != %v", have, []string{"1.2.3.4", "5.6.7.8"}) } } diff --git a/probe/docker/registry_test.go b/probe/docker/registry_test.go index 44471f8d8..f6599403f 100644 --- a/probe/docker/registry_test.go +++ b/probe/docker/registry_test.go @@ -196,6 +196,11 @@ var ( }, client.Port("81/tcp"): {}, }, + Networks: map[string]client.ContainerNetwork{ + "network1": { + IPAddress: "5.6.7.8", + }, + }, }, Config: &client.Config{ Labels: map[string]string{