mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
Fix node scoping rules
We only want to scope (i.e. prefix with hostID) those addresses that are deemed loopback, to disambiguate them. Otherwise, we want to leave addresses in unscoped form, so they can be matched, and links between communicating nodes properly made. So, we make the isLoopback check in MakeAddressID, and omit hostID if the address isn't loopback. So far so good. But this breaks topology rendering, as we were relying on extracting hostID from adjacency node IDs, to populate origin hosts in the rendered node output. So we need another way to get origin host from an arbitrary node. A survey revealed no reliable way to get that information from IDs in their new form. However, we have access to node metadata, so this changeset introduces the OriginHostTagger, which tags each node with its origin host, via the foreign-key semantics we'll use going forward.
This commit is contained in:
@@ -66,7 +66,13 @@ func main() {
|
||||
}
|
||||
defer publisher.Close()
|
||||
|
||||
taggers := []tag.Tagger{tag.NewTopologyTagger()}
|
||||
var (
|
||||
hostName = hostname()
|
||||
hostID = hostName // TODO: we should sanitize the hostname
|
||||
)
|
||||
|
||||
taggers := []tag.Tagger{tag.NewTopologyTagger(), tag.NewOriginHostTagger(hostID)}
|
||||
|
||||
var dockerTagger *tag.DockerTagger
|
||||
if *dockerEnabled && runtime.GOOS == linux {
|
||||
var err error
|
||||
@@ -84,11 +90,9 @@ func main() {
|
||||
defer close(quit)
|
||||
go func() {
|
||||
var (
|
||||
hostName = hostname()
|
||||
hostID = hostName // TODO: we should sanitize the hostname
|
||||
pubTick = time.Tick(*publishInterval)
|
||||
spyTick = time.Tick(*spyInterval)
|
||||
r = report.MakeReport()
|
||||
pubTick = time.Tick(*publishInterval)
|
||||
spyTick = time.Tick(*spyInterval)
|
||||
r = report.MakeReport()
|
||||
)
|
||||
|
||||
for {
|
||||
|
||||
29
probe/tag/origin_host_tagger.go
Normal file
29
probe/tag/origin_host_tagger.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package tag
|
||||
|
||||
import (
|
||||
"github.com/weaveworks/scope/report"
|
||||
)
|
||||
|
||||
type originHostTagger struct{ hostNodeID string }
|
||||
|
||||
// NewOriginHostTagger tags each node with a foreign key linking it to its
|
||||
// origin host in the host topology.
|
||||
func NewOriginHostTagger(hostID string) Tagger {
|
||||
return &originHostTagger{hostNodeID: report.MakeHostNodeID(hostID)}
|
||||
}
|
||||
|
||||
func (t originHostTagger) Tag(r report.Report) report.Report {
|
||||
for _, topology := range []*report.Topology{
|
||||
&(r.Endpoint),
|
||||
&(r.Address),
|
||||
&(r.Process),
|
||||
&(r.Container),
|
||||
&(r.Host),
|
||||
} {
|
||||
md := report.NodeMetadata{report.HostNodeID: t.hostNodeID}
|
||||
for nodeID := range topology.NodeMetadatas {
|
||||
(*topology).NodeMetadatas[nodeID].Merge(md)
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
25
probe/tag/origin_host_tagger_test.go
Normal file
25
probe/tag/origin_host_tagger_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package tag_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/weaveworks/scope/probe/tag"
|
||||
"github.com/weaveworks/scope/report"
|
||||
)
|
||||
|
||||
func TestOriginHostTagger(t *testing.T) {
|
||||
var (
|
||||
hostID = "foo"
|
||||
endpointNodeID = report.MakeEndpointNodeID(hostID, "1.2.3.4", "56789") // hostID ignored
|
||||
nodeMetadata = report.NodeMetadata{"foo": "bar"}
|
||||
)
|
||||
|
||||
r := report.MakeReport()
|
||||
r.Endpoint.NodeMetadatas[endpointNodeID] = nodeMetadata
|
||||
want := nodeMetadata.Merge(report.NodeMetadata{report.HostNodeID: report.MakeHostNodeID(hostID)})
|
||||
have := tag.NewOriginHostTagger(hostID).Tag(r).Endpoint.NodeMetadatas[endpointNodeID].Copy()
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Errorf("\nwant %+v\nhave %+v", want, have)
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,11 @@ func NewTopologyTagger() Tagger {
|
||||
|
||||
func (topologyTagger) Tag(r report.Report) report.Report {
|
||||
for val, topology := range map[string]*report.Topology{
|
||||
"endpoint": &(r.Endpoint),
|
||||
"address": &(r.Address),
|
||||
"endpoint": &(r.Endpoint),
|
||||
"address": &(r.Address),
|
||||
"process": &(r.Process),
|
||||
"container": &(r.Container),
|
||||
"host": &(r.Host),
|
||||
} {
|
||||
md := report.NodeMetadata{"topology": val}
|
||||
for nodeID := range topology.NodeMetadatas {
|
||||
|
||||
Reference in New Issue
Block a user