diff --git a/probe/endpoint/nat.go b/probe/endpoint/nat.go index b27343179a..2639c88fbe 100644 --- a/probe/endpoint/nat.go +++ b/probe/endpoint/nat.go @@ -149,7 +149,6 @@ func applyNAT(rpt report.Report, scope string) error { func conntrackModulePresent() bool { f, err := os.Open(modules) if err != nil { - //log.Printf("conntrack error: %v", err) // /proc doesn't exist on Darwin return false } defer f.Close() diff --git a/probe/main.go b/probe/main.go index 118f156a9e..999ea5c7b4 100644 --- a/probe/main.go +++ b/probe/main.go @@ -75,25 +75,13 @@ func main() { defer publisher.Close() var ( - hostName = hostname() - hostID = hostName // TODO: we should sanitize the hostname - ) - - var ( - weaveTagger *overlay.WeaveTagger + hostName = hostname() + hostID = hostName // TODO: we should sanitize the hostname + taggers = []Tagger{newTopologyTagger(), host.NewTagger(hostID)} + reporters = []Reporter{host.NewReporter(hostID, hostName), endpoint.NewReporter(hostID, hostName, *spyProcs)} processCache *process.CachingWalker ) - taggers := []Tagger{ - newTopologyTagger(), - host.NewTagger(hostID), - } - - reporters := []Reporter{ - host.NewReporter(hostID, hostName), - endpoint.NewReporter(hostID, hostName, *spyProcs), - } - // TODO provide an alternate implementation for Darwin. if runtime.GOOS == linux { processCache = process.NewCachingWalker(process.NewWalker(*procRoot)) @@ -116,12 +104,12 @@ func main() { } if *weaveRouterAddr != "" { - var err error - weaveTagger, err = overlay.NewWeaveTagger(*weaveRouterAddr) + weave, err := overlay.NewWeave(*weaveRouterAddr) if err != nil { log.Fatalf("failed to start Weave tagger: %v", err) } - taggers = append(taggers, weaveTagger) + taggers = append(taggers, weave) + reporters = append(reporters, weave) } log.Printf("listening on %s", *listen) @@ -157,10 +145,6 @@ func main() { r.Merge(newReport) } - if weaveTagger != nil { - r.Overlay.Merge(weaveTagger.OverlayTopology()) - } - r = Apply(r, taggers) case <-quit: diff --git a/probe/overlay/weave_tagger.go b/probe/overlay/weave.go similarity index 65% rename from probe/overlay/weave_tagger.go rename to probe/overlay/weave.go index ffd4f54dd5..2cd3d1dcae 100644 --- a/probe/overlay/weave_tagger.go +++ b/probe/overlay/weave.go @@ -21,39 +21,40 @@ const ( WeavePeerNickName = "weave_peer_nick_name" ) -// WeaveTagger represents a single Weave router, presumably on the same host -// as the probe. It can produce an Overlay topology, and in theory can tag -// existing topologies with foreign keys to overlay -- though I'm not sure -// what that would look like in practice right now. -type WeaveTagger struct { +// Weave represents a single Weave router, presumably on the same host +// as the probe. It is both a Reporter and a Tagger: it produces an Overlay +// topology, and (in theory) can tag existing topologies with foreign keys to +// overlay -- though I'm not sure what that would look like in practice right +// now. +type Weave struct { url string } -// NewWeaveTagger returns a new Weave tagger based on the Weave router at +// NewWeave returns a new Weave tagger based on the Weave router at // address. The address should be an IP or FQDN, no port. -func NewWeaveTagger(weaveRouterAddress string) (*WeaveTagger, error) { +func NewWeave(weaveRouterAddress string) (*Weave, error) { s, err := sanitize("http://", 6784, "/status-json")(weaveRouterAddress) if err != nil { return nil, err } - return &WeaveTagger{s}, nil + return &Weave{s}, nil } // Tag implements Tagger. -func (t WeaveTagger) Tag(r report.Report) (report.Report, error) { +func (w Weave) Tag(r report.Report) (report.Report, error) { // The status-json endpoint doesn't return any link information, so // there's nothing to tag, yet. return r, nil } -// OverlayTopology produces an overlay topology from the Weave router. -func (t WeaveTagger) OverlayTopology() report.Topology { - topology := report.NewTopology() +// Report implements Reporter. +func (w Weave) Report() (report.Report, error) { + r := report.MakeReport() - resp, err := http.Get(t.url) + resp, err := http.Get(w.url) if err != nil { log.Printf("Weave Tagger: %v", err) - return topology + return r, err } defer resp.Body.Close() @@ -65,17 +66,16 @@ func (t WeaveTagger) OverlayTopology() report.Topology { } if err := json.NewDecoder(resp.Body).Decode(&status); err != nil { log.Printf("Weave Tagger: %v", err) - return topology + return r, err } for _, peer := range status.Peers { - topology.NodeMetadatas[report.MakeOverlayNodeID(peer.Name)] = report.NodeMetadata{ + r.Overlay.NodeMetadatas[report.MakeOverlayNodeID(peer.Name)] = report.NodeMetadata{ WeavePeerName: peer.Name, WeavePeerNickName: peer.NickName, } } - - return topology + return r, nil } func sanitize(scheme string, port int, path string) func(string) (string, error) { diff --git a/probe/overlay/weave_tagger_test.go b/probe/overlay/weave_test.go similarity index 81% rename from probe/overlay/weave_tagger_test.go rename to probe/overlay/weave_test.go index b9eca48e1e..0872d26544 100644 --- a/probe/overlay/weave_tagger_test.go +++ b/probe/overlay/weave_test.go @@ -9,17 +9,22 @@ import ( "github.com/weaveworks/scope/probe/overlay" "github.com/weaveworks/scope/report" + "github.com/weaveworks/scope/test" ) func TestWeaveTaggerOverlayTopology(t *testing.T) { s := httptest.NewServer(http.HandlerFunc(mockWeaveRouter)) defer s.Close() - w, err := overlay.NewWeaveTagger(s.URL) + w, err := overlay.NewWeave(s.URL) if err != nil { t.Fatal(err) } + have, err := w.Report() + if err != nil { + t.Fatal(err) + } if want, have := (report.Topology{ Adjacency: report.Adjacency{}, EdgeMetadatas: report.EdgeMetadatas{}, @@ -29,8 +34,8 @@ func TestWeaveTaggerOverlayTopology(t *testing.T) { overlay.WeavePeerNickName: mockWeavePeerNickName, }, }, - }), w.OverlayTopology(); !reflect.DeepEqual(want, have) { - t.Errorf("want\n\t%#v, have\n\t%#v", want, have) + }), have.Overlay; !reflect.DeepEqual(want, have) { + t.Error(test.Diff(want, have)) } } @@ -46,6 +51,6 @@ func mockWeaveRouter(w http.ResponseWriter, r *http.Request) { "NickName": mockWeavePeerNickName, }}, }); err != nil { - println(err.Error()) + panic(err) } }