mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-16 03:49:52 +00:00
Propagate multiple container values at once
This is more efficient than repeatedly inserting a single value.
This commit is contained in:
@@ -143,11 +143,9 @@ func (r containerWithImageNameRenderer) Render(rpt report.Report) Nodes {
|
||||
imageNameWithoutTag := docker.ImageNameWithoutTag(imageName)
|
||||
imageNodeID := report.MakeContainerImageNodeID(imageNameWithoutTag)
|
||||
|
||||
c = propagateLatest(docker.ImageName, image, c)
|
||||
c = propagateLatest(docker.ImageTag, image, c)
|
||||
c = propagateLatest(docker.ImageSize, image, c)
|
||||
c = propagateLatest(docker.ImageVirtualSize, image, c)
|
||||
c = propagateLatest(docker.ImageLabelPrefix+"works.weave.role", image, c)
|
||||
c.Latest = c.Latest.Propagate(image.Latest, docker.ImageName, docker.ImageTag,
|
||||
docker.ImageSize, docker.ImageVirtualSize, docker.ImageLabelPrefix+"works.weave.role")
|
||||
|
||||
c.Parents = c.Parents.
|
||||
Delete(report.ContainerImage).
|
||||
Add(report.ContainerImage, report.MakeStringSet(imageNodeID))
|
||||
|
||||
@@ -115,13 +115,6 @@ func (m Map) Render(rpt report.Report) Nodes {
|
||||
return output.result(input)
|
||||
}
|
||||
|
||||
func propagateLatest(key string, from, to report.Node) report.Node {
|
||||
if value, timestamp, ok := from.Latest.LookupEntry(key); ok {
|
||||
to.Latest = to.Latest.Set(key, timestamp, value)
|
||||
}
|
||||
return to
|
||||
}
|
||||
|
||||
// Condition is a predecate over the entire report that can evaluate to true or false.
|
||||
type Condition func(report.Report) bool
|
||||
|
||||
|
||||
@@ -173,3 +173,16 @@ func (m StringLatestMap) addMapEntries(ts time.Time, n map[string]string) String
|
||||
out.fixup()
|
||||
return out
|
||||
}
|
||||
|
||||
// Propagate a set of latest values from one set to another.
|
||||
func (m StringLatestMap) Propagate(from StringLatestMap, keys ...string) StringLatestMap {
|
||||
out := make(StringLatestMap, len(m), len(m)+len(keys))
|
||||
copy(out, m)
|
||||
for _, k := range keys {
|
||||
if v, ts, ok := from.LookupEntry(k); ok {
|
||||
out = append(out, stringLatestEntry{key: k, Value: v, Timestamp: ts})
|
||||
}
|
||||
}
|
||||
out.fixup()
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user