render

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

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 (
	TheInternetID      = "theinternet"
	IncomingInternetID = "in-" + TheInternetID
	OutgoingInternetID = "out-" + TheInternetID
)

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"

	// Topology for pseudo-nodes and IPs so we can differentiate them at the end
	Pseudo = "pseudo"
)

Constants are used in the tests.

View Source
const IsConnected = "is_connected"

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

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)
	SelectReplicaSet     = TopologySelector(report.ReplicaSet)
	SelectECSTask        = TopologySelector(report.ECSTask)
	SelectECSService     = TopologySelector(report.ECSService)
	SelectSwarmService   = TopologySelector(report.SwarmService)
	SelectOverlay        = TopologySelector(report.Overlay)
)

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

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

ContainerImageRenderer is a Renderer which produces a renderable container image graph by merging the container graph and the container image topology.

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

		state, ok := n.Latest.Lookup(docker.ContainerState)
		return !ok || state != docker.StateDeleted
	},
	MakeReduce(
		MakeMap(
			MapProcess2Container,
			ProcessRenderer,
		),

		ConnectionJoin(SelectContainer, MapContainer2IP),

		SelectContainer,
	),
)

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 = containerWithImageNameRenderer{ContainerRenderer}

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

DaemonSetRenderer is a Renderer which produces a renderable kubernetes daemonsets graph by merging the pods graph and the daemonsets topology.

View Source
var DeploymentRenderer = ConditionalRenderer(renderKubernetesTopologies,
	MakeMap(
		PropagateSingleMetrics(report.ReplicaSet),
		MakeReduce(
			MakeMap(
				Map2Parent(report.Deployment, "", mapPodCounts),
				ReplicaSetRenderer,
			),
			SelectDeployment,
		),
	),
)

DeploymentRenderer is a Renderer which produces a renderable kubernetes deployments graph by merging the pods graph and the deployments topology.

ECSServiceRenderer is a Renderer for Amazon ECS services.

ECSTaskRenderer is a Renderer for Amazon ECS tasks.

EndpointRenderer is a Renderer which produces a renderable endpoint graph.

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

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 PodRenderer = ConditionalRenderer(renderKubernetesTopologies,
	MakeFilter(
		func(n report.Node) bool {
			state, ok := n.Latest.Lookup(kubernetes.State)
			return (!ok || state != kubernetes.StateDeleted)
		},
		MakeMap(
			PropagateSingleMetrics(report.Container),
			MakeReduce(
				MakeMap(
					Map2Parent(report.Pod, UnmanagedID, nil),
					MakeFilter(
						ComposeFilterFuncs(
							IsRunning,
							Complement(isPauseContainer),
						),
						ContainerWithImageNameRenderer,
					),
				),
				ConnectionJoin(SelectPod, MapPod2IP),
				SelectPod,
			),
		),
	),
)

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,
	MakeMap(
		PropagateSingleMetrics(report.Pod),
		MakeReduce(
			MakeMap(
				Map2Parent(report.Service, "", nil),
				PodRenderer,
			),
			SelectService,
		),
	),
)

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

View Source
var ProcessNameRenderer = ConditionalRenderer(renderProcesses,
	MakeMap(
		MapProcess2Name,
		ProcessRenderer,
	),
)

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

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

View Source
var ProcessWithContainerNameRenderer = processWithContainerNameRenderer{ProcessRenderer}

ProcessWithContainerNameRenderer is a Renderer which produces a process graph enriched with container names where appropriate

ReplicaSetRenderer is a Renderer which produces a renderable kubernetes replica sets graph by merging the pods graph and the replica sets topology.

View Source
var (
	// ServiceNodeIDPrefix is how the ID of all service pseudo nodes begin
	ServiceNodeIDPrefix = "service-"
)

SwarmServiceRenderer is a Renderer for Docker Swarm services

WeaveRenderer is a Renderer which produces a renderable weave topology.

Functions

func DNSNames added in v1.0.0

func DNSNames(n report.Node) []string

DNSNames returns a prioritized list of snooped and reverse-resolved DNS names associated with node n.

func IsApplication added in v0.15.0

func IsApplication(n report.Node) bool

IsApplication checks if the node is an "application" node

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 IsPseudoTopology added in v1.4.0

func IsPseudoTopology(n report.Node) bool

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()

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 MapContainer2ContainerImage

func MapContainer2ContainerImage(n report.Node, _ report.Networks) report.Nodes

MapContainer2ContainerImage maps container Nodes to container image Nodes.

If this function is given a node without a docker_image_id (including other pseudo nodes), 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 MapContainer2Hostname added in v0.9.0

func MapContainer2Hostname(n report.Node, _ report.Networks) report.Nodes

MapContainer2Hostname maps container Nodes to 'hostname' renderabled nodes..

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.Networks) report.Nodes

MapContainerImage2Name ignores image versions

func MapEndpoint2Host added in v0.14.0

func MapEndpoint2Host(n report.Node, local report.Networks) report.Nodes

MapEndpoint2Host takes nodes from the endpoint topology and produces host nodes or pseudo nodes.

func MapEndpoint2Process

func MapEndpoint2Process(n report.Node, local report.Networks) report.Nodes

MapEndpoint2Process maps endpoint Nodes to process Nodes.

If this function is given a pseudo node, then it will just return it; Pseudo nodes will never have pids in them, and therefore will never be able to be turned into a Process node.

Otherwise, this function will produce a node with the correct ID format for a process, 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 process graph to get that info.

func MapEndpoint2Pseudo added in v0.14.0

func MapEndpoint2Pseudo(n report.Node, local report.Networks) report.Nodes

MapEndpoint2Pseudo makes internet of host pesudo nodes from a endpoint node.

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.Networks) report.Nodes

MapProcess2Container maps process Nodes to container Nodes.

If this function is given a node without a docker_container_id (including other pseudo nodes), 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 MapProcess2Name

func MapProcess2Name(n report.Node, _ report.Networks) report.Nodes

MapProcess2Name maps process Nodes to Nodes for each process name.

This mapper is unlike the other foo2bar mappers as the intention is not to join the information with another topology.

func MapToEmpty added in v0.15.0

func MapToEmpty(n report.Node, _ report.Networks) report.Nodes

MapToEmpty removes all the attributes, children, etc, of a node. Useful when we just want to count the presence of nodes.

func MapWeaveIdentity added in v1.0.0

func MapWeaveIdentity(m report.Node, _ report.Networks) report.Nodes

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

func MapX2Host added in v0.12.0

func MapX2Host(n report.Node, _ report.Networks) report.Nodes

MapX2Host maps any Nodes to host Nodes.

If this function is given a node without a hostname (including other pseudo nodes), it will drop the 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 NewDerivedExternalNode added in v1.2.0

func NewDerivedExternalNode(n report.Node, addr string, local report.Networks) (report.Node, bool)

NewDerivedExternalNode figures out if a node should be considered external and creates the corresponding pseudo 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 ResetCache added in v0.12.0

func ResetCache()

ResetCache blows away the rendered node 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 ConstantRenderer added in v1.0.0

type ConstantRenderer report.Nodes

ConstantRenderer renders a fixed set of nodes

func (ConstantRenderer) Render added in v1.0.0

Render implements Renderer

func (ConstantRenderer) Stats added in v1.0.0

Stats implements Renderer

type CustomRenderer added in v0.7.0

type CustomRenderer struct {
	RenderFunc func(report.Nodes) report.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(rpt report.Report, dct Decorator) report.Nodes

Render implements Renderer

type Decorator added in v0.15.0

type Decorator func(Renderer) Renderer

Decorator transforms one renderer to another. e.g. Filters.

func ComposeDecorators added in v0.15.0

func ComposeDecorators(decorators ...Decorator) Decorator

ComposeDecorators composes decorators into one.

func MakeFilterDecorator added in v0.16.0

func MakeFilterDecorator(f FilterFunc) Decorator

MakeFilterDecorator makes a decorator that filters out non-pseudo nodes which match the predicate.

func MakeFilterPseudoDecorator added in v0.16.0

func MakeFilterPseudoDecorator(f FilterFunc) Decorator

MakeFilterPseudoDecorator makes a decorator that filters out all nodes (including pseudo nodes) which match the predicate.

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(rpt report.Report, dct Decorator) report.Nodes

Render implements Renderer

func (Filter) Stats added in v0.8.0

func (f Filter) Stats(rpt report.Report, dct Decorator) Stats

Stats implements Renderer. General logic is to take the first (i.e. highest-level) stats we find, so upstream stats are ignored. This means that if we want to count the stats from multiple filters we need to compose their FilterFuncs, into a single Filter.

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

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(rpt report.Report, dct Decorator) report.Nodes

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

func (*Map) Stats added in v0.8.0

func (m *Map) Stats(_ report.Report, _ Decorator) Stats

Stats implements Renderer

type MapFunc

type MapFunc func(report.Node, report.Networks) report.Nodes

MapFunc is anything which can take an arbitrary Node and return a set of other Nodes.

If the output is empty, the node shall be omitted from the rendered topology.

func Map2Parent added in v0.15.0

func Map2Parent(

	topology string,

	noParentsPseudoID string,

	modifyMappedNode func(parent, original report.Node) report.Node,
) MapFunc

Map2Parent returns a MapFunc which maps Nodes to some parent grouping.

func PropagateSingleMetrics added in v0.16.0

func PropagateSingleMetrics(topology string) MapFunc

PropagateSingleMetrics puts metrics from one of the children onto the parent iff there is only one child of that type.

type PreciousNodeRenderer added in v1.0.0

type PreciousNodeRenderer struct {
	PreciousNodeID string
	Renderer
}

PreciousNodeRenderer ensures a node is never filtered out by decorators

func (PreciousNodeRenderer) Render added in v1.0.0

Render implements Renderer

func (PreciousNodeRenderer) Stats added in v1.0.0

func (p PreciousNodeRenderer) Stats(rpt report.Report, dct Decorator) Stats

Stats implements Renderer

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(rpt report.Report, dct Decorator) report.Nodes

Render produces a set of Nodes given a Report.

func (*Reduce) Stats added in v0.8.0

func (r *Reduce) Stats(rpt report.Report, dct Decorator) Stats

Stats implements Renderer

type Renderer

type Renderer interface {
	Render(report.Report, Decorator) report.Nodes
	Stats(report.Report, Decorator) Stats
}

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

func ApplyDecorator added in v1.3.0

func ApplyDecorator(renderer Renderer) Renderer

ApplyDecorator returns a renderer which will apply the given decorator to the child render.

func ColorConnected added in v0.7.0

func ColorConnected(r Renderer) Renderer

ColorConnected colors nodes with the IsConnected 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(r Renderer, toIPs func(report.Node) []string) Renderer

ConnectionJoin joins the given renderer 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 FilterProcspiedOrEBPF added in v1.5.0

func FilterProcspiedOrEBPF(r Renderer) Renderer

FilterProcspiedOrEBPF keeps only endpoints which were found via procspy or eBPF.

func FilterUnconnected

func FilterUnconnected(r Renderer) Renderer

FilterUnconnected produces a renderer that filters unconnected nodes from the given renderer

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 Memoise added in v0.12.0

func Memoise(r Renderer) Renderer

Memoise wraps the renderer in a loving embrace of caching.

type Stats added in v0.8.0

type Stats struct {
	FilteredNodes int
}

Stats is the type returned by Renderer.Stats

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

func (TopologySelector) Stats added in v0.8.0

Stats implements Renderer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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