Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure k8s views are correctly hidden. #1241

Merged
merged 4 commits into from
Apr 7, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/app/scripts/utils/topology-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ export function setTopologyUrlsById(topologyUrlsById, topologies) {
}

export function filterHiddenTopologies(topologies) {
return topologies.filter(t => (!t.hidden_if_empty || t.stats.node_count > 0 ||
return topologies.filter(t => (!t.hide_if_empty || t.stats.node_count > 0 ||
t.stats.filtered_nodes > 0));
}
24 changes: 20 additions & 4 deletions render/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,26 @@ func ColorConnected(r Renderer) Renderer {
// Filter removes nodes from a view based on a predicate.
type Filter struct {
Renderer
FilterFunc func(report.Node) bool
FilterFunc func(report.Node) bool
ReportFiltered bool // false means we don't report stats for how many are filtered

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

}

// MakeFilter makes a new Filter.
func MakeFilter(f func(report.Node) bool, r Renderer) Renderer {
return Memoise(&Filter{r, f})
return Memoise(&Filter{
Renderer: r,
FilterFunc: f,
ReportFiltered: true,
})
}

// MakeSilentFilter makes a new Filter which does not report how many nodes it filters in Stats.
func MakeSilentFilter(f func(report.Node) bool, r Renderer) Renderer {
return Memoise(&Filter{
Renderer: r,
FilterFunc: f,
ReportFiltered: false,
})
}

// Render implements Renderer
Expand Down Expand Up @@ -115,9 +129,11 @@ func (f *Filter) render(rpt report.Report) (report.Nodes, int) {

// Stats implements Renderer
func (f Filter) Stats(rpt report.Report) Stats {
_, filtered := f.render(rpt)
var upstream = f.Renderer.Stats(rpt)
upstream.FilteredNodes += filtered
if f.ReportFiltered {
_, filtered := f.render(rpt)
upstream.FilteredNodes += filtered
}
return upstream
}

Expand Down
17 changes: 11 additions & 6 deletions render/topologies.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ var ProcessNameRenderer = MakeMap(
// but we need to be careful to ensure we only include each edge once, by only
// including the ProcessRenderer once.
var ContainerRenderer = MakeReduce(
MakeFilter(
MakeSilentFilter(
func(n report.Node) bool {
_, inContainer := n.Latest.Lookup(docker.ContainerID)
_, isConnected := n.Latest.Lookup(IsConnected)
return inContainer || isConnected
return n.Topology != Pseudo || isConnected
},
MakeMap(
MapProcess2Container,
Expand Down Expand Up @@ -224,9 +223,15 @@ var HostRenderer = MakeReduce(
// PodRenderer is a Renderer which produces a renderable kubernetes
// graph by merging the container graph and the pods topology.
var PodRenderer = MakeReduce(
MakeMap(
MapContainer2Pod,
ContainerRenderer,
MakeSilentFilter(
func(n report.Node) bool {
_, isConnected := n.Latest.Lookup(IsConnected)
return n.Topology != Pseudo || isConnected
},
MakeMap(
MapContainer2Pod,
ColorConnected(ContainerRenderer),
),

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

),
SelectPod,
)
Expand Down