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

remove unused memoisation #2924

Merged
merged 5 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions app/api_topologies.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ func (r *Registry) Add(ts ...APITopologyDesc) {
defer r.Unlock()
for _, t := range ts {
t.URL = apiTopologyURL + t.id
t.renderer = render.Memoise(t.renderer)

if t.parent != "" {
parent := r.items[t.parent]
Expand Down
14 changes: 8 additions & 6 deletions render/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var UncontainedIDPrefix = MakePseudoNodeID(UncontainedID)
// NB We only want processes in container _or_ processes with network connections
// but we need to be careful to ensure we only include each edge once, by only
// including the ProcessRenderer once.
var ContainerRenderer = MakeFilter(
var ContainerRenderer = Memoise(MakeFilter(
func(n report.Node) bool {
// Drop deleted containers
state, ok := n.Latest.Lookup(docker.ContainerState)
Expand All @@ -37,9 +37,9 @@ var ContainerRenderer = MakeFilter(
),
ConnectionJoin(MapContainer2IP, SelectContainer),
),
)
))

var mapEndpoint2IP = MakeMap(endpoint2IP, SelectEndpoint)
var mapEndpoint2IP = Memoise(MakeMap(endpoint2IP, SelectEndpoint))

const originalNodeID = "original_node_id"

Expand Down Expand Up @@ -182,11 +182,11 @@ func (r containerWithImageNameRenderer) Render(rpt report.Report, dct Decorator)

// ContainerWithImageNameRenderer is a Renderer which produces a container
// graph where the ranks are the image names, not their IDs
var ContainerWithImageNameRenderer = containerWithImageNameRenderer{ContainerRenderer}
var ContainerWithImageNameRenderer = Memoise(containerWithImageNameRenderer{ContainerRenderer})

// ContainerImageRenderer is a Renderer which produces a renderable container
// image graph by merging the container graph and the container image topology.
var ContainerImageRenderer = FilterEmpty(report.Container,
var ContainerImageRenderer = Memoise(FilterEmpty(report.Container,
MakeMap(
MapContainerImage2Name,
MakeReduce(
Expand All @@ -197,10 +197,12 @@ var ContainerImageRenderer = FilterEmpty(report.Container,
SelectContainerImage,
),
),
)
))

// ContainerHostnameRenderer is a Renderer which produces a renderable container
// by hostname graph..
//
// not memoised
var ContainerHostnameRenderer = FilterEmpty(report.Container,
MakeReduce(
MakeMap(
Expand Down
6 changes: 4 additions & 2 deletions render/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import (
)

// ECSTaskRenderer is a Renderer for Amazon ECS tasks.
var ECSTaskRenderer = ConditionalRenderer(renderECSTopologies,
var ECSTaskRenderer = Memoise(ConditionalRenderer(renderECSTopologies,
renderParents(
report.Container, []string{report.ECSTask}, UnmanagedID,
MakeFilter(
IsRunning,
ContainerWithImageNameRenderer,
),
),
)
))

// ECSServiceRenderer is a Renderer for Amazon ECS services.
//
// not memoised
var ECSServiceRenderer = ConditionalRenderer(renderECSTopologies,
renderParents(
report.ECSTask, []string{report.ECSService}, "",
Expand Down
8 changes: 4 additions & 4 deletions render/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ type Filter struct {

// MakeFilter makes a new Filter (that ignores pseudo nodes).
func MakeFilter(f FilterFunc, r Renderer) Renderer {
return Memoise(&Filter{
return &Filter{
Renderer: r,
FilterFunc: func(n report.Node) bool {
return n.Topology == Pseudo || f(n)
},
})
}
}

// MakeFilterPseudo makes a new Filter that will not ignore pseudo nodes.
func MakeFilterPseudo(f FilterFunc, r Renderer) Renderer {
return Memoise(&Filter{
return &Filter{
Renderer: r,
FilterFunc: f,
})
}
}

// MakeFilterDecorator makes a decorator that filters out non-pseudo nodes
Expand Down
2 changes: 2 additions & 0 deletions render/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

// HostRenderer is a Renderer which produces a renderable host
// graph from the host topology.
//
// not memoised
var HostRenderer = MakeReduce(
MakeMap(
MapEndpoint2Host,
Expand Down
12 changes: 9 additions & 3 deletions render/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func isPauseContainer(n report.Node) bool {

// PodRenderer is a Renderer which produces a renderable kubernetes
// graph by merging the container graph and the pods topology.
var PodRenderer = ConditionalRenderer(renderKubernetesTopologies,
var PodRenderer = Memoise(ConditionalRenderer(renderKubernetesTopologies,
MakeFilter(
func(n report.Node) bool {
state, ok := n.Latest.Lookup(kubernetes.State)
Expand All @@ -62,13 +62,17 @@ var PodRenderer = ConditionalRenderer(renderKubernetesTopologies,
),
),
),
ConnectionJoin(MapPod2IP, selectPodsWithDeployments{}),
// ConnectionJoin invokes the renderer twice, hence it
// helps to memoise it.
ConnectionJoin(MapPod2IP, Memoise(selectPodsWithDeployments{})),
),
),
)
))

// PodServiceRenderer is a Renderer which produces a renderable kubernetes services
// graph by merging the pods graph and the services topology.
//
// not memoised
var PodServiceRenderer = ConditionalRenderer(renderKubernetesTopologies,
renderParents(
report.Pod, []string{report.Service}, "",
Expand All @@ -80,6 +84,8 @@ var PodServiceRenderer = ConditionalRenderer(renderKubernetesTopologies,
// Pods with no controller are mapped to 'Unmanaged'
// We can't simply combine the rendered graphs of the high level objects as they would never
// have connections to each other.
//
// not memoised
var KubeControllerRenderer = ConditionalRenderer(renderKubernetesTopologies,
renderParents(
report.Pod, []string{report.Deployment, report.DaemonSet, report.StatefulSet, report.CronJob}, UnmanagedID,
Expand Down
10 changes: 7 additions & 3 deletions render/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ var EndpointRenderer = SelectEndpoint

// ProcessRenderer is a Renderer which produces a renderable process
// graph by merging the endpoint graph and the process topology.
var ProcessRenderer = ConditionalRenderer(renderProcesses,
var ProcessRenderer = Memoise(ConditionalRenderer(renderProcesses,
MakeReduce(
MakeMap(
MapEndpoint2Process,
EndpointRenderer,
),
SelectProcess,
),
)
))

// ColorConnectedProcessRenderer colors connected nodes from
// ProcessRenderer. Since the process topology views only show
// connected processes, we need this info to determine whether
// processes appearing in a details panel are linkable.
var ColorConnectedProcessRenderer = ColorConnected(ProcessRenderer)
var ColorConnectedProcessRenderer = Memoise(ColorConnected(ProcessRenderer))

// processWithContainerNameRenderer is a Renderer which produces a process
// graph enriched with container names where appropriate
Expand Down Expand Up @@ -74,10 +74,14 @@ func (r processWithContainerNameRenderer) Render(rpt report.Report, dct Decorato

// ProcessWithContainerNameRenderer is a Renderer which produces a process
// graph enriched with container names where appropriate
//
// not memoised
var ProcessWithContainerNameRenderer = processWithContainerNameRenderer{ProcessRenderer}

// ProcessNameRenderer is a Renderer which produces a renderable process
// name graph by munging the progess graph.
//
// not memoised
var ProcessNameRenderer = ConditionalRenderer(renderProcesses,
MakeMap(
MapProcess2Name,
Expand Down
17 changes: 8 additions & 9 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,18 @@ type Reduce []Renderer

// MakeReduce is the only sane way to produce a Reduce Renderer.
func MakeReduce(renderers ...Renderer) Renderer {
r := Reduce(renderers)
return Memoise(&r)
return Reduce(renderers)
}

// Render produces a set of Nodes given a Report.
func (r *Reduce) Render(rpt report.Report, dct Decorator) report.Nodes {
l := len(*r)
func (r Reduce) Render(rpt report.Report, dct Decorator) report.Nodes {
l := len(r)
switch l {
case 0:
return report.Nodes{}
}
c := make(chan report.Nodes, l)
for _, renderer := range *r {
for _, renderer := range r {
renderer := renderer // Pike!!
go func() {
c <- renderer.Render(rpt, dct)
Expand All @@ -61,9 +60,9 @@ func (r *Reduce) Render(rpt report.Report, dct Decorator) report.Nodes {
}

// Stats implements Renderer
func (r *Reduce) Stats(rpt report.Report, dct Decorator) Stats {
func (r Reduce) Stats(rpt report.Report, dct Decorator) Stats {
var result Stats
for _, renderer := range *r {
for _, renderer := range r {
result = result.merge(renderer.Stats(rpt, dct))
}
return result
Expand All @@ -78,7 +77,7 @@ type Map struct {

// MakeMap makes a new Map
func MakeMap(f MapFunc, r Renderer) Renderer {
return Memoise(&Map{f, r})
return &Map{f, r}
}

// Render transforms a set of Nodes produces by another Renderer.
Expand Down Expand Up @@ -180,7 +179,7 @@ type conditionalRenderer struct {
// ConditionalRenderer renders nothing if the condition is false, otherwise it defers
// to the wrapped Renderer.
func ConditionalRenderer(c Condition, r Renderer) Renderer {
return Memoise(conditionalRenderer{c, r})
return conditionalRenderer{c, r}
}

func (cr conditionalRenderer) Render(rpt report.Report, dct Decorator) report.Nodes {
Expand Down
2 changes: 2 additions & 0 deletions render/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
)

// SwarmServiceRenderer is a Renderer for Docker Swarm services
//
// not memoised
var SwarmServiceRenderer = ConditionalRenderer(renderSwarmTopologies,
renderParents(
report.Container, []string{report.SwarmService}, UnmanagedID,
Expand Down
2 changes: 2 additions & 0 deletions render/weave.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

// WeaveRenderer is a Renderer which produces a renderable weave topology.
//
// not memoised
var WeaveRenderer = MakeMap(
MapWeaveIdentity,
SelectOverlay,
Expand Down