mirror of
https://github.com/weaveworks/scope.git
synced 2026-02-14 18:09:59 +00:00
Add method to add a single string into Sets
This avoids creating and discarding a StringSet just to pass the parameter
This commit is contained in:
@@ -182,10 +182,10 @@ func (r Reporter) Tag(rpt report.Report) (report.Report, error) {
|
||||
|
||||
// parents sets to merge into all matching container nodes
|
||||
parentsSets := report.MakeSets()
|
||||
parentsSets = parentsSets.Add(report.ECSTask, report.MakeStringSet(taskID))
|
||||
parentsSets = parentsSets.AddString(report.ECSTask, taskID)
|
||||
if serviceName, ok := ecsInfo.TaskServiceMap[taskArn]; ok {
|
||||
serviceID := report.MakeECSServiceNodeID(cluster, serviceName)
|
||||
parentsSets = parentsSets.Add(report.ECSService, report.MakeStringSet(serviceID))
|
||||
parentsSets = parentsSets.AddString(report.ECSService, serviceID)
|
||||
// in addition, make service parent of task
|
||||
rpt.ECSTask.Nodes[taskID] = rpt.ECSTask.Nodes[taskID].WithParents(report.MakeSets().Add(report.ECSService, report.MakeStringSet(serviceID)))
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (p *pod) UID() string {
|
||||
}
|
||||
|
||||
func (p *pod) AddParent(topology, id string) {
|
||||
p.parents = p.parents.Add(topology, report.MakeStringSet(id))
|
||||
p.parents = p.parents.AddString(topology, id)
|
||||
}
|
||||
|
||||
func (p *pod) State() string {
|
||||
|
||||
@@ -357,7 +357,7 @@ func (r *Reporter) hostTopology(services []Service) report.Topology {
|
||||
t := report.MakeTopology()
|
||||
t.AddNode(
|
||||
report.MakeNode(report.MakeHostNodeID(r.hostID)).
|
||||
WithSets(report.MakeSets().Add(host.LocalNetworks, report.MakeStringSet(serviceNetwork.String()))))
|
||||
WithSets(report.MakeSets().AddString(host.LocalNetworks, serviceNetwork.String())))
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ func (r containerWithImageNameRenderer) Render(rpt report.Report) Nodes {
|
||||
c = propagateLatest(docker.ImageLabelPrefix+"works.weave.role", image, c)
|
||||
c.Parents = c.Parents.
|
||||
Delete(report.ContainerImage).
|
||||
Add(report.ContainerImage, report.MakeStringSet(imageNodeID))
|
||||
AddString(report.ContainerImage, imageNodeID)
|
||||
outputs[id] = c
|
||||
}
|
||||
return Nodes{Nodes: outputs, Filtered: containers.Filtered}
|
||||
|
||||
@@ -46,6 +46,21 @@ func (s Sets) Add(key string, value StringSet) Sets {
|
||||
}
|
||||
}
|
||||
|
||||
// AddString adds a single string under a key, creating a new StringSet if necessary.
|
||||
func (s Sets) AddString(key string, str string) Sets {
|
||||
if s.psMap == nil {
|
||||
s = emptySets
|
||||
}
|
||||
value, found := s.Lookup(key)
|
||||
if found && value.Contains(str) {
|
||||
return s
|
||||
}
|
||||
value = value.Add(str)
|
||||
return Sets{
|
||||
psMap: s.psMap.Set(key, value),
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the given set from the Sets.
|
||||
func (s Sets) Delete(key string) Sets {
|
||||
if s.psMap == nil {
|
||||
|
||||
Reference in New Issue
Block a user