provider

package
v0.0.0-...-a4a88c6 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package provider defines the Provider interface which allows to get metrics collectors for the different container runtimes supported (Docker, containerd, etc.).

Package provider defines the Provider interface which allows to get metrics collectors for the different container runtimes supported (Docker, containerd, etc.).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNothingYet is returned when no collector is currently detected.
	// This might change in the future if new collectors are valid.
	ErrNothingYet = &retry.Error{
		LogicError:    errors.New("no collector detected for runtime"),
		RessourceName: "catalog",
		RetryStatus:   retry.FailWillRetry,
	}

	// ErrPermaFail is returned when a collector will never be available
	ErrPermaFail = &retry.Error{
		LogicError:    errors.New("no collector available for runtime"),
		RessourceName: "catalog",
		RetryStatus:   retry.PermaFail,
	}

	// AllLinuxRuntimes lists all runtimes available on Linux
	// nolint: deadcode, unused
	AllLinuxRuntimes = []Runtime{
		RuntimeNameDocker,
		RuntimeNameContainerd,
		RuntimeNameCRIO,
		RuntimeNameGarden,
		RuntimeNamePodman,
		RuntimeNameECSFargate,
	}

	// AllWindowsRuntimes lists all runtimes available on Windows
	// nolint: deadcode, unused
	AllWindowsRuntimes = []Runtime{
		RuntimeNameDocker,
		RuntimeNameContainerd,
		RuntimeNameECSFargate,
	}
)

Functions

func ConvertRetrierErr

func ConvertRetrierErr(err error) error

ConvertRetrierErr converts a retrier error into a metrics error

func RegisterCollector

func RegisterCollector(collectorFactory CollectorFactory)

RegisterCollector registers a collector

Types

type Cache

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

Cache provides a caching mechanism based on staleness toleration provided by requestor

func NewCache

func NewCache(gcInterval time.Duration) *Cache

NewCache returns a new cache dedicated to a collector

func (*Cache) Get

func (c *Cache) Get(currentTime time.Time, key string, cacheValidity time.Duration) (interface{}, bool, error)

Get retrieves data from cache, returns not found if cacheValidity == 0

func (*Cache) Store

func (c *Cache) Store(currentTime time.Time, key string, value interface{}, err error)

Store retrieves data from cache

type Collector

Collector defines the public interface

type CollectorCatalog

type CollectorCatalog map[RuntimeMetadata]*Collectors

CollectorCatalog defines the enabled Collectors for a given runtime

type CollectorFactory

type CollectorFactory struct {
	ID          string
	Constructor func(*Cache, optional.Option[workloadmeta.Component]) (CollectorMetadata, error)
}

CollectorFactory allows to register a factory to dynamically create Collector at startup

type CollectorMetadata

type CollectorMetadata struct {
	ID         string
	Collectors CollectorCatalog
}

CollectorMetadata contains the characteristics of a collector to be registered with RegisterCollector

type CollectorRef

type CollectorRef[T comparable] struct {
	Collector T
	Priority  uint8
}

CollectorRef holds a collector interface reference with metadata T is always an interface. Collectors implementing this interface need to be comparable, often means that it should be a pointer receiver.

func MakeRef

func MakeRef[T comparable](collector T, priority uint8) CollectorRef[T]

MakeRef returns a CollectorRef[T] given a T and a priority

type Collectors

type Collectors struct {
	Stats          CollectorRef[ContainerStatsGetter]
	Network        CollectorRef[ContainerNetworkStatsGetter]
	OpenFilesCount CollectorRef[ContainerOpenFilesCountGetter]
	PIDs           CollectorRef[ContainerPIDsGetter]

	// These collectors are used in the meta collector
	ContainerIDForPID               CollectorRef[ContainerIDForPIDRetriever]
	ContainerIDForInode             CollectorRef[ContainerIDForInodeRetriever]
	SelfContainerID                 CollectorRef[SelfContainerIDRetriever]
	ContainerIDForPodUIDAndContName CollectorRef[ContainerIDForPodUIDAndContNameRetriever]
}

Collectors is used by implementation to set their capabilities and by registry to store current version Priority fields: lowest gets higher priority (0 more prioritary than 1)

func MakeCached

func MakeCached(providerID string, cache *Cache, collectors *Collectors) *Collectors

MakeCached modifies `collectors` to go through a caching layer

type ContainerCPUStats

type ContainerCPUStats struct {
	// Common fields
	Total          *float64
	System         *float64
	User           *float64
	Limit          *float64 // Percentage 0-100*numCPU
	DefaultedLimit bool     // If Limit != nil, indicated if limit was explicit from container or defaulted to # of host CPUs

	// Linux-only fields
	Shares           *float64 // Available only in cgroups v1
	Weight           *float64 // Available only in cgroups v2. Similar concept as shares but the default value and the range of valid values are different.
	ElapsedPeriods   *float64
	ThrottledPeriods *float64
	ThrottledTime    *float64
	PartialStallTime *float64 // Correspond to PSI Some total
}

ContainerCPUStats stores CPU stats.

type ContainerIDForInodeRetriever

type ContainerIDForInodeRetriever interface {
	// GetContainerIDForInode returns a container ID for the given inode.
	// ("", nil) will be returned if no error but the containerd ID was not found.
	GetContainerIDForInode(inode uint64, cacheValidity time.Duration) (string, error)
}

ContainerIDForInodeRetriever interface

type ContainerIDForPIDRetriever

type ContainerIDForPIDRetriever interface {
	// GetContainerIDForPID returns a container ID for given PID.
	// ("", nil) will be returned if no error but the containerd ID was not found.
	GetContainerIDForPID(pid int, cacheValidity time.Duration) (string, error)
}

ContainerIDForPIDRetriever interface

type ContainerIDForPodUIDAndContNameRetriever

type ContainerIDForPodUIDAndContNameRetriever interface {
	// ContainerIDForPodUIDAndContName returns a container ID for the given pod uid
	// and container name. Returns ("", nil) if the containerd ID was not found.
	ContainerIDForPodUIDAndContName(podUID, contName string, initCont bool, cacheValidity time.Duration) (string, error)
}

ContainerIDForPodUIDAndContNameRetriever interface

type ContainerIOStats

type ContainerIOStats struct {
	// Common fields
	ReadBytes       *float64
	WriteBytes      *float64
	ReadOperations  *float64
	WriteOperations *float64

	// Linux only
	PartialStallTime *float64 // Correspond to PSI Some total

	Devices map[string]DeviceIOStats
}

ContainerIOStats store I/O statistics about a container.

type ContainerMemStats

type ContainerMemStats struct {
	// Common fields
	UsageTotal   *float64
	KernelMemory *float64
	Limit        *float64
	Softlimit    *float64
	Swap         *float64
	SwapLimit    *float64 // Memory+Swap Limit (>= Limit)

	// Linux-only fields
	WorkingSet       *float64 // Following cAdvisor/Kubernetes: defined as UsageTotal - InactiveFiles
	RSS              *float64
	Cache            *float64
	OOMEvents        *float64 // Number of events where memory allocation failed
	PartialStallTime *float64 // Correspond to PSI Some total
	Peak             *float64
	Pgfault          *float64
	Pgmajfault       *float64

	// Windows-only fields
	PrivateWorkingSet *float64
	CommitBytes       *float64
	CommitPeakBytes   *float64
}

ContainerMemStats stores memory statistics.

type ContainerNetworkStats

type ContainerNetworkStats struct {
	Timestamp               time.Time
	BytesSent               *float64
	BytesRcvd               *float64
	PacketsSent             *float64
	PacketsRcvd             *float64
	Interfaces              map[string]InterfaceNetStats
	NetworkIsolationGroupID *uint64
	UsingHostNetwork        *bool
}

ContainerNetworkStats stores network statistics about a container per interface

type ContainerNetworkStatsGetter

type ContainerNetworkStatsGetter interface {
	GetContainerNetworkStats(containerNS, containerID string, cacheValidity time.Duration) (*ContainerNetworkStats, error)
}

ContainerNetworkStatsGetter interface

type ContainerOpenFilesCountGetter

type ContainerOpenFilesCountGetter interface {
	GetContainerOpenFilesCount(containerNS, containerID string, cacheValidity time.Duration) (*uint64, error)
}

ContainerOpenFilesCountGetter interface

type ContainerPIDStats

type ContainerPIDStats struct {
	// Common fields
	ThreadCount *float64
	ThreadLimit *float64
}

ContainerPIDStats stores stats about threads & processes.

type ContainerPIDsGetter

type ContainerPIDsGetter interface {
	GetPIDs(containerNS, containerID string, cacheValidity time.Duration) ([]int, error)
}

ContainerPIDsGetter interface

type ContainerStats

type ContainerStats struct {
	Timestamp time.Time
	CPU       *ContainerCPUStats
	Memory    *ContainerMemStats
	IO        *ContainerIOStats
	PID       *ContainerPIDStats
}

ContainerStats wraps all container metrics

type ContainerStatsGetter

type ContainerStatsGetter interface {
	GetContainerStats(containerNS, containerID string, cacheValidity time.Duration) (*ContainerStats, error)
}

ContainerStatsGetter interface

type DeviceIOStats

type DeviceIOStats struct {
	// Common fields
	ReadBytes       *float64
	WriteBytes      *float64
	ReadOperations  *float64
	WriteOperations *float64
}

DeviceIOStats stores Device IO stats.

type GenericProvider

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

GenericProvider offers an interface to retrieve a metrics collector

func (*GenericProvider) GetCollector

func (mp *GenericProvider) GetCollector(r RuntimeMetadata) Collector

GetCollector returns the best collector for given runtime. The best collector may change depending on other collectors availability. You should not cache the result from this function.

func (*GenericProvider) GetMetaCollector

func (mp *GenericProvider) GetMetaCollector() MetaCollector

GetMetaCollector returns the meta collector.

type InterfaceNetStats

type InterfaceNetStats struct {
	BytesSent   *float64
	BytesRcvd   *float64
	PacketsSent *float64
	PacketsRcvd *float64
}

InterfaceNetStats stores network statistics about a network interface

type MetaCollector

MetaCollector is a special collector that uses all available collectors, by priority order.

type Provider

type Provider interface {
	GetCollector(RuntimeMetadata) Collector
	GetMetaCollector() MetaCollector
}

Provider interface allows to mock the metrics provider

func GetProvider

func GetProvider(wmeta optional.Option[workloadmeta.Component]) Provider

GetProvider returns the metrics provider singleton

type Runtime

type Runtime string

Runtime is a typed string for supported container runtimes

const (
	RuntimeNameDocker     Runtime = "docker"
	RuntimeNameContainerd Runtime = "containerd"
	RuntimeNameCRIO       Runtime = "cri-o"
	RuntimeNameGarden     Runtime = "garden"
	RuntimeNamePodman     Runtime = "podman"
	RuntimeNameECSFargate Runtime = "ecsfargate"
)

Known container runtimes

type RuntimeFlavor

type RuntimeFlavor string

RuntimeFlavor is a typed string for supported container runtime flavors

const (
	RuntimeFlavorDefault RuntimeFlavor = ""
	RuntimeFlavorKata    RuntimeFlavor = "kata"
)

Known container runtime flavors

type RuntimeMetadata

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

RuntimeMetadata contains the runtime flavor and runtime name

func NewRuntimeMetadata

func NewRuntimeMetadata(runtime, flavor string) RuntimeMetadata

NewRuntimeMetadata returns a new RuntimeMetadata

func (*RuntimeMetadata) String

func (r *RuntimeMetadata) String() string

String returns the runtime compose.

type SelfContainerIDRetriever

type SelfContainerIDRetriever interface {
	// GetSelfContainerID returns the container ID for current container.
	// ("", nil) will be returned if not possible to get ID for current container.
	GetSelfContainerID() (string, error)
}

SelfContainerIDRetriever interface

Jump to

Keyboard shortcuts

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