render

package
v1.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2020 License: Apache-2.0 Imports: 15 Imported by: 42

Documentation

Index

Constants

View Source
const (
	UncontainedID    = "uncontained"
	UncontainedMajor = "Uncontained"

	// Topology for IPs so we can differentiate them at the end
	IP = "IP"
)

Constants are used in the tests.

View Source
const (
	IncomingInternetID = "in-theinternet"
	OutgoingInternetID = "out-theinternet"
)

Constants are used in the tests.

View Source
const (
	UnmanagedID    = "unmanaged"
	UnmanagedMajor = "Unmanaged"
)

Constants are used in the tests.

View Source
const (
	InboundMajor  = "The Internet"
	OutboundMajor = "The Internet"
	InboundMinor  = "Inbound connections"
	OutboundMinor = "Outbound connections"
)

Constants are used in the tests.

View Source
const IsConnectedMark = "is_connected"

IsConnectedMark is the key added to Node.Metadata by ColorConnected to indicate a node has an edge pointing to it or from it

View Source
const Pseudo = "pseudo"

Pseudo is the topology for nodes that aren't "real" nodes inside a cluster, such as nodes representing the internet, external services, and artificial grouping such as "uncontained processes" and "unmanaged containers".

Variables

View Source
var (
	SelectEndpoint              = TopologySelector(report.Endpoint)
	SelectProcess               = TopologySelector(report.Process)
	SelectContainer             = TopologySelector(report.Container)
	SelectContainerImage        = TopologySelector(report.ContainerImage)
	SelectHost                  = TopologySelector(report.Host)
	SelectPod                   = TopologySelector(report.Pod)
	SelectService               = TopologySelector(report.Service)
	SelectDeployment            = TopologySelector(report.Deployment)
	SelectDaemonSet             = TopologySelector(report.DaemonSet)
	SelectStatefulSet           = TopologySelector(report.StatefulSet)
	SelectCronJob               = TopologySelector(report.CronJob)
	SelectJob                   = TopologySelector(report.Job)
	SelectECSTask               = TopologySelector(report.ECSTask)
	SelectECSService            = TopologySelector(report.ECSService)
	SelectSwarmService          = TopologySelector(report.SwarmService)
	SelectOverlay               = TopologySelector(report.Overlay)
	SelectPersistentVolume      = TopologySelector(report.PersistentVolume)
	SelectPersistentVolumeClaim = TopologySelector(report.PersistentVolumeClaim)
	SelectStorageClass          = TopologySelector(report.StorageClass)
	SelectVolumeSnapshot        = TopologySelector(report.VolumeSnapshot)
	SelectVolumeSnapshotData    = TopologySelector(report.VolumeSnapshotData)
)

The topology selectors implement a Renderer which fetch the nodes from the various report topologies.

View Source
var ConnectedProcessRenderer = ColorConnected(ProcessRenderer)

ConnectedProcessRenderer is a Renderer which colors connected nodes, so we can apply a filter to show/hide unconnected nodes depending on user choice.

not memoised

View Source
var ContainerHostnameRenderer = FilterEmpty(report.Container,
	containerHostnameRenderer{},
)

ContainerHostnameRenderer is a Renderer which produces a renderable container by hostname graph..

not memoised

View Source
var ContainerImageRenderer = Memoise(FilterEmpty(report.Container,
	MakeMap(
		MapContainerImage2Name,
		containerImageRenderer{},
	),
))

ContainerImageRenderer produces a graph where each node is a container image with the original containers as children

View Source
var ContainerRenderer = Memoise(MakeFilter(
	func(n report.Node) bool {

		state, ok := n.Latest.Lookup(report.DockerContainerState)
		return !ok || state != report.StateDeleted
	},
	MakeReduce(
		MakeMap(
			MapProcess2Container,
			ProcessRenderer,
		),
		ConnectionJoin(MapContainer2IP, report.Container),
	),
))

ContainerRenderer is a Renderer which produces a renderable container graph by merging the process graph and the container topology. 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.

View Source
var ContainerWithImageNameRenderer = Memoise(containerWithImageNameRenderer{})

ContainerWithImageNameRenderer is a Renderer which produces a container graph where the ranks are the image names, not their IDs

View Source
var ECSServiceRenderer = ConditionalRenderer(renderECSTopologies,
	renderParents(
		report.ECSTask, []string{report.ECSService}, "",
		ECSTaskRenderer,
	),
)

ECSServiceRenderer is a Renderer for Amazon ECS services.

not memoised

View Source
var ECSTaskRenderer = Memoise(ConditionalRenderer(renderECSTopologies,
	renderParents(
		report.Container, []string{report.ECSTask}, UnmanagedID,
		MakeFilter(
			IsRunning,
			ContainerWithImageNameRenderer,
		),
	),
))

ECSTaskRenderer is a Renderer for Amazon ECS tasks.

View Source
var EndpointRenderer = SelectEndpoint

EndpointRenderer is a Renderer which produces a renderable endpoint graph.

View Source
var FilterUnconnected = filterUnconnected{/* contains filtered or unexported fields */}

FilterUnconnected is a transformer that filters unconnected nodes

View Source
var FilterUnconnectedPseudo = filterUnconnected{/* contains filtered or unexported fields */}

FilterUnconnectedPseudo is a transformer that filters unconnected pseudo nodes

View Source
var HostRenderer = MakeReduce(
	CustomRenderer{RenderFunc: nodes2Hosts, Renderer: ProcessRenderer},
	CustomRenderer{RenderFunc: nodes2Hosts, Renderer: ContainerRenderer},
	CustomRenderer{RenderFunc: nodes2Hosts, Renderer: ContainerImageRenderer},
	CustomRenderer{RenderFunc: nodes2Hosts, Renderer: PodRenderer},
	MapEndpoints(endpoint2Host, report.Host),
)

HostRenderer is a Renderer which produces a renderable host graph from the host topology.

not memoised

View Source
var IsPseudoTopology = IsTopology(Pseudo)

IsPseudoTopology returns true if the node is in a pseudo topology, mimicing the check performed by MakeFilter() instead of the more complex check in IsNotPseudo()

View Source
var IsStopped = Complement(IsRunning)

IsStopped checks if the node is *not* a running docker container

IsSystem checks if the node is a "system" node

View Source
var KubeControllerRenderer = ConditionalRenderer(renderKubernetesTopologies,
	renderParents(
		report.Pod, []string{report.Deployment, report.DaemonSet, report.StatefulSet, report.CronJob, report.Job}, UnmanagedID,
		PodRenderer,
	),
)

KubeControllerRenderer is a Renderer which combines all the 'controller' topologies. 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

KubernetesVolumesRenderer is a Renderer which combines all Kubernetes volumes components such as stateful Pods, Persistent Volume, Persistent Volume Claim, Storage Class.

View Source
var PVCToStorageClassRenderer = pvcToStorageClassRenderer{}

PVCToStorageClassRenderer is a Renderer which produces a renderable kubernetes PVC & Storage class graph.

View Source
var PVToSnapshotRenderer = pvToSnapshotRenderer{}

PVToSnapshotRenderer is a Renderer which produces a renderable kubernetes PV

View Source
var PodRenderer = Memoise(ConditionalRenderer(renderKubernetesTopologies,
	MakeFilter(
		func(n report.Node) bool {
			state, ok := n.Latest.Lookup(report.KubernetesState)
			return !ok || !(state == report.StateDeleted || state == report.StateFailed)
		},
		MakeReduce(
			PropagateSingleMetrics(report.Container,
				MakeMap(propagatePodHost,
					Map2Parent{topologies: []string{report.Pod}, noParentsPseudoID: UnmanagedID,
						chainRenderer: MakeFilter(
							ComposeFilterFuncs(
								IsRunning,
								Complement(isPauseContainer),
							),
							ContainerWithImageNameRenderer,
						)},
				),
			),
			ConnectionJoin(MapPod2IP, report.Pod),
			KubernetesVolumesRenderer,
		),
	),
))

PodRenderer is a Renderer which produces a renderable kubernetes graph by merging the container graph and the pods topology.

View Source
var PodServiceRenderer = ConditionalRenderer(renderKubernetesTopologies,
	renderParents(
		report.Pod, []string{report.Service}, "",
		PodRenderer,
	),
)

PodServiceRenderer is a Renderer which produces a renderable kubernetes services graph by merging the pods graph and the services topology.

not memoised

View Source
var PodToVolumeRenderer = podToVolumesRenderer{}

PodToVolumeRenderer is a Renderer which produces a renderable kubernetes Pod graph by merging the pods graph and the Persistent Volume Claim topology. Pods having persistent volumes are rendered.

View Source
var ProcessNameRenderer = ColorConnected(CustomRenderer{RenderFunc: processes2Names, Renderer: ProcessRenderer})

ProcessNameRenderer is a Renderer which produces a renderable process name graph by munging the progess graph.

It also colors connected nodes, so we can apply a filter to show/hide unconnected nodes depending on user choice.

not memoised

View Source
var ProcessRenderer = Memoise(endpoints2Processes{})

ProcessRenderer is a Renderer which produces a renderable process graph by merging the endpoint graph and the process topology.

View Source
var (
	// ServiceNodeIDPrefix is how the ID of all service pseudo nodes begin
	ServiceNodeIDPrefix = "service-"
)
View Source
var SwarmServiceRenderer = ConditionalRenderer(renderSwarmTopologies,
	renderParents(
		report.Container, []string{report.SwarmService}, UnmanagedID,
		MakeFilter(
			IsRunning,
			ContainerWithImageNameRenderer,
		),
	),
)

SwarmServiceRenderer is a Renderer for Docker Swarm services

not memoised

View Source
var UncontainedIDPrefix = MakePseudoNodeID(UncontainedID, "")

UncontainedIDPrefix is the prefix of uncontained pseudo nodes

View Source
var UnmanagedIDPrefix = MakePseudoNodeID(UnmanagedID, "")

UnmanagedIDPrefix is the prefix of unmanaged pseudo nodes

View Source
var VolumeSnapshotRenderer = volumeSnapshotRenderer{}

VolumeSnapshotRenderer is a renderer which produces a renderable Kubernetes Volume Snapshot and Volume Snapshot Data

View Source
var VolumesRenderer = volumesRenderer{}

VolumesRenderer is a Renderer which produces a renderable kubernetes PV & PVC graph by merging the pods graph and the Persistent Volume topology.

WeaveRenderer is a Renderer which produces a renderable weave topology.

not memoised

Functions

func IsApplication added in v0.15.0

func IsApplication(n report.Node) bool

IsApplication checks if the node is an "application" node

func IsConnected added in v0.7.0

func IsConnected(node report.Node) bool

IsConnected checks whether the node has been marked with the IsConnectedMark.

func IsInternetNode added in v1.7.0

func IsInternetNode(n report.Node) bool

IsInternetNode determines whether the node represents the Internet.

func IsNonSnapshotComponent added in v1.10.0

func IsNonSnapshotComponent(node report.Node) bool

IsNonSnapshotComponent checks whether given node is everything but Volume Snapshot, Volume Snapshot Data

func IsNotPseudo added in v0.16.0

func IsNotPseudo(n report.Node) bool

IsNotPseudo returns true if the node is not a pseudo node or internet/service nodes.

func IsPodComponent added in v1.9.1

func IsPodComponent(node report.Node) bool

IsPodComponent check whether given node is everything but PV, PVC, SC

func IsRunning added in v0.14.0

func IsRunning(n report.Node) bool

IsRunning checks if the node is a running docker container

func LocalNetworks

func LocalNetworks(r report.Report) report.Networks

LocalNetworks returns a superset of the networks (think: CIDRs) that are "local" from the perspective of each host represented in the report. It's used to determine which nodes in the report are "remote", i.e. outside of our infrastructure.

func MakeGroupNodeTopology added in v0.15.0

func MakeGroupNodeTopology(originalTopology, key string) string

MakeGroupNodeTopology joins the parts of a group topology into the topology of a group node

func MakePseudoNodeID

func MakePseudoNodeID(parts ...string) string

MakePseudoNodeID joins the parts of an id into the id of a pseudonode

func MapContainer2IP added in v0.7.0

func MapContainer2IP(m report.Node) []string

MapContainer2IP maps container nodes to their IP addresses (outputs multiple nodes). This allows container to be joined directly with the endpoint topology.

func MapContainerImage2Name added in v0.5.0

func MapContainerImage2Name(n report.Node) report.Node

MapContainerImage2Name ignores image versions

func MapPod2IP added in v0.16.0

func MapPod2IP(m report.Node) []string

MapPod2IP maps pod nodes to their IP address. This allows pods to be joined directly with the endpoint topology.

func MapProcess2Container

func MapProcess2Container(n report.Node) report.Node

MapProcess2Container maps process Nodes to container Nodes.

Pseudo nodes are passed straight through.

If this function is given a node without a docker_container_id, it will produce an "Uncontained" pseudo node.

Otherwise, this function will produce a node with the correct ID format for a container, but without any Major or Minor labels. It does not have enough info to do that, and the resulting graph must be merged with a container graph to get that info.

func MapWeaveIdentity added in v1.0.0

func MapWeaveIdentity(m report.Node) report.Node

MapWeaveIdentity maps an overlay topology node to a weave topology node.

func NewDerivedNode added in v0.7.0

func NewDerivedNode(id string, node report.Node) report.Node

NewDerivedNode makes a node based on node, but with a new ID

func NewDerivedPseudoNode added in v0.14.0

func NewDerivedPseudoNode(id string, node report.Node) report.Node

NewDerivedPseudoNode makes a new pseudo node with the node as a child

func Noop added in v0.15.0

func Noop(_ report.Node) bool

Noop allows all nodes through

func ParseGroupNodeTopology added in v1.7.0

func ParseGroupNodeTopology(topology string) (string, string, bool)

ParseGroupNodeTopology returns the parts of a group topology.

func ParsePseudoNodeID added in v1.7.0

func ParsePseudoNodeID(nodeID string) (string, bool)

ParsePseudoNodeID returns the joined id parts of a pseudonode ID. If the ID is not recognisable as a pseudonode ID, it is returned as is, with the returned bool set to false. That is convenient because not all pseudonode IDs actually follow the format produced by MakePseudoNodeID.

func ResetCache added in v0.12.0

func ResetCache()

ResetCache blows away the rendered node cache, and known service cache.

Types

type Condition added in v0.15.0

type Condition func(report.Report) bool

Condition is a predecate over the entire report that can evaluate to true or false.

type CustomRenderer added in v0.7.0

type CustomRenderer struct {
	RenderFunc func(Nodes) Nodes
	Renderer
}

CustomRenderer allow for mapping functions that received the entire topology in one call - useful for functions that need to consider the entire graph. We should minimise the use of this renderer type, as it is very inflexible.

func (CustomRenderer) Render added in v0.7.0

func (c CustomRenderer) Render(ctx context.Context, rpt report.Report) Nodes

Render implements Renderer

type Filter added in v0.7.0

type Filter struct {
	Renderer
	FilterFunc FilterFunc
}

Filter removes nodes from a view based on a predicate.

func (Filter) Render added in v0.7.0

func (f Filter) Render(ctx context.Context, rpt report.Report) Nodes

Render implements Renderer

type FilterFunc added in v0.15.0

type FilterFunc func(report.Node) bool

FilterFunc is the function type used by Filters

func AnyFilterFunc added in v1.3.0

func AnyFilterFunc(fs ...FilterFunc) FilterFunc

AnyFilterFunc checks if any of the filterfuncs matches.

func Complement added in v0.14.0

func Complement(f FilterFunc) FilterFunc

Complement takes a FilterFunc f and returns a FilterFunc that has the same effects, if any, and returns the opposite truth value.

func ComposeFilterFuncs added in v0.15.0

func ComposeFilterFuncs(fs ...FilterFunc) FilterFunc

ComposeFilterFuncs composes filterfuncs into a single FilterFunc checking all.

func DoesNotHaveLabel added in v1.1.0

func DoesNotHaveLabel(labelKey string, labelValue string) FilterFunc

DoesNotHaveLabel checks if the node does NOT have the specified docker label

func HasChildren added in v0.15.0

func HasChildren(topology string) FilterFunc

HasChildren returns true if the node has no children from the specified topology.

func HasLabel added in v1.1.0

func HasLabel(labelKey string, labelValue string) FilterFunc

HasLabel checks if the node has the desired docker label

func IsNamespace added in v0.15.0

func IsNamespace(namespace string) FilterFunc

IsNamespace checks if the node is a pod/service in the specified namespace

func IsTopology added in v1.6.0

func IsTopology(topology string) FilterFunc

IsTopology checks if the node is from a particular report topology

func (FilterFunc) Transform added in v1.6.6

func (f FilterFunc) Transform(nodes Nodes) Nodes

Transform applies the filter to all nodes

type Map

type Map struct {
	MapFunc
	Renderer
}

Map is a Renderer which produces a set of Nodes from the set of Nodes produced by another Renderer.

func (Map) Render

func (m Map) Render(ctx context.Context, rpt report.Report) Nodes

Render transforms a set of Nodes produces by another Renderer. using a map function

type Map2Parent added in v0.15.0

type Map2Parent struct {
	// contains filtered or unexported fields
}

Map2Parent is a Renderer which maps Nodes to some parent grouping.

func (Map2Parent) Render added in v1.8.1

func (m Map2Parent) Render(ctx context.Context, rpt report.Report) Nodes

Render implements Renderer

type MapFunc

type MapFunc func(report.Node) report.Node

MapFunc is anything which can take an arbitrary Node and return another Node.

If the output ID is blank, the node shall be omitted from the rendered topology. (we chose not to return an extra bool because it adds clutter)

type Nodes added in v1.6.6

type Nodes struct {
	report.Nodes
	Filtered int
}

Nodes is the result of Rendering

func Render added in v1.6.6

func Render(ctx context.Context, rpt report.Report, renderer Renderer, transformer Transformer) Nodes

Render renders the report and then transforms it

func (Nodes) Merge added in v1.6.6

func (r Nodes) Merge(o Nodes) Nodes

Merge merges the results of Rendering

type Reduce

type Reduce []Renderer

Reduce renderer is a Renderer which merges together the output of several other renderers.

func (Reduce) Render

func (r Reduce) Render(ctx context.Context, rpt report.Report) Nodes

Render produces a set of Nodes given a Report.

type Renderer

type Renderer interface {
	Render(context.Context, report.Report) Nodes
}

Renderer is something that can render a report to a set of Nodes.

func ColorConnected added in v0.7.0

func ColorConnected(r Renderer) Renderer

ColorConnected colors nodes with the IsConnectedMark key if they have edges to or from them. Edges to/from yourself are not counted here (see #656).

func ConditionalRenderer added in v0.15.0

func ConditionalRenderer(c Condition, r Renderer) Renderer

ConditionalRenderer renders nothing if the condition is false, otherwise it defers to the wrapped Renderer.

func ConnectionJoin added in v1.5.0

func ConnectionJoin(toIPs func(report.Node) []string, topology string) Renderer

ConnectionJoin joins the given topology with connections from the endpoints topology, using the toIPs function to extract IPs from the nodes.

func FilterEmpty added in v0.15.0

func FilterEmpty(topology string, r Renderer) Renderer

FilterEmpty is a Renderer which filters out nodes which have no children from the specified topology.

func MakeFilter added in v0.12.0

func MakeFilter(f FilterFunc, r Renderer) Renderer

MakeFilter makes a new Filter (that ignores pseudo nodes).

func MakeFilterPseudo added in v0.16.0

func MakeFilterPseudo(f FilterFunc, r Renderer) Renderer

MakeFilterPseudo makes a new Filter that will not ignore pseudo nodes.

func MakeMap added in v0.12.0

func MakeMap(f MapFunc, r Renderer) Renderer

MakeMap makes a new Map

func MakeReduce

func MakeReduce(renderers ...Renderer) Renderer

MakeReduce is the only sane way to produce a Reduce Renderer.

func MapEndpoints added in v1.7.0

func MapEndpoints(f endpointMapFunc, topology string) Renderer

MapEndpoints creates a renderer for the endpoint topology. Each endpoint is either turned into a pseudo node, or mapped to a node in the specified topology by the supplied function.

func Memoise added in v0.12.0

func Memoise(r Renderer) Renderer

Memoise wraps the renderer in a loving embrace of caching.

func PropagateSingleMetrics added in v0.16.0

func PropagateSingleMetrics(topology string, r Renderer) Renderer

PropagateSingleMetrics creates a renderer which propagates metrics from a node's child to the node. The child is selected based on the specified topology. No metrics are propagated when there is more than one such child.

type TopologySelector added in v0.7.0

type TopologySelector string

TopologySelector selects a single topology from a report. NB it is also a Renderer!

func (TopologySelector) Render added in v0.7.0

Render implements Renderer

type Transformer added in v1.6.6

type Transformer interface {
	Transform(nodes Nodes) Nodes
}

Transformer is something that transforms one set of Nodes to another set of Nodes.

type Transformers added in v1.6.6

type Transformers []Transformer

Transformers is a composition of Transformers

func (Transformers) Transform added in v1.6.6

func (ts Transformers) Transform(nodes Nodes) Nodes

Transform implements Transformer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL