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

Don't show blank IPs metadata row for containers with no IP #960

Merged
merged 3 commits into from
Feb 19, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion probe/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
ContainerState = "docker_container_state"
ContainerUptime = "docker_container_uptime"
ContainerRestartCount = "docker_container_restart_count"
ContainerNetworkMode = "docker_container_network_mode"

NetworkRxDropped = "network_rx_dropped"
NetworkRxBytes = "network_rx_bytes"
Expand All @@ -58,6 +59,8 @@ const (
StateStopped = "stopped"
StatePaused = "paused"

NetworkModeHost = "host"

stopTimeout = 10
)

Expand Down Expand Up @@ -318,7 +321,10 @@ func (c *container) GetNode(hostID string, localAddrs []net.IP) report.Node {
c.RLock()
defer c.RUnlock()

ips := append(c.container.NetworkSettings.SecondaryIPAddresses, c.container.NetworkSettings.IPAddress)
ips := c.container.NetworkSettings.SecondaryIPAddresses
if c.container.NetworkSettings.IPAddress != "" {
ips = append(ips, c.container.NetworkSettings.IPAddress)
}
// Treat all Docker IPs as local scoped.
ipsWithScopes := []string{}
for _, ip := range ips {
Expand Down Expand Up @@ -352,6 +358,7 @@ func (c *container) GetNode(hostID string, localAddrs []net.IP) report.Node {
result = result.WithLatests(map[string]string{
ContainerUptime: uptime.String(),
ContainerRestartCount: strconv.Itoa(c.container.RestartCount),
ContainerNetworkMode: c.container.HostConfig.NetworkMode,
})
result = result.WithControls(
RestartContainer, StopContainer, PauseContainer, AttachContainer, ExecContainer,
Expand Down
54 changes: 53 additions & 1 deletion render/topologies.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package render

import (
"fmt"
"net"

"github.com/weaveworks/scope/probe/docker"
"github.com/weaveworks/scope/probe/host"
"github.com/weaveworks/scope/probe/process"
"github.com/weaveworks/scope/report"
)
Expand Down Expand Up @@ -116,6 +118,56 @@ var ContainerRenderer = MakeReduce(
),
)

type containerWithHostIPsRenderer struct {
Renderer
}

// Render produces a process graph where the ips for host network mode are set
// to the host's IPs.
func (r containerWithHostIPsRenderer) Render(rpt report.Report) RenderableNodes {
containers := r.Renderer.Render(rpt)
hosts := MakeMap(
MapHostIdentity,
SelectHost,
).Render(rpt)

for id, c := range containers {
networkMode, ok := c.Node.Latest.Lookup(docker.ContainerNetworkMode)
if !ok || networkMode != docker.NetworkModeHost {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

continue
}

ips, ok := c.Node.Sets.Lookup(docker.ContainerIPs)
if ok && len(ips) > 0 {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

continue
}

h, ok := hosts[MakeHostID(report.ExtractHostID(c.Node))]
if !ok {
continue
}

hostNetworks, ok := h.Sets.Lookup(host.LocalNetworks)
if !ok {
continue
}

hostIPs := report.MakeStringSet()
for _, cidr := range hostNetworks {
if ip, _, err := net.ParseCIDR(cidr); err == nil {
hostIPs = hostIPs.Add(ip.String())
}
}

c.Sets = c.Sets.Add(docker.ContainerIPs, hostIPs)
containers[id] = c
}

return containers
}

var ContainerWithHostIPsRenderer = containerWithHostIPsRenderer{ContainerRenderer}

type containerWithImageNameRenderer struct {
Renderer
}
Expand Down Expand Up @@ -149,7 +201,7 @@ func (r containerWithImageNameRenderer) Render(rpt report.Report) RenderableNode

// ContainerWithImageNameRenderer is a Renderer which produces a container
// graph where the ranks are the image names, not their IDs
var ContainerWithImageNameRenderer = containerWithImageNameRenderer{ContainerRenderer}
var ContainerWithImageNameRenderer = containerWithImageNameRenderer{ContainerWithHostIPsRenderer}

// ContainerImageRenderer is a Renderer which produces a renderable container
// image graph by merging the container graph and the container image topology.
Expand Down