Skip to content

Commit

Permalink
remove filtering of unconnected pseudo nodes from ordinary filters
Browse files Browse the repository at this point in the history
It's now done via a special filter, once, after all other filters have
been applied.

Some tests need updating since they were relying on ordinary filters
doing that filtering.
  • Loading branch information
rade committed Nov 23, 2017
1 parent 7e59820 commit de22ef7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
10 changes: 8 additions & 2 deletions render/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ import (
)

var (
filterApplication = render.AnyFilterFunc(render.IsPseudoTopology, render.IsApplication)
filterSystem = render.AnyFilterFunc(render.IsPseudoTopology, render.IsSystem)
filterApplication = render.Transformers([]render.Transformer{
render.AnyFilterFunc(render.IsPseudoTopology, render.IsApplication),
render.FilterUnconnectedPseudo,
})
filterSystem = render.Transformers([]render.Transformer{
render.AnyFilterFunc(render.IsPseudoTopology, render.IsSystem),
render.FilterUnconnectedPseudo,
})
)

func TestMapProcess2Container(t *testing.T) {
Expand Down
15 changes: 0 additions & 15 deletions render/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,10 @@ func Complement(f FilterFunc) FilterFunc {
// Transform applies the filter to all nodes
func (f FilterFunc) Transform(nodes Nodes) Nodes {
output := report.Nodes{}
inDegrees := map[string]int{}
filtered := nodes.Filtered
for id, node := range nodes.Nodes {
if f(node) {
output[id] = node
inDegrees[id] = 0
} else {
filtered++
}
Expand All @@ -80,25 +78,12 @@ func (f FilterFunc) Transform(nodes Nodes) Nodes {
for _, dstID := range node.Adjacency {
if _, ok := output[dstID]; ok {
newAdjacency = newAdjacency.Add(dstID)
inDegrees[dstID]++
}
}
node.Adjacency = newAdjacency
output[id] = node
}

// Remove unconnected pseudo nodes, see #483.
for id, inDegree := range inDegrees {
if inDegree > 0 {
continue
}
node := output[id]
if node.Topology != Pseudo || len(node.Adjacency) > 0 {
continue
}
delete(output, id)
filtered++
}
return Nodes{Nodes: output, Filtered: filtered}
}

Expand Down
15 changes: 9 additions & 6 deletions render/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import (
"github.com/weaveworks/scope/test/reflect"
)

func isNotBar(node report.Node) bool {
return node.ID != "bar"
}
var isNotBar = render.Transformers([]render.Transformer{
render.FilterFunc(func(node report.Node) bool {
return node.ID != "bar"
}),
render.FilterUnconnectedPseudo,
})

func TestFilterRender(t *testing.T) {
renderer := mockRenderer{Nodes: report.Nodes{
Expand All @@ -36,7 +39,7 @@ func TestFilterRender2(t *testing.T) {
"bar": report.MakeNode("bar").WithAdjacent("foo"),
"baz": report.MakeNode("baz"),
}}
have := render.Render(report.MakeReport(), renderer, render.FilterFunc(isNotBar)).Nodes
have := render.Render(report.MakeReport(), renderer, isNotBar).Nodes
if have["foo"].Adjacency.Contains("bar") {
t.Error("adjacencies for removed nodes should have been removed")
}
Expand Down Expand Up @@ -64,7 +67,7 @@ func TestFilterUnconnectedPseudoNodes(t *testing.T) {
"bar": report.MakeNode("bar").WithAdjacent("baz"),
"baz": report.MakeNode("baz").WithTopology(render.Pseudo),
}}
have := render.Render(report.MakeReport(), renderer, render.FilterFunc(isNotBar)).Nodes
have := render.Render(report.MakeReport(), renderer, isNotBar).Nodes
if _, ok := have["baz"]; ok {
t.Error("expected the unconnected pseudonode baz to have been removed")
}
Expand All @@ -75,7 +78,7 @@ func TestFilterUnconnectedPseudoNodes(t *testing.T) {
"bar": report.MakeNode("bar").WithAdjacent("foo"),
"baz": report.MakeNode("baz").WithTopology(render.Pseudo).WithAdjacent("bar"),
}}
have := render.Render(report.MakeReport(), renderer, render.FilterFunc(isNotBar)).Nodes
have := render.Render(report.MakeReport(), renderer, isNotBar).Nodes
if _, ok := have["baz"]; ok {
t.Error("expected the unconnected pseudonode baz to have been removed")
}
Expand Down
5 changes: 4 additions & 1 deletion render/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ func TestPodRenderer(t *testing.T) {
}
}

var filterNonKubeSystem = render.Complement(render.IsNamespace("kube-system"))
var filterNonKubeSystem = render.Transformers([]render.Transformer{
render.Complement(render.IsNamespace("kube-system")),
render.FilterUnconnectedPseudo,
})

func TestPodFilterRenderer(t *testing.T) {
// tag on containers or pod namespace in the topology and ensure
Expand Down

0 comments on commit de22ef7

Please sign in to comment.