mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 17:51:21 +00:00
AddParent() function to optimise the case where there is only one parent
Avoids creating and discarding a StringSet just to carry the parameters, and makes the code more readable too.
This commit is contained in:
@@ -407,9 +407,7 @@ func (c *container) getBaseNode() report.Node {
|
||||
ContainerCommand: c.getSanitizedCommand(),
|
||||
ImageID: c.Image(),
|
||||
ContainerHostname: c.Hostname(),
|
||||
}).WithParents(report.MakeSets().
|
||||
Add(report.ContainerImage, report.MakeStringSet(report.MakeContainerImageNodeID(c.Image()))),
|
||||
)
|
||||
}).WithParent(report.ContainerImage, report.MakeContainerImageNodeID(c.Image()))
|
||||
result = result.AddPrefixPropertyList(LabelPrefix, c.container.Config.Labels)
|
||||
if !c.noEnvironmentVariables {
|
||||
result = result.AddPrefixPropertyList(EnvPrefix, c.env())
|
||||
|
||||
@@ -74,7 +74,7 @@ func (t *Tagger) Tag(r report.Report) (report.Report, error) {
|
||||
})
|
||||
r.SwarmService.AddNode(node)
|
||||
|
||||
r.Container.Nodes[containerID] = container.WithParents(container.Parents.Add(report.SwarmService, report.MakeStringSet(nodeID)))
|
||||
r.Container.Nodes[containerID] = container.WithParent(report.SwarmService, nodeID)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
@@ -116,17 +116,13 @@ func (t *Tagger) tag(tree process.Tree, topology *report.Topology) {
|
||||
}
|
||||
|
||||
node = node.WithLatest(ContainerID, mtime.Now(), c.ID())
|
||||
node = node.WithParents(report.MakeSets().
|
||||
Add(report.Container, report.MakeStringSet(report.MakeContainerNodeID(c.ID()))),
|
||||
)
|
||||
node = node.WithParent(report.Container, report.MakeContainerNodeID(c.ID()))
|
||||
|
||||
// If we can work out the image name, add a parent tag for it
|
||||
image, ok := t.registry.GetContainerImage(c.Image())
|
||||
if ok && len(image.RepoTags) > 0 {
|
||||
imageName := ImageNameWithoutTag(image.RepoTags[0])
|
||||
node = node.WithParents(report.MakeSets().
|
||||
Add(report.ContainerImage, report.MakeStringSet(report.MakeContainerImageNodeID(imageName))),
|
||||
)
|
||||
node = node.WithParent(report.ContainerImage, report.MakeContainerImageNodeID(imageName))
|
||||
}
|
||||
|
||||
topology.ReplaceNode(node)
|
||||
|
||||
Reference in New Issue
Block a user