Switch to LatestMap-style node controls

This allows plugins to add controls to nodes that already have some
controls set by other plugin. Previously only the last plugin that
sets the controls in the node would have its controls visible. That
was because of NodeControls' Merge function that actually weren't
merging data from two inputs, but rather returning data that was newer
and discarding the older one.
This commit is contained in:
Krzesimir Nowak
2016-07-22 14:34:18 +02:00
parent 5fdb8a5362
commit 9e092f1a4a
12 changed files with 179 additions and 91 deletions

View File

@@ -2,6 +2,7 @@ package detailed
import (
"sort"
"time"
"github.com/ugorji/go/codec"
@@ -98,20 +99,22 @@ func controlsFor(topology report.Topology, nodeID string) []ControlInstance {
if !ok {
return result
}
for _, id := range node.Controls.Controls {
if control, ok := topology.Controls[id]; ok {
probeID, ok := node.Latest.Lookup(report.ControlProbeID)
if !ok {
continue
}
probeID, ok := node.Latest.Lookup(report.ControlProbeID)
if !ok {
return result
}
node.LatestControls.ForEach(func(controlID string, _ time.Time, data report.NodeControlData) {
if data.Dead {
return
}
if control, ok := topology.Controls[controlID]; ok {
result = append(result, ControlInstance{
ProbeID: probeID,
NodeID: nodeID,
Control: control,
})
}
}
})
return result
}