mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-02 17:50:39 +00:00
refactor: introduce ParseGroupNodeTopology
This commit is contained in:
@@ -337,21 +337,21 @@ func weaveNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) {
|
||||
// groupNodeSummary renders the summary for a group node. n.Topology is
|
||||
// expected to be of the form: group:container:hostname
|
||||
func groupNodeSummary(base NodeSummary, r report.Report, n report.Node) (NodeSummary, bool) {
|
||||
parts := strings.Split(n.Topology, ":")
|
||||
if len(parts) != 3 {
|
||||
topology, key, ok := render.ParseGroupNodeTopology(n.Topology)
|
||||
if !ok {
|
||||
return NodeSummary{}, false
|
||||
}
|
||||
|
||||
label, ok := n.Latest.Lookup(parts[2])
|
||||
label, ok := n.Latest.Lookup(key)
|
||||
if !ok {
|
||||
return NodeSummary{}, false
|
||||
}
|
||||
base.Label, base.Rank = label, label
|
||||
|
||||
if t, ok := r.Topology(parts[1]); ok {
|
||||
if t, ok := r.Topology(topology); ok {
|
||||
base.Shape = t.GetShape()
|
||||
if t.Label != "" {
|
||||
base.LabelMinor = pluralize(n.Counters, parts[1], t.Label, t.LabelPlural)
|
||||
base.LabelMinor = pluralize(n.Counters, topology, t.Label, t.LabelPlural)
|
||||
}
|
||||
}
|
||||
base.Stack = true
|
||||
|
||||
@@ -42,6 +42,15 @@ func MakeGroupNodeTopology(originalTopology, key string) string {
|
||||
return strings.Join([]string{"group", originalTopology, key}, ":")
|
||||
}
|
||||
|
||||
// ParseGroupNodeTopology returns the parts of a group topology.
|
||||
func ParseGroupNodeTopology(topology string) (string, string, bool) {
|
||||
parts := strings.Split(topology, ":")
|
||||
if len(parts) != 3 || parts[0] != "group" {
|
||||
return "", "", false
|
||||
}
|
||||
return parts[1], parts[2], true
|
||||
}
|
||||
|
||||
// NewDerivedNode makes a node based on node, but with a new ID
|
||||
func NewDerivedNode(id string, node report.Node) report.Node {
|
||||
return report.MakeNode(id).WithChildren(node.Children.Add(node))
|
||||
|
||||
Reference in New Issue
Block a user