observek8sattributesprocessor

package module
v0.0.0-...-d485009 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: Apache-2.0 Imports: 23 Imported by: 1

README

Observe K8s Attributes Processor

This processor operates on K8s resource logs from the k8sobjectsreceiver and adds additional attributes.

Caveats

This processor currently expects the kind field to be set at the base level of the event. In the case of watch events from the k8sobjectsreceiver, this field is instead present inside of the object field. This processor currently expects this field to be lifted from inside the object field to the base level by a transform processor earlier in the pipeline. If that isn't set up, this processor will only calculate status for pull events from the k8sobjectsreceiver.

Emitted Attributes

Attribute Key Description
observe_transform.facets.status The derived Pod status based on the current Pod description.

Documentation

Overview

package observek8sattributesprocessor implements a processor which calculates and attaches additional k8s attributes

Index

Constants

View Source
const (
	IngressRulesAttributeKey        = "rules"
	IngressLoadBalancerAttributeKey = "loadBalancer"
)
View Source
const (
	JobStatusAttributeKey   = "status"
	JobDurationAttributeKey = "duration"
)
View Source
const (
	NodeStatusAttributeKey = "status"

	NodePoolAttributeKey = "nodePool"

	NodeRolesAttributeKey = "roles"
)
View Source
const (
	PodStatusAttributeKey = "status"

	PodContainerRestartsAttributeKey = "restarts"
	PodTotalContainersAttributeKey   = "total_containers"
	PodReadyContainersAttributeKey   = "ready_containers"

	PodReadinessGatesReadyAttributeKey = "readinessGatesReady"
	PodReadinessGatesTotalAttributeKey = "readinessGatesTotal"

	PodConditionsAttributeKey = "conditions"

	PodCronJobNameAttributeKey = "cronJobName"
	OwnerKindCronJob           = "CronJob"

	PodJobNameAttributeKey = "jobName"
	OwnerKindJob           = "Job"

	PodDaemonSetNameAttributeKey = "daemonSetName"
	OwnerKindDaemonSet           = "DaemonSet"

	PodStatefulSetNameAttributeKey = "statefulSetName"
	OwnerKindStatefulSet           = "StatefulSet"
)
View Source
const (
	// CORE
	EventKindPod            = "Pod"
	EventKindNode           = "Node"
	EventKindService        = "Service"
	EventKindServiceAccount = "ServiceAccount"
	EventKindEndpoints      = "Endpoints"
	EventKindConfigMap      = "ConfigMap"
	EventKindSecret         = "Secret"
	// APPS
	EventKindStatefulSet = "StatefulSet"
	EventKindDaemonSet   = "DaemonSet"
	EventKindDeployment  = "Deployment"
	// WORKLOAD
	EventKindJob     = "Job"
	EventKindCronJob = "CronJob"
	// STORAGE
	EventKindPersistentVolume      = "PersistentVolume"
	EventKindPersistentVolumeClaim = "PersistentVolumeClaim"
	// NETWORK
	EventKindIngress = "Ingress"
)
View Source
const (
	ServiceAccountSecretsNamesAttributeKey     = "secretsNames"
	ServiceAccountSecretsAttributeKey          = "secrets"
	ServiceAccountImagePullSecretsAttributeKey = "imagePullSecrets"
)
View Source
const (
	ServiceLBIngressAttributeKey   = "loadBalancerIngress"
	ServiceExternalIPsAttributeKey = "externalIPs"
	ServicePortsAttributeKey       = "ports"
)
View Source
const (
	ConfigMapDataAttributeKey = "data"
)
View Source
const (
	CronJobActiveKey = "activeJobs"
)
View Source
const (
	DaemonSetSelectorAttributeKey = "selector"
)
View Source
const (
	DeploymentSelectorAttributeKey = "selector"
)
View Source
const (
	EnpdointsAttributeKey = "endpoints"
)
View Source
const (
	PersistentVolumeClaimSelectorAttributeKey = "selector"
)
View Source
const (
	PersistentVolumeTypeAttributeKey = "volumeType"
)
View Source
const (
	RedactedSecretValue = "REDACTED"
)
View Source
const (
	StatefulsetSelectorAttributeKey = "selector"
)

Variables

This section is empty.

Functions

func FormatLabels

func FormatLabels(labelMap map[string]string) string

FormatLabels converts label map into plain string

func NewFactory

func NewFactory() processor.Factory

Types

type Config

type Config struct {
}

func (*Config) Validate

func (cfg *Config) Validate() error

type ConfigMapDataAction

type ConfigMapDataAction struct{}

func NewConfigMapDataAction

func NewConfigMapDataAction() ConfigMapDataAction

func (ConfigMapDataAction) ComputeAttributes

func (ConfigMapDataAction) ComputeAttributes(configMap corev1.ConfigMap) (attributes, error)

Generates the ConfigMap "data" facet, calculated as the total number of entries in data and binaryData

type CronJobActiveAction

type CronJobActiveAction struct{}

func NewCronJobActiveAction

func NewCronJobActiveAction() CronJobActiveAction

func (CronJobActiveAction) ComputeAttributes

func (CronJobActiveAction) ComputeAttributes(cronJob batch.CronJob) (attributes, error)

Generates the CronJob "active" facet. This is essentially just the length of a slice. However, since the slice's inner type is not of the accepted ValueTypes for OTTL's Len() function, computing this requires a custom processor

type DaemonSetSelectorAction

type DaemonSetSelectorAction struct{}

func NewDaemonSetSelectorAction

func NewDaemonSetSelectorAction() DaemonSetSelectorAction

func (DaemonSetSelectorAction) ComputeAttributes

func (DaemonSetSelectorAction) ComputeAttributes(daemonset appsv1.DaemonSet) (attributes, error)

Generates the DaemonSet "selector" facet.

type DeploymentSelectorAction

type DeploymentSelectorAction struct{}

func NewDeploymentSelectorAction

func NewDeploymentSelectorAction() DeploymentSelectorAction

func (DeploymentSelectorAction) ComputeAttributes

func (DeploymentSelectorAction) ComputeAttributes(deployment appsv1.Deployment) (attributes, error)

Generates the Deployment "selector" facet.

type EndpointsStatusAction

type EndpointsStatusAction struct{}

func NewEndpointsStatusAction

func NewEndpointsStatusAction() EndpointsStatusAction

func (EndpointsStatusAction) ComputeAttributes

func (EndpointsStatusAction) ComputeAttributes(endpoints corev1.Endpoints) (attributes, error)

Generates the Endpoints "endpoints" facet, which is a list of all individual endpoints, encoded as strings

type IngressLoadBalancerAction

type IngressLoadBalancerAction struct{}

func NewIngressLoadBalancerAction

func NewIngressLoadBalancerAction() IngressLoadBalancerAction

func (IngressLoadBalancerAction) ComputeAttributes

func (IngressLoadBalancerAction) ComputeAttributes(ingress netv1.Ingress) (attributes, error)

Generates the Ingress "loadBalancer" facet.

type IngressRulesAction

type IngressRulesAction struct{}

func NewIngressRulesAction

func NewIngressRulesAction() IngressRulesAction

func (IngressRulesAction) ComputeAttributes

func (IngressRulesAction) ComputeAttributes(ingress netv1.Ingress) (attributes, error)

Generates the Ingress "rules" facet.

type JobDurationAction

type JobDurationAction struct{}

func NewJobDurationAction

func NewJobDurationAction() JobDurationAction

func (JobDurationAction) ComputeAttributes

func (JobDurationAction) ComputeAttributes(job batch.Job) (attributes, error)

Generates the Job "duration" facet. Same logic as kubectl printer

type JobStatusAction

type JobStatusAction struct{}

func NewJobStatusAction

func NewJobStatusAction() JobStatusAction

func (JobStatusAction) ComputeAttributes

func (JobStatusAction) ComputeAttributes(job batch.Job) (attributes, error)

Generates the Job "status" facet. Same logic as kubectl printer https://github.com/kubernetes/kubernetes/blob/0d3b859af81e6a5f869a7766c8d45afd1c600b04/pkg/printers/internalversion/printers.go#L1204

type K8sEvent

type K8sEvent struct {
	Kind       string `json:"kind,omitempty"`
	ApiVersion string `json:"apiVersion,omitempty"`
}

type K8sEventProcessorAction

type K8sEventProcessorAction interface {
	// Computes attributes for a k8s entity.  Since entities like Pod, Node,
	// etc. don't have a common interface, the argument of ComputeAttributes is
	// of type any types that implement this method should check that the arg is
	// of the right type before proceeding.
	// Check the utility functions below for more info
	ComputeAttributes(any) (attributes, error)
}

Action that processes a K8S object and computes custom attributes for it

type K8sEventsProcessor

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

func (*K8sEventsProcessor) RunActions

func (proc *K8sEventsProcessor) RunActions(obj metav1.Object) (attributes, error)

Runs actions that generate new attributes for an (unmarshalled) object.

func (*K8sEventsProcessor) RunBodyActions

func (proc *K8sEventsProcessor) RunBodyActions(obj metav1.Object) (bool, error)

Runs actions that modify parts of the body of this event IN PLACE. Since we want these actions to modify body attributes, these actions intentionally DO NOT DeepCopy() the object and must run BEFORE the actions that generate new attributes. This is useful, for instance, when we want to redact secrets' values, to prevent generating attributes that contain secret's values before redacting them. Returns true if the object was modified by any action, false otherwise

func (*K8sEventsProcessor) Shutdown

func (kep *K8sEventsProcessor) Shutdown(_ context.Context) error

func (*K8sEventsProcessor) Start

type NodePoolAction

type NodePoolAction struct{}

func NewNodePoolAction

func NewNodePoolAction() NodePoolAction

func (NodePoolAction) ComputeAttributes

func (NodePoolAction) ComputeAttributes(node v1.Node) (attributes, error)

Discover the Node "pool" facet. This facet is not provided natively by Kubernetes, so it will be present only when using a managed deployment/service provided by either of the vendors listed above.

type NodeRolesAction

type NodeRolesAction struct{}

func NewNodeRolesAction

func NewNodeRolesAction() NodeRolesAction

func (NodeRolesAction) ComputeAttributes

func (NodeRolesAction) ComputeAttributes(node v1.Node) (attributes, error)

Generates the Node "roles" facet.

type NodeStatusAction

type NodeStatusAction struct{}

func NewNodeStatusAction

func NewNodeStatusAction() NodeStatusAction

func (NodeStatusAction) ComputeAttributes

func (NodeStatusAction) ComputeAttributes(node v1.Node) (attributes, error)

Generates the Node "status" facet. Assumes that objLog is a log from a Node event.

type PersistentVolumeClaimSelectorAction

type PersistentVolumeClaimSelectorAction struct{}

func NewPersistentVolumeClaimSelectorAction

func NewPersistentVolumeClaimSelectorAction() PersistentVolumeClaimSelectorAction

func (PersistentVolumeClaimSelectorAction) ComputeAttributes

func (PersistentVolumeClaimSelectorAction) ComputeAttributes(pvc corev1.PersistentVolumeClaim) (attributes, error)

Generates the PersistentVolumeClaim "selector" facet.

type PersistentVolumeTypeAction

type PersistentVolumeTypeAction struct{}

func NewPersistentVolumeTypeAction

func NewPersistentVolumeTypeAction() PersistentVolumeTypeAction

func (PersistentVolumeTypeAction) ComputeAttributes

func (PersistentVolumeTypeAction) ComputeAttributes(pvc corev1.PersistentVolume) (attributes, error)

Generates the PersistentVolume "type" facet.

type PodConditionsAction

type PodConditionsAction struct{}

Gather all Pod conditions into a single facet named "conditions"

func NewPodConditionsAction

func NewPodConditionsAction() PodConditionsAction

func (PodConditionsAction) ComputeAttributes

func (PodConditionsAction) ComputeAttributes(pod v1.Pod) (attributes, error)

type PodContainersCountsAction

type PodContainersCountsAction struct{}

This action computes various facets for Pod by aggregating "status" values across all containers of a Pod.

We compute more facets into a single action to avoid iterating over the same slice multiple times in different actions.

func NewPodContainersCountsAction

func NewPodContainersCountsAction() PodContainersCountsAction

func (PodContainersCountsAction) ComputeAttributes

func (PodContainersCountsAction) ComputeAttributes(pod v1.Pod) (attributes, error)

type PodCronJobNameAction

type PodCronJobNameAction struct{}

func NewPodCronJobNameAction

func NewPodCronJobNameAction() PodCronJobNameAction

func (PodCronJobNameAction) ComputeAttributes

func (PodCronJobNameAction) ComputeAttributes(pod v1.Pod) (attributes, error)

Name of the cronJob this Pod belongs to (only present if the owner is a CronJob resource)

type PodDaemonSetNameAction

type PodDaemonSetNameAction struct{}

func NewPodDaemonSetNameAction

func NewPodDaemonSetNameAction() PodDaemonSetNameAction

func (PodDaemonSetNameAction) ComputeAttributes

func (PodDaemonSetNameAction) ComputeAttributes(pod v1.Pod) (attributes, error)

Name of the cronJob this Pod belongs to (only present if the owner is a DaemonSet resource)

type PodJobNameAction

type PodJobNameAction struct{}

func NewPodJobAction

func NewPodJobAction() PodJobNameAction

func (PodJobNameAction) ComputeAttributes

func (PodJobNameAction) ComputeAttributes(pod v1.Pod) (attributes, error)

Name of the job this Pod belongs to (only present if the owner is a Job resource)

type PodReadinessAction

type PodReadinessAction struct{}

func NewPodReadinessAction

func NewPodReadinessAction() PodReadinessAction

func (PodReadinessAction) ComputeAttributes

func (PodReadinessAction) ComputeAttributes(pod v1.Pod) (attributes, error)

type PodStatefulSetNameAction

type PodStatefulSetNameAction struct{}

func NewPodStatefulSetNameAction

func NewPodStatefulSetNameAction() PodStatefulSetNameAction

func (PodStatefulSetNameAction) ComputeAttributes

func (PodStatefulSetNameAction) ComputeAttributes(pod v1.Pod) (attributes, error)

Name of the cronJob this Pod belongs to (only present if the owner is a StatefulSet resource)

type PodStatusAction

type PodStatusAction struct{}

func NewPodStatusAction

func NewPodStatusAction() PodStatusAction

func (PodStatusAction) ComputeAttributes

func (PodStatusAction) ComputeAttributes(pod v1.Pod) (attributes, error)

Generates the Pod "status" facet.

type SecretRedactorBodyAction

type SecretRedactorBodyAction struct{}

func NewSecretRedactorBodyAction

func NewSecretRedactorBodyAction() SecretRedactorBodyAction

func (SecretRedactorBodyAction) Modify

func (SecretRedactorBodyAction) Modify(secret *corev1.Secret) error

Redacts secrets' values

type ServiceAccountImagePullSecretsAction

type ServiceAccountImagePullSecretsAction struct{}

func NewServiceAccountImagePullSecretsAction

func NewServiceAccountImagePullSecretsAction() ServiceAccountImagePullSecretsAction

func (ServiceAccountImagePullSecretsAction) ComputeAttributes

func (ServiceAccountImagePullSecretsAction) ComputeAttributes(serviceAccount corev1.ServiceAccount) (attributes, error)

Generates the ServiceAccount "ImagePullSecrets" facet.

type ServiceAccountSecretsAction

type ServiceAccountSecretsAction struct{}

func NewServiceAccountSecretsAction

func NewServiceAccountSecretsAction() ServiceAccountSecretsAction

func (ServiceAccountSecretsAction) ComputeAttributes

func (ServiceAccountSecretsAction) ComputeAttributes(serviceAccount corev1.ServiceAccount) (attributes, error)

Generates the ServiceAccount "secrets" facet.

type ServiceAccountSecretsNamesAction

type ServiceAccountSecretsNamesAction struct{}

func NewServiceAccountSecretsNamesAction

func NewServiceAccountSecretsNamesAction() ServiceAccountSecretsNamesAction

func (ServiceAccountSecretsNamesAction) ComputeAttributes

func (ServiceAccountSecretsNamesAction) ComputeAttributes(serviceAccount corev1.ServiceAccount) (attributes, error)

Generates the ServiceAccount "secretsNames" facet.

type ServiceExternalIPsAction

type ServiceExternalIPsAction struct{}

func NewServiceExternalIPsAction

func NewServiceExternalIPsAction() ServiceExternalIPsAction

func (ServiceExternalIPsAction) ComputeAttributes

func (ServiceExternalIPsAction) ComputeAttributes(service corev1.Service) (attributes, error)

Generates the Service "loadBalancerIngress" facet. We return an array of IPs (even if there's only a single IP) if there is at least one. We set the facet to a string (no array in this case) as follows:

- "None" --> service != LoadBalancer and there are no external IPs - "Pending" --> service is a LoadBalancer and there are no external IPs - "Unknown" --> service is of an unknown type

type ServiceLBIngressAction

type ServiceLBIngressAction struct{}

func NewServiceLBIngressAction

func NewServiceLBIngressAction() ServiceLBIngressAction

func (ServiceLBIngressAction) ComputeAttributes

func (ServiceLBIngressAction) ComputeAttributes(service corev1.Service) (attributes, error)

Generates the Service "loadBalancerIngress" facet.

type ServicePortsAction

type ServicePortsAction struct{}

func NewServicePortsAction

func NewServicePortsAction() ServicePortsAction

func (ServicePortsAction) ComputeAttributes

func (ServicePortsAction) ComputeAttributes(service corev1.Service) (attributes, error)

Generates the Service "ports" facet.

type ServiceSelectorAction

type ServiceSelectorAction struct{}

func NewServiceSelectorAction

func NewServiceSelectorAction() ServiceSelectorAction

func (ServiceSelectorAction) ComputeAttributes

func (ServiceSelectorAction) ComputeAttributes(service corev1.Service) (attributes, error)

Generates the Service "selector" facet.

type Set

type Set map[string]string

func (Set) String

func (ls Set) String() string

String returns all labels listed as a human readable string. Conveniently, exactly the format that ParseSelector takes.

type StatefulSetSelectorAction

type StatefulSetSelectorAction struct{}

func NewStatefulsetSelectorAction

func NewStatefulsetSelectorAction() StatefulSetSelectorAction

func (StatefulSetSelectorAction) ComputeAttributes

func (StatefulSetSelectorAction) ComputeAttributes(statefulSet appsv1.StatefulSet) (attributes, error)

Generates the Statefulset "selector" facet.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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