From ceb3539d356bdc9710e3f5c3a58e3c8b73d343ba Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 21 Dec 2017 15:55:55 +0000 Subject: [PATCH] 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. --- render/process.go | 2 +- report/id.go | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/render/process.go b/render/process.go index f1ca648e2..3d84792fa 100644 --- a/render/process.go +++ b/render/process.go @@ -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; diff --git a/report/id.go b/report/id.go index f0d3dec9b..9727b1341 100644 --- a/report/id.go +++ b/report/id.go @@ -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 }