Documentation
¶
Index ¶
- Constants
- func NewFakeInformer(_ kubernetes.Interface, namespace string, labelSelector labels.Selector, ...) cache.SharedInformer
- func NewFakeNamespaceInformer(_ kubernetes.Interface) cache.SharedInformer
- func NewNoOpInformer(_ kubernetes.Interface) cache.SharedInformer
- type APIClientsetProvider
- type Association
- type AssociationSource
- type Associations
- type Client
- type ClientProvider
- type Container
- type ContainerStatus
- type ExcludePods
- type Excludes
- type ExtractionRules
- type FakeController
- type FakeInformer
- func (f *FakeInformer) AddEventHandler(handler cache.ResourceEventHandler) (cache.ResourceEventHandlerRegistration, error)
- func (f *FakeInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, resyncPeriod time.Duration) (cache.ResourceEventHandlerRegistration, error)
- func (f *FakeInformer) GetController() cache.Controller
- func (f *FakeInformer) GetStore() cache.Store
- func (f *FakeInformer) IsStopped() bool
- func (f *FakeInformer) RemoveEventHandler(handle cache.ResourceEventHandlerRegistration) error
- func (f *FakeInformer) SetTransform(handler cache.TransformFunc) error
- func (f *FakeInformer) SetWatchErrorHandler(cache.WatchErrorHandler) error
- type FakeNamespaceInformer
- func (f *FakeNamespaceInformer) AddEventHandler(handler cache.ResourceEventHandler)
- func (f *FakeNamespaceInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, period time.Duration)
- func (f *FakeNamespaceInformer) GetController() cache.Controller
- func (f *FakeNamespaceInformer) GetStore() cache.Store
- type FieldExtractionRule
- type FieldFilter
- type Filters
- type InformerProvider
- type InformerProviderNamespace
- type Namespace
- type NoOpController
- type NoOpInformer
- func (f *NoOpInformer) AddEventHandler(handler cache.ResourceEventHandler) (cache.ResourceEventHandlerRegistration, error)
- func (f *NoOpInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, resyncPeriod time.Duration) (cache.ResourceEventHandlerRegistration, error)
- func (f *NoOpInformer) GetController() cache.Controller
- func (f *NoOpInformer) GetStore() cache.Store
- func (f *NoOpInformer) RemoveEventHandler(handle cache.ResourceEventHandlerRegistration) error
- func (f *NoOpInformer) SetTransform(handler cache.TransformFunc) error
- type Pod
- type PodContainers
- type PodIdentifier
- type PodIdentifierAttribute
- type WatchClient
Constants ¶
const ( // MetadataFromPod is used to specify to extract metadata/labels/annotations from pod MetadataFromPod = "pod" // MetadataFromNamespace is used to specify to extract metadata/labels/annotations from namespace MetadataFromNamespace = "namespace" PodIdentifierMaxLength = 4 ResourceSource = "resource_attribute" ConnectionSource = "connection" K8sIPLabelName = "k8s.pod.ip" )
Variables ¶
This section is empty.
Functions ¶
func NewFakeInformer ¶
func NewFakeInformer( _ kubernetes.Interface, namespace string, labelSelector labels.Selector, fieldSelector fields.Selector, ) cache.SharedInformer
func NewFakeNamespaceInformer ¶
func NewFakeNamespaceInformer( _ kubernetes.Interface, ) cache.SharedInformer
func NewNoOpInformer ¶
func NewNoOpInformer( _ kubernetes.Interface, ) cache.SharedInformer
Types ¶
type APIClientsetProvider ¶
type APIClientsetProvider func(config k8sconfig.APIConfig) (kubernetes.Interface, error)
APIClientsetProvider defines a func type that initializes and return a new kubernetes Clientset object.
type Association ¶
type Association struct {
Name string
Sources []AssociationSource
}
Association represents one association rule
type AssociationSource ¶ added in v0.55.0
type Associations ¶
type Associations struct {
Associations []Association
}
Associations represent a list of rules for Pod metadata associations with resources
type Client ¶
type Client interface {
GetPod(PodIdentifier) (*Pod, bool)
GetNamespace(string) (*Namespace, bool)
Start()
Stop()
}
Client defines the main interface that allows querying pods by metadata.
func New ¶
func New(logger *zap.Logger, apiCfg k8sconfig.APIConfig, rules ExtractionRules, filters Filters, associations []Association, exclude Excludes, newClientSet APIClientsetProvider, newInformer InformerProvider, newNamespaceInformer InformerProviderNamespace) (Client, error)
New initializes a new k8s Client.
type ClientProvider ¶
type ClientProvider func(*zap.Logger, k8sconfig.APIConfig, ExtractionRules, Filters, []Association, Excludes, APIClientsetProvider, InformerProvider, InformerProviderNamespace) (Client, error)
ClientProvider defines a func type that returns a new Client.
type Container ¶
type Container struct {
Name string
ImageName string
ImageTag string
// Statuses is a map of container k8s.container.restart_count attribute to ContainerStatus struct.
Statuses map[int]ContainerStatus
}
Container stores resource attributes for a specific container defined by k8s pod spec.
type ContainerStatus ¶
type ContainerStatus struct {
ContainerID string
}
ContainerStatus stores resource attributes for a particular container run defined by k8s pod status.
type ExcludePods ¶
ExcludePods represent a Pod name to ignore
type Excludes ¶
type Excludes struct {
Pods []ExcludePods
}
Excludes represent a list of Pods to ignore
type ExtractionRules ¶
type ExtractionRules struct {
CronJobName bool
Deployment bool
DaemonSetUID bool
DaemonSetName bool
JobUID bool
JobName bool
Namespace bool
PodName bool
PodUID bool
PodHostName bool
ReplicaSetID bool
ReplicaSetName bool
StatefulSetUID bool
StatefulSetName bool
Node bool
StartTime bool
ContainerName bool
ContainerID bool
ContainerImageName bool
ContainerImageTag bool
Annotations []FieldExtractionRule
Labels []FieldExtractionRule
}
ExtractionRules is used to specify the information that needs to be extracted from pods and added to the spans as tags.
type FakeController ¶
func (*FakeController) HasStopped ¶
func (c *FakeController) HasStopped() bool
func (*FakeController) HasSynced ¶
func (c *FakeController) HasSynced() bool
func (*FakeController) LastSyncResourceVersion ¶
func (c *FakeController) LastSyncResourceVersion() string
func (*FakeController) Run ¶
func (c *FakeController) Run(stopCh <-chan struct{})
type FakeInformer ¶
type FakeInformer struct {
*FakeController
// contains filtered or unexported fields
}
func (*FakeInformer) AddEventHandler ¶
func (f *FakeInformer) AddEventHandler(handler cache.ResourceEventHandler) (cache.ResourceEventHandlerRegistration, error)
func (*FakeInformer) AddEventHandlerWithResyncPeriod ¶
func (f *FakeInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, resyncPeriod time.Duration) (cache.ResourceEventHandlerRegistration, error)
func (*FakeInformer) GetController ¶
func (f *FakeInformer) GetController() cache.Controller
func (*FakeInformer) GetStore ¶
func (f *FakeInformer) GetStore() cache.Store
func (*FakeInformer) IsStopped ¶ added in v0.68.0
func (f *FakeInformer) IsStopped() bool
func (*FakeInformer) RemoveEventHandler ¶ added in v0.68.0
func (f *FakeInformer) RemoveEventHandler(handle cache.ResourceEventHandlerRegistration) error
func (*FakeInformer) SetTransform ¶ added in v0.51.0
func (f *FakeInformer) SetTransform(handler cache.TransformFunc) error
func (*FakeInformer) SetWatchErrorHandler ¶
func (f *FakeInformer) SetWatchErrorHandler(cache.WatchErrorHandler) error
type FakeNamespaceInformer ¶
type FakeNamespaceInformer struct {
*FakeController
}
func (*FakeNamespaceInformer) AddEventHandler ¶
func (f *FakeNamespaceInformer) AddEventHandler(handler cache.ResourceEventHandler)
func (*FakeNamespaceInformer) AddEventHandlerWithResyncPeriod ¶
func (f *FakeNamespaceInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, period time.Duration)
func (*FakeNamespaceInformer) GetController ¶
func (f *FakeNamespaceInformer) GetController() cache.Controller
func (*FakeNamespaceInformer) GetStore ¶
func (f *FakeNamespaceInformer) GetStore() cache.Store
type FieldExtractionRule ¶
type FieldExtractionRule struct {
// Name is used to as the Span tag name.
Name string
// Key is used to lookup k8s pod fields.
Key string
// KeyRegex is a regular expression(full length match) used to extract a Key that matches the regex.
KeyRegex *regexp.Regexp
HasKeyRegexReference bool
// Regex is a regular expression used to extract a sub-part of a field value.
// Full value is extracted when no regexp is provided.
Regex *regexp.Regexp
// From determines the kubernetes object the field should be retrieved from.
// Currently only two values are supported,
// - pod
// - namespace
From string
}
FieldExtractionRule is used to specify which fields to extract from pod fields and inject into spans as attributes.
type FieldFilter ¶
type FieldFilter struct {
// Key matches the field name.
Key string
// Value matches the field value.
Value string
// Op determines the matching operation.
// Currently only two operations are supported,
// - Equals
// - NotEquals
Op selection.Operator
}
FieldFilter represents exactly one filter by field rule.
type Filters ¶
type Filters struct {
Node string
Namespace string
Fields []FieldFilter
Labels []FieldFilter
}
Filters is used to instruct the client on how to filter out k8s pods. Right now only filters supported are the ones supported by k8s API itself for performance reasons. We can support adding additional custom filters in future if there is a real need.
type InformerProvider ¶
type InformerProvider func( client kubernetes.Interface, namespace string, labelSelector labels.Selector, fieldSelector fields.Selector, ) cache.SharedInformer
InformerProvider defines a function type that returns a new SharedInformer. It is used to allow passing custom shared informers to the watch client.
type InformerProviderNamespace ¶
type InformerProviderNamespace func( client kubernetes.Interface, ) cache.SharedInformer
InformerProviderNamespace defines a function type that returns a new SharedInformer. It is used to allow passing custom shared informers to the watch client for fetching namespace objects.
type Namespace ¶
type Namespace struct {
Name string
NamespaceUID string
Attributes map[string]string
StartTime metav1.Time
DeletedAt time.Time
}
Namespace represents a kubernetes namespace.
type NoOpController ¶
type NoOpController struct {
// contains filtered or unexported fields
}
func (*NoOpController) HasSynced ¶
func (c *NoOpController) HasSynced() bool
func (*NoOpController) IsStopped ¶ added in v0.68.0
func (c *NoOpController) IsStopped() bool
func (*NoOpController) LastSyncResourceVersion ¶
func (c *NoOpController) LastSyncResourceVersion() string
func (*NoOpController) Run ¶
func (c *NoOpController) Run(stopCh <-chan struct{})
func (*NoOpController) SetWatchErrorHandler ¶
func (c *NoOpController) SetWatchErrorHandler(cache.WatchErrorHandler) error
type NoOpInformer ¶
type NoOpInformer struct {
*NoOpController
}
func (*NoOpInformer) AddEventHandler ¶
func (f *NoOpInformer) AddEventHandler(handler cache.ResourceEventHandler) (cache.ResourceEventHandlerRegistration, error)
func (*NoOpInformer) AddEventHandlerWithResyncPeriod ¶
func (f *NoOpInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, resyncPeriod time.Duration) (cache.ResourceEventHandlerRegistration, error)
func (*NoOpInformer) GetController ¶
func (f *NoOpInformer) GetController() cache.Controller
func (*NoOpInformer) GetStore ¶
func (f *NoOpInformer) GetStore() cache.Store
func (*NoOpInformer) RemoveEventHandler ¶ added in v0.68.0
func (f *NoOpInformer) RemoveEventHandler(handle cache.ResourceEventHandlerRegistration) error
func (*NoOpInformer) SetTransform ¶ added in v0.51.0
func (f *NoOpInformer) SetTransform(handler cache.TransformFunc) error
type Pod ¶
type Pod struct {
Name string
Address string
PodUID string
Attributes map[string]string
StartTime *metav1.Time
Ignore bool
Namespace string
HostNetwork bool
// Containers specifies all containers in this pod.
Containers PodContainers
DeletedAt time.Time
}
Pod represents a kubernetes pod.
type PodContainers ¶ added in v0.76.1
type PodContainers struct {
// ByID specifies all containers in a pod by container ID.
ByID map[string]*Container
// ByName specifies all containers in a pod by container name (k8s.container.name).
ByName map[string]*Container
}
PodContainers specifies a list of pod containers. It is not safe for concurrent use.
type PodIdentifier ¶
type PodIdentifier [PodIdentifierMaxLength]PodIdentifierAttribute
PodIdentifier is a custom type to represent Pod identification
func (*PodIdentifier) IsNotEmpty ¶ added in v0.55.0
func (p *PodIdentifier) IsNotEmpty() bool
IsNotEmpty checks if PodIdentifier is empty or not
type PodIdentifierAttribute ¶ added in v0.55.0
type PodIdentifierAttribute struct {
Source AssociationSource
Value string
}
PodIdentifierAttribute represents AssociationSource with matching value for pod
func PodIdentifierAttributeFromConnection ¶ added in v0.55.0
func PodIdentifierAttributeFromConnection(value string) PodIdentifierAttribute
PodIdentifierAttributeFromSource builds PodIdentifierAttribute for connection with given value
func PodIdentifierAttributeFromResourceAttribute ¶ added in v0.55.0
func PodIdentifierAttributeFromResourceAttribute(key string, value string) PodIdentifierAttribute
PodIdentifierAttributeFromSource builds PodIdentifierAttribute for given resource_attribute name and value
func PodIdentifierAttributeFromSource ¶ added in v0.55.0
func PodIdentifierAttributeFromSource(source AssociationSource, value string) PodIdentifierAttribute
PodIdentifierAttributeFromSource builds PodIdentifierAttribute using AssociationSource and value
type WatchClient ¶
type WatchClient struct {
// A map containing Pod related data, used to associate them with resources.
// Key can be either an IP address or Pod UID
Pods map[PodIdentifier]*Pod
Rules ExtractionRules
Filters Filters
Associations []Association
Exclude Excludes
// A map containing Namespace related data, used to associate them with resources.
// Key is namespace name
Namespaces map[string]*Namespace
// contains filtered or unexported fields
}
WatchClient is the main interface provided by this package to a kubernetes cluster.
func (*WatchClient) GetNamespace ¶
func (c *WatchClient) GetNamespace(namespace string) (*Namespace, bool)
GetNamespace takes a namespace and returns the namespace object the namespace is associated with.
func (*WatchClient) GetPod ¶
func (c *WatchClient) GetPod(identifier PodIdentifier) (*Pod, bool)
GetPod takes an IP address or Pod UID and returns the pod the identifier is associated with.
func (*WatchClient) Start ¶
func (c *WatchClient) Start()
Start registers pod event handlers and starts watching the kubernetes cluster for pod changes.
func (*WatchClient) Stop ¶
func (c *WatchClient) Stop()
Stop signals the the k8s watcher/informer to stop watching for new events.