Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add topology.ReplaceNode() for efficiency #3073

Merged
merged 2 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion probe/host/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (t Tagger) Tag(r report.Report) (report.Report, error) {
// and as such do their own host tagging.
for _, topology := range []report.Topology{r.Process, r.Container, r.ContainerImage, r.Host, r.Pod} {
for _, node := range topology.Nodes {
topology.AddNode(node.WithLatests(metadata).WithParents(parents))
topology.ReplaceNode(node.WithLatests(metadata).WithParents(parents))
}
}
return r, nil
Expand Down
2 changes: 1 addition & 1 deletion probe/topology_tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (topologyTagger) Name() string { return "Topology" }
func (topologyTagger) Tag(r report.Report) (report.Report, error) {
r.WalkNamedTopologies(func(name string, t *report.Topology) {
for _, node := range t.Nodes {
t.AddNode(node.WithTopology(name))
t.ReplaceNode(node.WithTopology(name))
}
})
return r, nil
Expand Down
7 changes: 7 additions & 0 deletions report/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ func (t Topology) AddNode(node Node) Topology {
return t
}

// ReplaceNode adds node to the topology under key nodeID; if a
// node already exists for this key, node replaces that node.
// Like AddNode, it mutates the Topology
func (t Topology) ReplaceNode(node Node) {
t.Nodes[node.ID] = node
}

// GetShape returns the current topology shape, or the default if there isn't one.
func (t Topology) GetShape() string {
if t.Shape == "" {
Expand Down