Files
weave-scope/render/metrics.go
Matthias Radestock 0c894e9446 refactor: drop networks from render.MapFunc
All the MapFuncs that needed networks have been elevated to Renderers.
2017-12-17 00:18:12 +00:00

25 lines
623 B
Go

package render
import (
"github.com/weaveworks/scope/report"
)
// PropagateSingleMetrics puts metrics from one of the children onto the parent
// iff there is only one child of that type.
func PropagateSingleMetrics(topology string) MapFunc {
return func(n report.Node) report.Nodes {
var found []report.Node
n.Children.ForEach(func(child report.Node) {
if child.Topology == topology {
if _, ok := child.Latest.Lookup(report.DoesNotMakeConnections); !ok {
found = append(found, child)
}
}
})
if len(found) == 1 {
n = n.WithMetrics(found[0].Metrics)
}
return report.Nodes{n.ID: n}
}
}