Skip to content

Commit

Permalink
Merge pull request weaveworks#730 from weaveworks/301-edge-metadata-c…
Browse files Browse the repository at this point in the history
…leanup

Cleaning up some dead code around edges and edgemetadata
  • Loading branch information
paulbellamy committed Dec 7, 2015
2 parents 036f786 + 9bd8181 commit 8db21fb
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 189 deletions.
19 changes: 0 additions & 19 deletions app/api_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/gorilla/websocket"

"github.com/weaveworks/scope/render"
"github.com/weaveworks/scope/report"
)

const (
Expand All @@ -26,11 +25,6 @@ type APINode struct {
Node render.DetailedNode `json:"node"`
}

// APIEdge is returned by the /api/topology/*/*/* handlers.
type APIEdge struct {
Metadata report.EdgeMetadata `json:"metadata"`
}

// Full topology.
func handleTopology(rep Reporter, renderer render.Renderer, w http.ResponseWriter, r *http.Request) {
respondWith(w, http.StatusOK, APITopology{
Expand Down Expand Up @@ -70,19 +64,6 @@ func handleNode(rep Reporter, renderer render.Renderer, w http.ResponseWriter, r
respondWith(w, http.StatusOK, APINode{Node: render.MakeDetailedNode(rpt, node)})
}

// Individual edges.
func handleEdge(rep Reporter, renderer render.Renderer, w http.ResponseWriter, r *http.Request) {
var (
vars = mux.Vars(r)
localID = vars["local"]
remoteID = vars["remote"]
rpt = rep.Report()
metadata = renderer.EdgeMetadata(rpt, localID, remoteID)
)

respondWith(w, http.StatusOK, APIEdge{Metadata: metadata})
}

var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true },
}
Expand Down
26 changes: 0 additions & 26 deletions app/api_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/weaveworks/scope/app"
"github.com/weaveworks/scope/render"
"github.com/weaveworks/scope/render/expected"
"github.com/weaveworks/scope/report"
"github.com/weaveworks/scope/test"
"github.com/weaveworks/scope/test/fixture"
)
Expand Down Expand Up @@ -88,19 +87,6 @@ func TestAPITopologyApplications(t *testing.T) {
equals(t, false, node.Node.Pseudo)
// Let's not unit-test the specific content of the detail tables
}
{
body := getRawJSON(t, ts, fmt.Sprintf("/api/topology/applications/%s/%s", expected.ClientProcess1ID, expected.ServerProcessID))
var edge app.APIEdge
if err := json.Unmarshal(body, &edge); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
if want, have := (report.EdgeMetadata{
EgressPacketCount: newu64(10),
EgressByteCount: newu64(100),
}), edge.Metadata; !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
}

func TestAPITopologyHosts(t *testing.T) {
Expand Down Expand Up @@ -130,18 +116,6 @@ func TestAPITopologyHosts(t *testing.T) {
equals(t, false, node.Node.Pseudo)
// Let's not unit-test the specific content of the detail tables
}
{
body := getRawJSON(t, ts, fmt.Sprintf("/api/topology/hosts/%s/%s", expected.ClientHostRenderedID, expected.ServerHostRenderedID))
var edge app.APIEdge
if err := json.Unmarshal(body, &edge); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
if want, have := (report.EdgeMetadata{
MaxConnCountTCP: newu64(3),
}), edge.Metadata; !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}
}

// Basic websocket test
Expand Down
2 changes: 0 additions & 2 deletions app/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ func RegisterTopologyRoutes(c Reporter, router *mux.Router) {
topologyRegistry.captureRenderer(c, handleWs)) // NB not gzip!
get.MatcherFunc(URLMatcher("/api/topology/{topology}/{id}")).HandlerFunc(
gzipHandler(topologyRegistry.captureRendererWithoutFilters(c, handleNode)))
get.MatcherFunc(URLMatcher("/api/topology/{topology}/{local}/{remote}")).HandlerFunc(
gzipHandler(topologyRegistry.captureRenderer(c, handleEdge)))
get.HandleFunc("/api/report", gzipHandler(makeRawReportHandler(c)))
}

Expand Down
43 changes: 0 additions & 43 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
// Renderer is something that can render a report to a set of RenderableNodes.
type Renderer interface {
Render(report.Report) RenderableNodes
EdgeMetadata(rpt report.Report, localID, remoteID string) report.EdgeMetadata
Stats(report.Report) Stats
}

Expand Down Expand Up @@ -40,15 +39,6 @@ func (r Reduce) Render(rpt report.Report) RenderableNodes {
return result
}

// EdgeMetadata produces an EdgeMetadata for a given edge.
func (r Reduce) EdgeMetadata(rpt report.Report, localID, remoteID string) report.EdgeMetadata {
metadata := report.EdgeMetadata{}
for _, renderer := range r {
metadata = metadata.Merge(renderer.EdgeMetadata(rpt, localID, remoteID))
}
return metadata
}

// Stats implements Renderer
func (r Reduce) Stats(rpt report.Report) Stats {
var result Stats
Expand Down Expand Up @@ -118,36 +108,3 @@ func (m Map) render(rpt report.Report) (RenderableNodes, map[string]report.IDLis

return output, mapped
}

// EdgeMetadata gives the metadata of an edge from the perspective of the
// srcRenderableID. Since an edgeID can have multiple edges on the address
// level, it uses the supplied mapping function to translate address IDs to
// renderable node (mapped) IDs.
func (m Map) EdgeMetadata(rpt report.Report, srcRenderableID, dstRenderableID string) report.EdgeMetadata {
// First we need to map the ids in this layer into the ids in the underlying layer
_, mapped := m.render(rpt) // this maps from old -> new
inverted := map[string][]string{} // this maps from new -> old(s)
for k, vs := range mapped {
for _, v := range vs {
existing := inverted[v]
existing = append(existing, k)
inverted[v] = existing
}
}

// Now work out a slice of edges this edge is constructed from
oldEdges := []struct{ src, dst string }{}
for _, oldSrcID := range inverted[srcRenderableID] {
for _, oldDstID := range inverted[dstRenderableID] {
oldEdges = append(oldEdges, struct{ src, dst string }{oldSrcID, oldDstID})
}
}

// Now recurse for each old edge
output := report.EdgeMetadata{}
for _, edge := range oldEdges {
metadata := m.Renderer.EdgeMetadata(rpt, edge.src, edge.dst)
output = output.Merge(metadata)
}
return output
}
83 changes: 0 additions & 83 deletions render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import (

type mockRenderer struct {
render.RenderableNodes
edgeMetadata report.EdgeMetadata
}

func (m mockRenderer) Render(rpt report.Report) render.RenderableNodes {
return m.RenderableNodes
}
func (m mockRenderer) EdgeMetadata(rpt report.Report, localID, remoteID string) report.EdgeMetadata {
return m.edgeMetadata
}
func (m mockRenderer) Stats(rpt report.Report) render.Stats {
return render.Stats{}
}
Expand All @@ -40,19 +36,6 @@ func TestReduceRender(t *testing.T) {
}
}

func TestReduceEdge(t *testing.T) {
renderer := render.Reduce([]render.Renderer{
mockRenderer{edgeMetadata: report.EdgeMetadata{EgressPacketCount: newu64(1)}},
mockRenderer{edgeMetadata: report.EdgeMetadata{EgressPacketCount: newu64(2)}},
})

want := report.EdgeMetadata{EgressPacketCount: newu64(3)}
have := renderer.EdgeMetadata(report.MakeReport(), "", "")
if !reflect.DeepEqual(want, have) {
t.Errorf("want %+v, have %+v", want, have)
}
}

func TestMapRender1(t *testing.T) {
// 1. Check when we return false, the node gets filtered out
mapper := render.Map{
Expand Down Expand Up @@ -114,70 +97,4 @@ func TestMapRender3(t *testing.T) {
}
}

func TestMapEdge(t *testing.T) {
selector := render.TopologySelector(func(_ report.Report) render.RenderableNodes {
return render.MakeRenderableNodes(report.Topology{
Nodes: report.Nodes{
"foo": report.MakeNode().WithMetadata(map[string]string{
"id": "foo",
}).WithEdge("bar", report.EdgeMetadata{
EgressPacketCount: newu64(1),
EgressByteCount: newu64(2),
}),

"bar": report.MakeNode().WithMetadata(map[string]string{
"id": "bar",
}).WithEdge("foo", report.EdgeMetadata{
EgressPacketCount: newu64(3),
EgressByteCount: newu64(4),
}),
},
})
})

mapper := render.Map{
MapFunc: func(node render.RenderableNode, _ report.Networks) render.RenderableNodes {
id := "_" + node.ID
return render.RenderableNodes{id: render.NewDerivedNode(id, node)}
},
Renderer: selector,
}

have := mapper.Render(report.MakeReport()).Prune()
want := (render.RenderableNodes{
"_foo": {
ID: "_foo",
Origins: report.MakeIDList("foo"),
Node: report.MakeNode().WithAdjacent("_bar"),
EdgeMetadata: report.EdgeMetadata{
EgressPacketCount: newu64(1),
EgressByteCount: newu64(2),
IngressPacketCount: newu64(3),
IngressByteCount: newu64(4),
},
},
"_bar": {
ID: "_bar",
Origins: report.MakeIDList("bar"),
Node: report.MakeNode().WithAdjacent("_foo"),
EdgeMetadata: report.EdgeMetadata{
EgressPacketCount: newu64(3),
EgressByteCount: newu64(4),
IngressPacketCount: newu64(1),
IngressByteCount: newu64(2),
},
},
}).Prune()
if !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}

if want, have := (report.EdgeMetadata{
EgressPacketCount: newu64(1),
EgressByteCount: newu64(2),
}), mapper.EdgeMetadata(report.MakeReport(), "_foo", "_bar"); !reflect.DeepEqual(want, have) {
t.Error(test.Diff(want, have))
}
}

func newu64(value uint64) *uint64 { return &value }
16 changes: 0 additions & 16 deletions render/selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@ func (t TopologySelector) Render(r report.Report) RenderableNodes {
return t(r)
}

// EdgeMetadata implements Renderer
func (t TopologySelector) EdgeMetadata(rpt report.Report, srcID, dstID string) report.EdgeMetadata {
var (
nodes = t(rpt)
metadata = report.EdgeMetadata{}
)
for src, node := range nodes {
for dst, edgeMeta := range node.Edges {
if src == srcID && dst == dstID {
return edgeMeta
}
}
}
return metadata
}

// Stats implements Renderer
func (t TopologySelector) Stats(r report.Report) Stats {
return Stats{}
Expand Down

0 comments on commit 8db21fb

Please sign in to comment.