mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-22 06:46:50 +00:00
optimization: generate children counts on demand
Accumulating counts in the Node data structure takes a lot of effort, and it turns out we only use this information in a few places where it's easy to compute.
This commit is contained in:
@@ -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.LookupCounter(n.Topology); !ok {
|
||||
if n.CountChildrenOfTopology(n.Topology) == 0 {
|
||||
if topology, ok := rc.Topology(n.Topology); ok {
|
||||
summary.Metadata = topology.MetadataTemplates.MetadataRows(n)
|
||||
summary.Metrics = topology.MetricTemplates.MetricRows(n)
|
||||
@@ -432,9 +432,10 @@ func groupNodeSummary(base BasicNodeSummary, r report.Report, n report.Node) Bas
|
||||
}
|
||||
|
||||
func pluralize(n report.Node, key, singular, plural string) string {
|
||||
// either fetch a stored counter, or count the children directly
|
||||
c, ok := n.LookupCounter(key)
|
||||
if !ok {
|
||||
c = 0
|
||||
c = n.CountChildrenOfTopology(key)
|
||||
}
|
||||
if c == 1 {
|
||||
return fmt.Sprintf("%d %s", c, singular)
|
||||
|
||||
@@ -113,7 +113,6 @@ var (
|
||||
RenderedProcessNames = report.Nodes{
|
||||
fixture.Client1Name: processNameNode(fixture.Client1Name, fixture.ServerName).
|
||||
WithLatests(map[string]string{process.Name: fixture.Client1Name}).
|
||||
AddCounter(report.Process, 2).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Client54001NodeID,
|
||||
fixture.Client54002NodeID,
|
||||
@@ -123,14 +122,12 @@ var (
|
||||
|
||||
fixture.ServerName: processNameNode(fixture.ServerName).
|
||||
WithLatests(map[string]string{process.Name: fixture.ServerName}).
|
||||
AddCounter(report.Process, 1).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Server80NodeID,
|
||||
fixture.ServerProcessNodeID,
|
||||
)),
|
||||
|
||||
fixture.NonContainerName: processNameNode(fixture.NonContainerName, render.OutgoingInternetID).
|
||||
AddCounter(report.Process, 1).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.NonContainerNodeID,
|
||||
fixture.NonContainerProcessNodeID,
|
||||
@@ -183,7 +180,6 @@ var (
|
||||
WithLatests(map[string]string{
|
||||
docker.ContainerHostname: fixture.ClientContainerHostname,
|
||||
}).
|
||||
AddCounter(report.Container, 1).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Client54001NodeID,
|
||||
fixture.Client54002NodeID,
|
||||
@@ -196,7 +192,6 @@ var (
|
||||
WithLatests(map[string]string{
|
||||
docker.ContainerHostname: fixture.ServerContainerHostname,
|
||||
}).
|
||||
AddCounter(report.Container, 2).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Server80NodeID,
|
||||
fixture.ServerProcessNodeID,
|
||||
@@ -219,7 +214,6 @@ var (
|
||||
docker.ImageID: fixture.ClientContainerImageID,
|
||||
docker.ImageName: fixture.ClientContainerImageName,
|
||||
}).
|
||||
AddCounter(report.Container, 1).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Client54001NodeID,
|
||||
fixture.Client54002NodeID,
|
||||
@@ -229,7 +223,6 @@ var (
|
||||
)),
|
||||
|
||||
ServerContainerImageNodeID: containerImage(ServerContainerImageNodeID).
|
||||
AddCounter(report.Container, 2).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Server80NodeID,
|
||||
fixture.ServerProcessNodeID,
|
||||
@@ -248,13 +241,10 @@ var (
|
||||
fixture.NonContainerNodeID,
|
||||
fixture.NonContainerProcessNodeID,
|
||||
fixture.ServerContainer2NodeID,
|
||||
)).
|
||||
AddCounter(report.Container, 1).
|
||||
AddCounter(render.Pseudo, 1)
|
||||
))
|
||||
|
||||
RenderedPods = report.Nodes{
|
||||
fixture.ClientPodNodeID: pod(fixture.ClientPodNodeID, fixture.ServerPodNodeID).
|
||||
AddCounter(report.Container, 1).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Client54001NodeID,
|
||||
fixture.Client54002NodeID,
|
||||
@@ -264,7 +254,6 @@ var (
|
||||
)),
|
||||
|
||||
fixture.ServerPodNodeID: pod(fixture.ServerPodNodeID).
|
||||
AddCounter(report.Container, 1).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Server80NodeID,
|
||||
fixture.ServerProcessNodeID,
|
||||
@@ -321,7 +310,6 @@ var (
|
||||
|
||||
RenderedPodServices = report.Nodes{
|
||||
fixture.ServiceNodeID: service(fixture.ServiceNodeID, fixture.ServiceNodeID).
|
||||
AddCounter(report.Pod, 2).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Client54001NodeID,
|
||||
fixture.Client54002NodeID,
|
||||
@@ -345,10 +333,6 @@ var (
|
||||
WithLatests(map[string]string{
|
||||
report.HostName: fixture.ClientHostName,
|
||||
}).
|
||||
AddCounter(report.Container, 1).
|
||||
AddCounter(report.ContainerImage, 1).
|
||||
AddCounter(report.Pod, 1).
|
||||
AddCounter(report.Process, 2).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Client54001NodeID,
|
||||
fixture.Client54002NodeID,
|
||||
@@ -360,10 +344,6 @@ var (
|
||||
)),
|
||||
|
||||
fixture.ServerHostNodeID: hostNode(fixture.ServerHostNodeID, render.OutgoingInternetID).
|
||||
AddCounter(report.Container, 2).
|
||||
AddCounter(report.ContainerImage, 1).
|
||||
AddCounter(report.Pod, 1).
|
||||
AddCounter(report.Process, 2).
|
||||
WithChildren(report.MakeIDList(
|
||||
fixture.Server80NodeID,
|
||||
fixture.NonContainerNodeID,
|
||||
|
||||
@@ -193,9 +193,6 @@ func (ret *joinResults) addUnmappedChild(m report.Node, id string, topology stri
|
||||
result = report.MakeNode(id).WithTopology(topology)
|
||||
}
|
||||
result = result.WithChildID(m.ID)
|
||||
if m.Topology != report.Endpoint { // optimisation: we never look at endpoint counts
|
||||
result = result.AddCounter(m.Topology, 1)
|
||||
}
|
||||
ret.nodes[id] = result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user