Skip to content

Commit

Permalink
Add "# Containers" column to container images as children
Browse files Browse the repository at this point in the history
Side effect is that it also adds it to the container image details panel
  • Loading branch information
paulbellamy committed Feb 5, 2016
1 parent 00cd193 commit a403917
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions render/detailed/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/weaveworks/scope/probe/kubernetes"
"github.com/weaveworks/scope/probe/overlay"
"github.com/weaveworks/scope/probe/process"
"github.com/weaveworks/scope/render"
)

var labels = map[string]string{
Expand Down Expand Up @@ -44,6 +45,7 @@ var labels = map[string]string{
process.PID: "PID",
process.PPID: "Parent PID",
process.Threads: "# Threads",
render.ContainersKey: "# Containers",
}

// Label maps from the internal keys to the human-readable label for a piece
Expand Down
12 changes: 12 additions & 0 deletions render/detailed/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package detailed

import (
"encoding/json"
"strconv"
"strings"

"github.com/weaveworks/scope/probe/docker"
"github.com/weaveworks/scope/probe/host"
"github.com/weaveworks/scope/probe/kubernetes"
"github.com/weaveworks/scope/probe/overlay"
"github.com/weaveworks/scope/probe/process"
"github.com/weaveworks/scope/render"
"github.com/weaveworks/scope/report"
)

Expand All @@ -34,6 +36,7 @@ var (
)
containerImageNodeMetadata = renderMetadata(
ltst(docker.ImageID),
counter(render.ContainersKey),
)
podNodeMetadata = renderMetadata(
ltst(kubernetes.PodID),
Expand Down Expand Up @@ -120,3 +123,12 @@ func ltst(id string) func(report.Node) []MetadataRow {
return nil
}
}

func counter(id string) func(report.Node) []MetadataRow {
return func(n report.Node) []MetadataRow {
if val, ok := n.Counters.Lookup(id); ok {
return []MetadataRow{{ID: id, Value: strconv.Itoa(val)}}
}
return nil
}
}
2 changes: 1 addition & 1 deletion render/detailed/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var (
}{
{report.Host, NodeSummaryGroup{TopologyID: "hosts", Label: "Hosts", Columns: []string{host.CPUUsage, host.MemoryUsage}}},
{report.Pod, NodeSummaryGroup{TopologyID: "pods", Label: "Pods", Columns: []string{}}},
{report.ContainerImage, NodeSummaryGroup{TopologyID: "containers-by-image", Label: "Container Images", Columns: []string{}}},
{report.ContainerImage, NodeSummaryGroup{TopologyID: "containers-by-image", Label: "Container Images", Columns: []string{render.ContainersKey}}},
{report.Container, NodeSummaryGroup{TopologyID: "containers", Label: "Containers", Columns: []string{docker.CPUTotalUsage, docker.MemoryUsage}}},
{report.Process, NodeSummaryGroup{TopologyID: "processes", Label: "Processes", Columns: []string{process.PID, process.CPUUsage, process.MemoryUsage}}},
}
Expand Down
6 changes: 4 additions & 2 deletions render/detailed/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ func TestMakeDetailedHostNode(t *testing.T) {
renderableNode := render.HostRenderer.Render(fixture.Report)[render.MakeHostID(fixture.ClientHostID)]
have := detailed.MakeNode(fixture.Report, renderableNode)

containerImageNodeSummary, _ := detailed.MakeNodeSummary(fixture.Report.ContainerImage.Nodes[fixture.ClientContainerImageNodeID])
containerImageNodeSummary, _ := detailed.MakeNodeSummary(
render.ContainerImageRenderer.Render(fixture.Report)[render.MakeContainerImageID(fixture.ClientContainerImageName)].Node,
)
containerNodeSummary, _ := detailed.MakeNodeSummary(fixture.Report.Container.Nodes[fixture.ClientContainerNodeID])
process1NodeSummary, _ := detailed.MakeNodeSummary(fixture.Report.Process.Nodes[fixture.ClientProcess1NodeID])
process1NodeSummary.Linkable = true
Expand Down Expand Up @@ -83,7 +85,7 @@ func TestMakeDetailedHostNode(t *testing.T) {
{
Label: "Container Images",
TopologyID: "containers-by-image",
Columns: []string{},
Columns: []string{render.ContainersKey},
Nodes: []detailed.NodeSummary{containerImageNodeSummary},
},
{
Expand Down
10 changes: 5 additions & 5 deletions render/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
TheInternetID = "theinternet"
TheInternetMajor = "The Internet"

containersKey = "containers"
ContainersKey = "containers"
ipsKey = "ips"
podsKey = "pods"
processesKey = "processes"
Expand Down Expand Up @@ -520,7 +520,7 @@ func MapContainer2ContainerImage(n RenderableNode, _ report.Networks) Renderable
// Add container id key to the counters, which will later be counted to produce the minor label
id := MakeContainerImageID(imageID)
result := NewDerivedNode(id, n.WithParents(report.EmptySets))
result.Node.Counters = result.Node.Counters.Add(containersKey, 1)
result.Node.Counters = result.Node.Counters.Add(ContainersKey, 1)

// Add the container as a child of the new image node
result.Children = result.Children.Add(n.Node)
Expand Down Expand Up @@ -653,7 +653,7 @@ func MapContainer2Pod(n RenderableNode, _ report.Networks) RenderableNodes {
// Add container-<id> key to NMD, which will later be counted to produce the
// minor label
result := NewRenderableNodeWith(id, "", "", podID, n.WithParents(report.EmptySets))
result.Counters = result.Counters.Add(containersKey, 1)
result.Counters = result.Counters.Add(ContainersKey, 1)

// Due to a bug in kubernetes, addon pods on the master node are not returned
// from the API. This is a workaround until
Expand Down Expand Up @@ -690,7 +690,7 @@ func MapContainer2Hostname(n RenderableNode, _ report.Networks) RenderableNodes
result.Rank = id

// Add container id key to the counters, which will later be counted to produce the minor label
result.Counters = result.Counters.Add(containersKey, 1)
result.Counters = result.Counters.Add(ContainersKey, 1)

result.Node.Topology = "container_hostname"
result.Node.ID = id
Expand All @@ -708,7 +708,7 @@ func MapCountContainers(n RenderableNode, _ report.Networks) RenderableNodes {
return RenderableNodes{n.ID: n}
}

containers, _ := n.Node.Counters.Lookup(containersKey)
containers, _ := n.Node.Counters.Lookup(ContainersKey)
if containers == 1 {
n.LabelMinor = "1 container"
} else {
Expand Down
9 changes: 1 addition & 8 deletions render/topologies.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,7 @@ var AddressRenderer = MakeMap(
var HostRenderer = MakeReduce(
MakeMap(
MapX2Host,
MakeMap(
MapContainerImageIdentity,
SelectContainerImage,
),
),
MakeMap(
MapX2Host,
FilterPseudo(ContainerRenderer),
FilterPseudo(ContainerImageRenderer),
),
MakeMap(
MapX2Host,
Expand Down

0 comments on commit a403917

Please sign in to comment.