ensure hostNodeIDs actually are what they claim

It's a dynamic type check of sorts.

In the process we stop abusing ParseNodeID for extracting the host,
which in turn allows us to clarify its purpose.
This commit is contained in:
Matthias Radestock
2017-12-21 15:55:55 +00:00
parent a8e3d04d21
commit ceb3539d35
2 changed files with 5 additions and 6 deletions

View File

@@ -103,7 +103,7 @@ func (e endpoints2Processes) Render(rpt report.Report) Nodes {
continue
}
hostID, _, _ := report.ParseNodeID(hostNodeID)
hostID, _ := report.ParseHostNodeID(hostNodeID)
id := report.MakeProcessNodeID(hostID, pid)
ret.addChild(n, id, func(id string) report.Node {
// we have a pid, but no matching process node;

View File

@@ -197,7 +197,7 @@ func ParseOverlayNodeID(id string) (overlayPrefix string, peerName string) {
return WeaveOverlayPeerPrefix, id
}
// Split a string s into to parts separated by sep.
// Split a string s into two parts separated by sep.
func split2(s, sep string) (s1, s2 string, ok bool) {
// Not using strings.SplitN() to avoid a heap allocation
pos := strings.Index(s, sep)
@@ -207,9 +207,8 @@ func split2(s, sep string) (s1, s2 string, ok bool) {
return s[:pos], s[pos+1:], true
}
// ParseNodeID produces the host ID and remainder (typically an address) from
// a node ID. Note that hostID may be blank.
func ParseNodeID(nodeID string) (hostID string, remainder string, ok bool) {
// ParseNodeID produces the id and tag of a single-component node ID.
func ParseNodeID(nodeID string) (id string, tag string, ok bool) {
return split2(nodeID, ScopeDelim)
}
@@ -250,7 +249,7 @@ func ParseECSServiceNodeID(ecsServiceNodeID string) (cluster, serviceName string
// ExtractHostID extracts the host id from Node
func ExtractHostID(m Node) string {
hostNodeID, _ := m.Latest.Lookup(HostNodeID)
hostID, _, _ := ParseNodeID(hostNodeID)
hostID, _ := ParseHostNodeID(hostNodeID)
return hostID
}