workloadmeta

package
v0.0.0-...-7983b3b Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

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

	SourceDocker       Source = "docker"
	SourceContainerd   Source = "containerd"
	SourceECS          Source = "ecs"
	SourceECSFargate   Source = "ecs_fargate"
	SourceKubelet      Source = "kubelet"
	SourceKubeMetadata Source = "kube_metadata"

	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 Source
	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.

func (Container) String

func (c Container) String(verbose bool) string

String returns a string representation of Container.

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

func (ContainerImage) String

func (c ContainerImage) String(verbose bool) string

String returns a string representation of ContainerImage.

type ContainerPort

type ContainerPort struct {
	Name     string
	Port     int
	Protocol string
}

ContainerPort is a port open in the container.

func (ContainerPort) String

func (c ContainerPort) String(verbose bool) string

String returns a string representation of ContainerPort.

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.

func (ContainerState) String

func (c ContainerState) String(verbose bool) string

String returns a string representation of ContainerState.

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.

func (ECSTask) String

func (t ECSTask) String(verbose bool) string

String returns a string representation of ECSTask.

type Entity

type Entity interface {
	GetID() EntityID
	Merge(Entity) error
	DeepCopy() Entity
	String(verbose bool) string
}

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.

func (EntityID) String

func (i EntityID) String(_ bool) string

String returns a string representation of EntityID.

type EntityMeta

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

EntityMeta represents generic metadata about an Entity.

func (EntityMeta) String

func (e EntityMeta) String(verbose bool) string

String returns a string representation of EntityMeta.

type Event

type Event struct {
	Type    EventType
	Sources []Source
	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 []Source) *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 Source) 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 []Source) ([]Source, 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.

func (KubernetesPod) String

func (p KubernetesPod) String(verbose bool) string

String returns a string representation of KubernetesPod.

type KubernetesPodOwner

type KubernetesPodOwner struct {
	Kind string
	Name string
	ID   string
}

KubernetesPodOwner is extracted from a pod's owner references.

func (KubernetesPodOwner) String

func (o KubernetesPodOwner) String(verbose bool) string

String returns a string representation of KubernetesPodOwner.

type OrchestratorContainer

type OrchestratorContainer struct {
	ID    string
	Name  string
	Image ContainerImage
}

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

func (OrchestratorContainer) String

func (o OrchestratorContainer) String(_ bool) string

String returns a string representation of OrchestratorContainer.

type Source

type Source string

Source is the source name of an entity.

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)
	ListContainers() ([]*Container, error)
	GetKubernetesPod(id string) (*KubernetesPod, error)
	GetKubernetesPodForContainer(containerID string) (*KubernetesPod, error)
	GetECSTask(id string) (*ECSTask, error)
	Notify(events []CollectorEvent)
	Dump(verbose bool) WorkloadDumpResponse
}

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.

type WorkloadDumpResponse

type WorkloadDumpResponse struct {
	Entities map[string]WorkloadEntity `json:"entities"`
}

WorkloadDumpResponse is used to dump the store content.

func (WorkloadDumpResponse) Write

func (wdr WorkloadDumpResponse) Write(writer io.Writer)

Write writes the stores content in a given writer. Useful for agent's CLI and Flare.

type WorkloadEntity

type WorkloadEntity struct {
	Infos map[string]string `json:"infos"`
}

WorkloadEntity contains entity data.

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