mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-19 05:19:35 +00:00
Review feedback+test
This commit is contained in:
@@ -50,8 +50,10 @@ var (
|
||||
)
|
||||
|
||||
func TestReporter(t *testing.T) {
|
||||
var controlProbeID = "a1b2c3d4"
|
||||
|
||||
containerImageNodeID := report.MakeContainerImageNodeID("baz")
|
||||
rpt, err := docker.NewReporter(mockRegistryInstance, "host1", "probeID", nil).Report()
|
||||
rpt, err := docker.NewReporter(mockRegistryInstance, "host1", controlProbeID, nil).Report()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -65,9 +67,10 @@ func TestReporter(t *testing.T) {
|
||||
}
|
||||
|
||||
for k, want := range map[string]string{
|
||||
docker.ContainerID: "ping",
|
||||
docker.ContainerName: "pong",
|
||||
docker.ImageID: "baz",
|
||||
docker.ContainerID: "ping",
|
||||
docker.ContainerName: "pong",
|
||||
docker.ImageID: "baz",
|
||||
report.ControlProbeID: controlProbeID,
|
||||
} {
|
||||
if have, ok := node.Latest.Lookup(k); !ok || have != want {
|
||||
t.Errorf("Expected container %s latest %q: %q, got %q", containerNodeID, k, want, have)
|
||||
|
||||
@@ -9,15 +9,13 @@ import (
|
||||
// in every topology to an origin host node in the host topology.
|
||||
type Tagger struct {
|
||||
hostNodeID string
|
||||
probeID string
|
||||
}
|
||||
|
||||
// NewTagger tags each node with a foreign key linking it to its origin host
|
||||
// in the host topology.
|
||||
func NewTagger(hostID, probeID string) Tagger {
|
||||
func NewTagger(hostID string) Tagger {
|
||||
return Tagger{
|
||||
hostNodeID: report.MakeHostNodeID(hostID),
|
||||
probeID: probeID,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +25,8 @@ func (Tagger) Name() string { return "Host" }
|
||||
// Tag implements Tagger.
|
||||
func (t Tagger) Tag(r report.Report) (report.Report, error) {
|
||||
var (
|
||||
metadata = map[string]string{
|
||||
report.HostNodeID: t.hostNodeID,
|
||||
report.ProbeID: t.probeID,
|
||||
}
|
||||
parents = report.EmptySets.Add(report.Host, report.MakeStringSet(t.hostNodeID))
|
||||
metadata = map[string]string{report.HostNodeID: t.hostNodeID}
|
||||
parents = report.EmptySets.Add(report.Host, report.MakeStringSet(t.hostNodeID))
|
||||
)
|
||||
|
||||
// Explicity don't tag Endpoints and Addresses - These topologies include pseudo nodes,
|
||||
|
||||
@@ -10,14 +10,13 @@ import (
|
||||
func TestTagger(t *testing.T) {
|
||||
var (
|
||||
hostID = "foo"
|
||||
probeID = "a1b2c3d4"
|
||||
endpointNodeID = report.MakeEndpointNodeID(hostID, "1.2.3.4", "56789") // hostID ignored
|
||||
node = report.MakeNodeWith(map[string]string{"foo": "bar"})
|
||||
)
|
||||
|
||||
r := report.MakeReport()
|
||||
r.Process.AddNode(endpointNodeID, node)
|
||||
rpt, _ := host.NewTagger(hostID, probeID).Tag(r)
|
||||
rpt, _ := host.NewTagger(hostID).Tag(r)
|
||||
have := rpt.Process.Nodes[endpointNodeID].Copy()
|
||||
|
||||
// It should now have the host ID
|
||||
@@ -26,11 +25,6 @@ func TestTagger(t *testing.T) {
|
||||
t.Errorf("Expected %q got %q", wantHostID, report.MakeHostNodeID(hostID))
|
||||
}
|
||||
|
||||
// It should now have the probe ID
|
||||
if haveProbeID, ok := have.Latest.Lookup(report.ProbeID); !ok || haveProbeID != probeID {
|
||||
t.Errorf("Expected %q got %q", probeID, haveProbeID)
|
||||
}
|
||||
|
||||
// It should still have the other keys
|
||||
want := "bar"
|
||||
if have, ok := have.Latest.Lookup("foo"); !ok || have != want {
|
||||
|
||||
@@ -146,7 +146,7 @@ func probeMain() {
|
||||
host.NewReporter(hostID, hostName),
|
||||
process.NewReporter(processCache, hostID, process.GetDeltaTotalJiffies),
|
||||
)
|
||||
p.AddTagger(probe.NewTopologyTagger(), host.NewTagger(hostID, probeID))
|
||||
p.AddTagger(probe.NewTopologyTagger(), host.NewTagger(hostID))
|
||||
|
||||
if *dockerEnabled {
|
||||
if err := report.AddLocalBridge(*dockerBridge); err != nil {
|
||||
|
||||
@@ -207,8 +207,6 @@ const (
|
||||
// a node in the host topology. That host node is the origin host, where
|
||||
// the node was originally detected.
|
||||
HostNodeID = "host_node_id"
|
||||
// ProbeID is the random ID of the probe which generated the specific node.
|
||||
ProbeID = "probe_id"
|
||||
// ControlProbeID is the random ID of the probe which controls the specific node.
|
||||
ControlProbeID = "control_probe_id"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user