Skip to content

Commit

Permalink
render sensible labels for parent nodes with little/no metadata
Browse files Browse the repository at this point in the history
We eliminate the custom parent renderer, which was a very partial
implementation MakeBasicNodeSummary.

We also ensure that parents are always rendered in the same, sensible
order. Previously the order was an alphabetic sort of the parent
topology IDs. Now lower level topologies come before higher level
topologies.
  • Loading branch information
rade committed Dec 26, 2017
1 parent 9674878 commit 4b1ab76
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 68 deletions.
20 changes: 10 additions & 10 deletions render/detailed/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,16 @@ func TestMakeDetailedContainerNode(t *testing.T) {
Label: fixture.ServerContainerImageName,
TopologyID: "containers-by-image",
},
{
ID: fixture.ServerHostNodeID,
Label: fixture.ServerHostName,
TopologyID: "hosts",
},
{
ID: fixture.ServerPodNodeID,
Label: "pong-b",
TopologyID: "pods",
},
{
ID: fixture.ServerHostNodeID,
Label: "server",
TopologyID: "hosts",
},
},
},
Controls: []detailed.ControlInstance{},
Expand Down Expand Up @@ -339,16 +339,16 @@ func TestMakeDetailedPodNode(t *testing.T) {
{ID: "kubernetes_namespace", Label: "Namespace", Value: "ping", Priority: 5},
},
Parents: []detailed.Parent{
{
ID: fixture.ServerHostNodeID,
Label: fixture.ServerHostName,
TopologyID: "hosts",
},
{
ID: fixture.ServiceNodeID,
Label: fixture.ServiceName,
TopologyID: "services",
},
{
ID: fixture.ServerHostNodeID,
Label: "server",
TopologyID: "hosts",
},
},
},
Controls: []detailed.ControlInstance{},
Expand Down
79 changes: 24 additions & 55 deletions render/detailed/parents.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package detailed

import (
"sort"

"github.com/weaveworks/scope/probe/awsecs"
"github.com/weaveworks/scope/probe/docker"
"github.com/weaveworks/scope/probe/host"
"github.com/weaveworks/scope/probe/kubernetes"
"github.com/weaveworks/scope/report"
)

Expand All @@ -17,24 +11,21 @@ type Parent struct {
TopologyID string `json:"topologyId"`
}

var (
kubernetesParentLabel = latestLookup(kubernetes.Name)

getLabelForTopology = map[string]func(report.Node) string{
report.Container: getRenderableContainerName,
report.Pod: kubernetesParentLabel,
report.Deployment: kubernetesParentLabel,
report.DaemonSet: kubernetesParentLabel,
report.StatefulSet: kubernetesParentLabel,
report.CronJob: kubernetesParentLabel,
report.Service: kubernetesParentLabel,
report.ECSTask: latestLookup(awsecs.TaskFamily),
report.ECSService: ecsServiceParentLabel,
report.SwarmService: latestLookup(docker.ServiceName),
report.ContainerImage: containerImageParentLabel,
report.Host: latestLookup(host.HostName),
}
)
// parent topologies, in the order we want to show them
var parentTopologies = []string{
report.Container,
report.ContainerImage,
report.Pod,
report.Deployment,
report.DaemonSet,
report.StatefulSet,
report.CronJob,
report.Service,
report.ECSTask,
report.ECSService,
report.SwarmService,
report.Host,
}

// Parents renders the parents of this report.Node, which have been aggregated
// from the probe reports.
Expand All @@ -43,13 +34,7 @@ func Parents(r report.Report, n report.Node) []Parent {
return nil
}
result := make([]Parent, 0, n.Parents.Size())
topologyIDs := []string{}
for topologyID := range getLabelForTopology {
topologyIDs = append(topologyIDs, topologyID)
}
sort.Strings(topologyIDs)
for _, topologyID := range topologyIDs {
getLabel := getLabelForTopology[topologyID]
for _, topologyID := range parentTopologies {
topology, ok := r.Topology(topologyID)
if !ok {
continue
Expand All @@ -63,7 +48,7 @@ func Parents(r report.Report, n report.Node) []Parent {
var parentNode report.Node
// Special case: container image parents should be empty nodes for some reason
if topologyID == report.ContainerImage {
parentNode = report.MakeNode(id)
parentNode = report.MakeNode(id).WithTopology(topologyID)
} else {
if parent, ok := topology.Nodes[id]; ok {
parentNode = parent
Expand All @@ -76,33 +61,17 @@ func Parents(r report.Report, n report.Node) []Parent {
if !ok {
continue
}

result = append(result, Parent{
ID: id,
Label: getLabel(parentNode),
TopologyID: apiTopologyID,
})
if summary, ok := MakeBasicNodeSummary(r, parentNode); ok {
result = append(result, Parent{
ID: summary.ID,
Label: summary.Label,
TopologyID: apiTopologyID,
})
}
}
}
if len(result) == 0 {
return nil
}
return result
}

func latestLookup(key string) func(report.Node) string {
return func(n report.Node) string {
value, _ := n.Latest.Lookup(key)
return value
}
}

func ecsServiceParentLabel(n report.Node) string {
_, name, _ := report.ParseECSServiceNodeID(n.ID)
return name
}

func containerImageParentLabel(n report.Node) string {
name, _ := report.ParseContainerImageNodeID(n.ID)
return name
}
6 changes: 3 additions & 3 deletions render/detailed/parents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ func TestParents(t *testing.T) {
name: "Container image",
node: render.ContainerImageRenderer.Render(fixture.Report).Nodes[expected.ClientContainerImageNodeID],
want: []detailed.Parent{
{ID: fixture.ClientHostNodeID, Label: fixture.ClientHostName, TopologyID: "hosts"},
{ID: fixture.ClientHostNodeID, Label: "client", TopologyID: "hosts"},
},
},
{
name: "Container",
node: render.ContainerWithImageNameRenderer.Render(fixture.Report).Nodes[fixture.ClientContainerNodeID],
want: []detailed.Parent{
{ID: expected.ClientContainerImageNodeID, Label: fixture.ClientContainerImageName, TopologyID: "containers-by-image"},
{ID: fixture.ClientHostNodeID, Label: fixture.ClientHostName, TopologyID: "hosts"},
{ID: fixture.ClientPodNodeID, Label: "pong-a", TopologyID: "pods"},
{ID: fixture.ClientHostNodeID, Label: "client", TopologyID: "hosts"},
},
},
{
node: render.ProcessRenderer.Render(fixture.Report).Nodes[fixture.ClientProcess1NodeID],
want: []detailed.Parent{
{ID: fixture.ClientContainerNodeID, Label: fixture.ClientContainerName, TopologyID: "containers"},
{ID: fixture.ClientHostNodeID, Label: fixture.ClientHostName, TopologyID: "hosts"},
{ID: fixture.ClientHostNodeID, Label: "client", TopologyID: "hosts"},
},
},
} {
Expand Down

0 comments on commit 4b1ab76

Please sign in to comment.