Skip to content

Commit

Permalink
Review feedback+test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfonso Acosta committed Feb 26, 2016
1 parent a559a23 commit b33c516
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
11 changes: 7 additions & 4 deletions probe/docker/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions probe/host/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions probe/host/tagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion prog/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit b33c516

Please sign in to comment.