workloadmeta

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindContainer     Kind = "container"
	KindKubernetesPod Kind = "kubernetes_pod"
	KindECSTask       Kind = "ecs_task"

	ContainerRuntimeDocker     ContainerRuntime = "docker"
	ContainerRuntimeContainerd ContainerRuntime = "containerd"

	ECSLaunchTypeEC2     ECSLaunchType = "ec2"
	ECSLaunchTypeFargate ECSLaunchType = "fargate"

	EventTypeSet EventType = iota
	EventTypeUnset
)

List of enumerable constants for the types above.

Variables

This section is empty.

Functions

func RegisterCollector

func RegisterCollector(id string, c collectorFactory)

RegisterCollector registers a new collector, identified by an id for logging and telemetry purposes, to be used by the store.

Types

type Collector

type Collector interface {
	// Start starts a collector. The collector should run until the context
	// is done. It also gets a reference to the store that started it so it
	// can use Notify, or get access to other entities in the store.
	Start(context.Context, Store) error

	// Pull triggers an entity collection. To be used by collectors that
	// don't have streaming functionality, and called periodically by the
	// store.
	Pull(context.Context) error
}

Collector is responsible for collecting metadata about workloads.

type CollectorEvent

type CollectorEvent struct {
	Type   EventType
	Source string
	Entity Entity
}

CollectorEvent is an event generated by a metadata collector, to be handled by the metadata store.

type Container

type Container struct {
	EntityID
	EntityMeta
	EnvVars    map[string]string
	Hostname   string
	Image      ContainerImage
	NetworkIPs map[string]string
	PID        int
	Ports      []ContainerPort
	Runtime    ContainerRuntime
	State      ContainerState
}

Container is a containerized workload.

func (Container) DeepCopy

func (c Container) DeepCopy() Entity

DeepCopy returns a deep copy of the container.

func (Container) GetID

func (c Container) GetID() EntityID

GetID returns the Container's EntityID.

func (*Container) Merge

func (c *Container) Merge(e Entity) error

Merge merges a Container with another. Returns an error if trying to merge with another kind.

type ContainerImage

type ContainerImage struct {
	ID        string
	RawName   string
	Name      string
	ShortName string
	Tag       string
}

ContainerImage is the an image used by a container.

func NewContainerImage

func NewContainerImage(imageName string) (ContainerImage, error)

NewContainerImage builds a ContainerImage from an image name

type ContainerPort

type ContainerPort struct {
	Name     string
	Port     int
	Protocol string
}

ContainerPort is a port open in the container.

type ContainerRuntime

type ContainerRuntime string

ContainerRuntime is the container runtime used by a container.

type ContainerState

type ContainerState struct {
	Running    bool
	StartedAt  time.Time
	FinishedAt time.Time
}

ContainerState is the state of a container.

type ECSLaunchType

type ECSLaunchType string

ECSLaunchType is the launch type of an ECS task.

type ECSTask

type ECSTask struct {
	EntityID
	EntityMeta
	Tags                  map[string]string
	ContainerInstanceTags map[string]string
	ClusterName           string
	Region                string
	AvailabilityZone      string
	Family                string
	Version               string
	LaunchType            ECSLaunchType
	Containers            []OrchestratorContainer
}

ECSTask is an ECS Task.

func (ECSTask) DeepCopy

func (t ECSTask) DeepCopy() Entity

DeepCopy returns a deep copy of the task.

func (ECSTask) GetID

func (t ECSTask) GetID() EntityID

GetID returns an ECSTasks's EntityID.

func (*ECSTask) Merge

func (t *ECSTask) Merge(e Entity) error

Merge merges a ECSTask with another. Returns an error if trying to merge with another kind.

type Entity

type Entity interface {
	GetID() EntityID
	Merge(Entity) error
	DeepCopy() Entity
}

Entity is an item in the metadata store. It exists as an interface to avoid usage of interface{}.

type EntityID

type EntityID struct {
	Kind Kind
	ID   string
}

EntityID represents the ID of an Entity.

func (EntityID) DeepCopy

func (i EntityID) DeepCopy() Entity

DeepCopy returns a deep copy of EntityID.

func (EntityID) GetID

func (i EntityID) GetID() EntityID

GetID satisfies the Entity interface for EntityID to allow a standalone EntityID to be passed in events of type EventTypeUnset without the need to build a full, concrete entity.

func (EntityID) Merge

func (i EntityID) Merge(e Entity) error

Merge returns an error because EntityID is not expected to be merged with another Entity, because it's used as an identifier.

type EntityMeta

type EntityMeta struct {
	Name        string
	Namespace   string
	Annotations map[string]string
	Labels      map[string]string
}

EntityMeta represents generic metadata about an Entity.

type Event

type Event struct {
	Type    EventType
	Sources []string
	Entity  Entity
}

Event is an event generated by the metadata store, to be broadcasted to subscribers.

type EventBundle

type EventBundle struct {
	Events []Event
	Ch     chan struct{}
}

EventBundle is a collection of events, and a channel that needs to be closed when the receiving subscriber wants to unblock the notifier.

type EventType

type EventType int

EventType is the type of an event.

type Filter

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

Filter allows a subscriber to filter events by entity kind or event source.

func NewFilter

func NewFilter(kinds []Kind, sources []string) *Filter

NewFilter creates a new filter for subscribing to workloadmeta events.

func (*Filter) Match

func (f *Filter) Match(ev CollectorEvent) bool

Match returns true if the filter matches an event.

func (*Filter) MatchKind

func (f *Filter) MatchKind(k Kind) bool

MatchKind returns true if the filter matches the passed Kind. If the filter is nil, or has no kinds, it always matches.

func (*Filter) MatchSource

func (f *Filter) MatchSource(source string) bool

MatchSource returns true if the filter matches the passed sources. If the filter is nil, or has no sources, it always matches.

func (*Filter) SelectSources

func (f *Filter) SelectSources(sources []string) ([]string, bool)

SelectSources returns a subset of the passed sources that match the filter.

type Kind

type Kind string

Kind is the kind of an entity.

type KubernetesPod

type KubernetesPod struct {
	EntityID
	EntityMeta
	Owners                     []KubernetesPodOwner
	PersistentVolumeClaimNames []string
	Containers                 []OrchestratorContainer
	Ready                      bool
	Phase                      string
	IP                         string
	PriorityClass              string
	KubeServices               []string
	NamespaceLabels            map[string]string
}

KubernetesPod is a Kubernetes Pod.

func (KubernetesPod) DeepCopy

func (p KubernetesPod) DeepCopy() Entity

DeepCopy returns a deep copy of the pod.

func (KubernetesPod) GetID

func (p KubernetesPod) GetID() EntityID

GetID returns the KubernetesPod's EntityID.

func (*KubernetesPod) Merge

func (p *KubernetesPod) Merge(e Entity) error

Merge merges a KubernetesPod with another. Returns an error if trying to merge with another kind.

type KubernetesPodOwner

type KubernetesPodOwner struct {
	Kind string
	Name string
	ID   string
}

KubernetesPodOwner is extracted from a pod's owner references.

type OrchestratorContainer

type OrchestratorContainer struct {
	ID   string
	Name string
}

OrchestratorContainer is a reference to a Container with orchestrator-specific data attached to it.

type Store

type Store interface {
	Start(ctx context.Context)
	Subscribe(name string, filter *Filter) chan EventBundle
	Unsubscribe(ch chan EventBundle)
	GetContainer(id string) (*Container, error)
	GetKubernetesPod(id string) (*KubernetesPod, error)
	GetKubernetesPodForContainer(containerID string) (*KubernetesPod, error)
	GetECSTask(id string) (*ECSTask, error)
	Notify(events []CollectorEvent)
}

Store is a central storage of metadata about workloads. A workload is any unit of work being done by a piece of software, like a process, a container, a kubernetes pod, or a task in any cloud provider.

func GetGlobalStore

func GetGlobalStore() Store

GetGlobalStore returns a global instance of the workloadmeta store, creating one if it doesn't exist. Start() needs to be called before any data collection happens.

func NewStore

func NewStore(catalog map[string]collectorFactory) Store

NewStore creates a new workload metadata store, building a new instance of each collector in the catalog. Call Start to start the store and its collectors.

Directories

Path Synopsis
Package collectors is a wrapper that loads the available workloadmeta collectors.
Package collectors is a wrapper that loads the available workloadmeta collectors.
ecs

Jump to

Keyboard shortcuts

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