mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-09 10:47:27 +00:00
Move Counters into Latest
The only place Counters are used is in rendering, for the number of nodes under a topology, so the overhead of holding a unique data structure in every Node is unwarranted.
This commit is contained in:
@@ -304,8 +304,8 @@ func MapContainer2ContainerImage(n report.Node) report.Node {
|
||||
// Add container id key to the counters, which will later be
|
||||
// counted to produce the minor label
|
||||
id := report.MakeContainerImageNodeID(imageID)
|
||||
result := NewDerivedNode(id, n).WithTopology(report.ContainerImage)
|
||||
result.Counters = result.Counters.Add(n.Topology, 1)
|
||||
result := NewDerivedNode(id, n).WithTopology(report.ContainerImage).
|
||||
WithCounter(n.Topology, 1)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -354,8 +354,8 @@ func MapContainer2Hostname(n report.Node) report.Node {
|
||||
return report.Node{}
|
||||
}
|
||||
|
||||
node := NewDerivedNode(id, n).WithTopology(containerHostnameTopology)
|
||||
node.Counters = node.Counters.Add(n.Topology, 1)
|
||||
node := NewDerivedNode(id, n).WithTopology(containerHostnameTopology).
|
||||
WithCounter(n.Topology, 1)
|
||||
return node
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ func MakeNodeSummary(rc RenderContext, n report.Node) (NodeSummary, bool) {
|
||||
Adjacency: n.Adjacency,
|
||||
}
|
||||
// Only include metadata, metrics, tables when it's not a group node
|
||||
if _, ok := n.Counters.Lookup(n.Topology); !ok {
|
||||
if _, ok := n.LookupCounter(n.Topology); !ok {
|
||||
if topology, ok := rc.Topology(n.Topology); ok {
|
||||
summary.Metadata = topology.MetadataTemplates.MetadataRows(n)
|
||||
summary.Metrics = topology.MetricTemplates.MetricRows(n)
|
||||
@@ -292,7 +292,7 @@ func containerImageNodeSummary(base BasicNodeSummary, n report.Node) BasicNodeSu
|
||||
// heuristic regexp match we cannot tell the difference.
|
||||
base.Label, _ = report.ParseContainerImageNodeID(n.ID)
|
||||
}
|
||||
base.LabelMinor = pluralize(n.Counters, report.Container, "container", "containers")
|
||||
base.LabelMinor = pluralize(n, report.Container, "container", "containers")
|
||||
base.Rank = base.Label
|
||||
base.Stack = true
|
||||
return base
|
||||
@@ -314,7 +314,7 @@ func addKubernetesLabelAndRank(base BasicNodeSummary, n report.Node) BasicNodeSu
|
||||
|
||||
func podNodeSummary(base BasicNodeSummary, n report.Node) BasicNodeSummary {
|
||||
base = addKubernetesLabelAndRank(base, n)
|
||||
base.LabelMinor = pluralize(n.Counters, report.Container, "container", "containers")
|
||||
base.LabelMinor = pluralize(n, report.Container, "container", "containers")
|
||||
return base
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ func podGroupNodeSummary(base BasicNodeSummary, n report.Node) BasicNodeSummary
|
||||
base.Stack = true
|
||||
// NB: pods are the highest aggregation level for which we display
|
||||
// counts.
|
||||
count := pluralize(n.Counters, report.Pod, "pod", "pods")
|
||||
count := pluralize(n, report.Pod, "pod", "pods")
|
||||
if typeName, ok := podGroupNodeTypeName[n.Topology]; ok {
|
||||
base.LabelMinor = fmt.Sprintf("%s of %s", typeName, count)
|
||||
} else {
|
||||
@@ -423,7 +423,7 @@ func groupNodeSummary(base BasicNodeSummary, r report.Report, n report.Node) Bas
|
||||
base.Shape = t.GetShape()
|
||||
base.Tag = t.Tag
|
||||
if t.Label != "" {
|
||||
base.LabelMinor = pluralize(n.Counters, topology, t.Label, t.LabelPlural)
|
||||
base.LabelMinor = pluralize(n, topology, t.Label, t.LabelPlural)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -431,8 +431,8 @@ func groupNodeSummary(base BasicNodeSummary, r report.Report, n report.Node) Bas
|
||||
return base
|
||||
}
|
||||
|
||||
func pluralize(counters report.Counters, key, singular, plural string) string {
|
||||
c, ok := counters.Lookup(key)
|
||||
func pluralize(n report.Node, key, singular, plural string) string {
|
||||
c, ok := n.LookupCounter(key)
|
||||
if !ok {
|
||||
c = 0
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ var (
|
||||
RenderedProcessNames = report.Nodes{
|
||||
fixture.Client1Name: processNameNode(fixture.Client1Name, fixture.ServerName).
|
||||
WithLatests(map[string]string{process.Name: fixture.Client1Name}).
|
||||
WithCounters(map[string]int{report.Process: 2}).
|
||||
WithCounter(report.Process, 2).
|
||||
WithChildren(report.MakeNodeSet(
|
||||
RenderedEndpoints[fixture.Client54001NodeID],
|
||||
RenderedEndpoints[fixture.Client54002NodeID],
|
||||
@@ -133,7 +133,7 @@ var (
|
||||
|
||||
fixture.ServerName: processNameNode(fixture.ServerName).
|
||||
WithLatests(map[string]string{process.Name: fixture.ServerName}).
|
||||
WithCounters(map[string]int{report.Process: 1}).
|
||||
WithCounter(report.Process, 1).
|
||||
WithChildren(report.MakeNodeSet(
|
||||
RenderedEndpoints[fixture.Server80NodeID],
|
||||
RenderedProcesses[fixture.ServerProcessNodeID],
|
||||
@@ -190,9 +190,7 @@ var (
|
||||
WithLatests(map[string]string{
|
||||
docker.ContainerHostname: fixture.ClientContainerHostname,
|
||||
}).
|
||||
WithCounters(map[string]int{
|
||||
report.Container: 1,
|
||||
}).
|
||||
WithCounter(report.Container, 1).
|
||||
WithChildren(report.MakeNodeSet(
|
||||
RenderedEndpoints[fixture.Client54001NodeID],
|
||||
RenderedEndpoints[fixture.Client54002NodeID],
|
||||
@@ -226,9 +224,7 @@ var (
|
||||
docker.ImageID: fixture.ClientContainerImageID,
|
||||
docker.ImageName: fixture.ClientContainerImageName,
|
||||
}).
|
||||
WithCounters(map[string]int{
|
||||
report.Container: 1,
|
||||
}).
|
||||
WithCounter(report.Container, 1).
|
||||
WithChildren(report.MakeNodeSet(
|
||||
RenderedEndpoints[fixture.Client54001NodeID],
|
||||
RenderedEndpoints[fixture.Client54002NodeID],
|
||||
|
||||
@@ -195,7 +195,7 @@ func (ret *joinResults) addUnmappedChild(m report.Node, id string, topology stri
|
||||
}
|
||||
result.Children.UnsafeAdd(m)
|
||||
if m.Topology != report.Endpoint { // optimisation: we never look at endpoint counts
|
||||
result.Counters = result.Counters.Add(m.Topology, 1)
|
||||
result = result.WithCounter(m.Topology, 1)
|
||||
}
|
||||
ret.nodes[id] = result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user