observer

package module
v0.116.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 8 Imported by: 6

README

Observers

Observers are implemented as an extension to discover networked endpoints like a Kubernetes pod, Docker container, or local listening port. Other components can subscribe to an observer instance to be notified of endpoints coming and going.

Currently the only component that uses observers is the receiver_creator.

Current Observers

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container added in v0.32.0

type Container struct {
	// Name is the primary name of the container
	Name string
	// Image is the name of the container image
	Image string
	// Tag is the container image tag, e.g. '0.1'
	Tag string
	// Port is the exposed port of container
	Port uint16
	// AlternatePort is the exposed port accessed through some kind of redirection,
	// such as Docker port redirection
	AlternatePort uint16
	// Command used to invoke the process using the Endpoint.
	Command string
	// ContainerID is the id of the container exposing the Endpoint.
	ContainerID string
	// Host is the hostname/ip address of the Endpoint.
	Host string
	// Transport is the transport protocol used by the Endpoint. (TCP or UDP).
	Transport Transport
	// Labels is a map of user-specified metadata on the container.
	Labels map[string]string
}

Container is a discovered container

func (*Container) Env added in v0.32.0

func (c *Container) Env() EndpointEnv

func (*Container) Type added in v0.32.0

func (c *Container) Type() EndpointType

type Endpoint

type Endpoint struct {
	// ID uniquely identifies this endpoint.
	ID EndpointID
	// Target is an IP address or hostname of the endpoint. It can also be a hostname/ip:port pair.
	Target string
	// Details contains additional context about the endpoint such as a Pod or Port.
	Details EndpointDetails
}

Endpoint is a service that can be contacted remotely.

func (*Endpoint) Env added in v0.19.0

func (e *Endpoint) Env() (EndpointEnv, error)

Env converts an endpoint into a map suitable for expr evaluation.

func (*Endpoint) String

func (e *Endpoint) String() string

type EndpointDetails added in v0.19.0

type EndpointDetails interface {
	Env() EndpointEnv
	Type() EndpointType
}

EndpointDetails provides additional context about an endpoint such as a Pod or Port.

type EndpointEnv added in v0.7.0

type EndpointEnv map[string]any

EndpointEnv is a map of endpoint attributes.

type EndpointID added in v0.7.0

type EndpointID string

EndpointID unique identifies an endpoint per-observer instance.

type EndpointType added in v0.19.0

type EndpointType string

EndpointType is a type of an endpoint like a port or pod.

const (
	// PortType is a port endpoint.
	PortType EndpointType = "port"
	// PodType is a pod endpoint.
	PodType EndpointType = "pod"
	// PodContainerType is a pod's container endpoint.
	PodContainerType EndpointType = "pod.container"
	// K8sServiceType is a service endpoint.
	K8sServiceType EndpointType = "k8s.service"
	// K8sIngressType is a ingress endpoint.
	K8sIngressType EndpointType = "k8s.ingress"
	// K8sNodeType is a Kubernetes Node endpoint.
	K8sNodeType EndpointType = "k8s.node"
	// HostPortType is a hostport endpoint.
	HostPortType EndpointType = "hostport"
	// ContainerType is a container endpoint.
	ContainerType EndpointType = "container"
)

type EndpointsLister added in v0.7.0

type EndpointsLister interface {
	// ListEndpoints provides a list of endpoints and is expected to be
	// implemented by an observer looking for endpoints.
	ListEndpoints() []Endpoint
}

EndpointsLister that provides a list of endpoints.

type EndpointsWatcher added in v0.7.0

type EndpointsWatcher struct {
	EndpointsLister EndpointsLister
	RefreshInterval time.Duration
	// contains filtered or unexported fields
}

EndpointsWatcher provides a generic mechanism to run EndpointsLister.ListEndpoints every RefreshInterval and report any new or removed endpoints to Notify instances registered via ListAndWatch. Any observer that lists endpoints can make use of EndpointsWatcher to poll for endpoints by embedding this struct and using NewEndpointsWatcher().

func NewEndpointsWatcher added in v0.58.0

func NewEndpointsWatcher(endpointsLister EndpointsLister, refreshInterval time.Duration, logger *zap.Logger) *EndpointsWatcher

func (*EndpointsWatcher) ListAndWatch added in v0.7.0

func (ew *EndpointsWatcher) ListAndWatch(notify Notify)

ListAndWatch runs EndpointsLister.ListEndpoints() on a regular interval and keeps track of the results for alerting all subscribed Notify's of the based on the differences from the previous call.

func (*EndpointsWatcher) StopListAndWatch added in v0.7.0

func (ew *EndpointsWatcher) StopListAndWatch()

StopListAndWatch polling the ListEndpoints.

func (*EndpointsWatcher) Unsubscribe added in v0.58.0

func (ew *EndpointsWatcher) Unsubscribe(notify Notify)

type HostPort added in v0.7.0

type HostPort struct {
	// ProcessName of the process associated to Endpoint.  If host_observer
	// is unable to collect information about process using the
	// Port, this value is an empty string.
	ProcessName string
	// Command used to invoke the process using the Endpoint.
	Command string
	// Port number of the endpoint.
	Port uint16
	// Transport is the transport protocol used by the Endpoint. (TCP or UDP).
	Transport Transport
	// IsIPv6 indicates whether or not the Endpoint is IPv6.
	IsIPv6 bool
}

HostPort is an endpoint discovered on a host.

func (*HostPort) Env added in v0.19.0

func (h *HostPort) Env() EndpointEnv

func (*HostPort) Type added in v0.19.0

func (h *HostPort) Type() EndpointType

type K8sIngress added in v0.104.0

type K8sIngress struct {
	// Name of the ingress.
	Name string
	// UID is the unique ID in the cluster for the ingress.
	UID string
	// Labels is a map of user-specified metadata.
	Labels map[string]string
	// Annotations is a map of user-specified metadata.
	Annotations map[string]string
	// Namespace must be unique for ingress with same name.
	Namespace string
	// Scheme represents whether the ingress path is accessible via HTTPS or HTTP.
	Scheme string
	// Host is the fully qualified domain name of a network host
	Host string
	// Path that map requests to backends
	Path string
}

K8sIngress is a discovered k8s ingress.

func (*K8sIngress) Env added in v0.104.0

func (s *K8sIngress) Env() EndpointEnv

func (*K8sIngress) Type added in v0.104.0

func (s *K8sIngress) Type() EndpointType

type K8sNode added in v0.42.0

type K8sNode struct {
	// Name is the name of the Kubernetes Node.
	Name string
	// UID is the unique ID for the node
	UID string
	// Hostname is the node hostname as reported by the status object
	Hostname string
	// ExternalIP is the node's external IP address as reported by the Status object
	ExternalIP string
	// InternalIP is the node internal IP address as reported by the Status object
	InternalIP string
	// ExternalDNS is the node's external DNS record as reported by the Status object
	ExternalDNS string
	// InternalDNS is the node's internal DNS record as reported by the Status object
	InternalDNS string
	// Annotations is an arbitrary key-value map of non-identifying, user-specified node metadata
	Annotations map[string]string
	// Labels is the map of identifying, user-specified node metadata
	Labels map[string]string
	// KubeletEndpointPort is the node status object's DaemonEndpoints.KubeletEndpoint.Port value
	KubeletEndpointPort uint16
}

K8sNode represents a Kubernetes Node object: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/k8s.md#node

func (*K8sNode) Env added in v0.42.0

func (n *K8sNode) Env() EndpointEnv

func (*K8sNode) Type added in v0.42.0

func (n *K8sNode) Type() EndpointType

type K8sService added in v0.90.0

type K8sService struct {
	// Name of the service.
	Name string
	// UID is the unique ID in the cluster for the service.
	UID string
	// Labels is a map of user-specified metadata.
	Labels map[string]string
	// Annotations is a map of user-specified metadata.
	Annotations map[string]string
	// Namespace must be unique for services with same name.
	Namespace string
	// ClusterIP is the IP under which the service is reachable within the cluster.
	ClusterIP string
	// ServiceType is the type of the service: ClusterIP, NodePort, LoadBalancer, ExternalName
	ServiceType string
}

K8sService is a discovered k8s service.

func (*K8sService) Env added in v0.90.0

func (s *K8sService) Env() EndpointEnv

func (*K8sService) Type added in v0.90.0

func (s *K8sService) Type() EndpointType

type Notify

type Notify interface {
	// ID must be unique for each Notify implementer instance and is for registration purposes.
	ID() NotifyID
	// OnAdd is called once or more initially for state sync as well as when further endpoints are added.
	OnAdd(added []Endpoint)
	// OnRemove is called when one or more endpoints are removed.
	OnRemove(removed []Endpoint)
	// OnChange is called when one or more endpoints are modified but the identity is not changed
	// (e.g. labels).
	OnChange(changed []Endpoint)
}

Notify is the callback for Observer events.

type NotifyID added in v0.58.0

type NotifyID string

type Observable

type Observable interface {
	// ListAndWatch provides initial state sync as well as change notification.
	// notify. OnAdd will be called one or more times if there are endpoints discovered.
	// (It would not be called if there are no endpoints present.) The endpoint synchronization
	// happens asynchronously to this call.
	ListAndWatch(notify Notify)

	// Unsubscribe stops the previously registered Notify from receiving callback invocations.
	Unsubscribe(notify Notify)
}

Observable is an interface that provides notification of endpoint changes.

type Pod

type Pod struct {
	// Name of the pod.
	Name string
	// UID is the unique ID in the cluster for the pod.
	UID string
	// Labels is a map of user-specified metadata.
	Labels map[string]string
	// Annotations is a map of user-specified metadata.
	Annotations map[string]string
	// Namespace must be unique for pods with same name.
	Namespace string
}

Pod is a discovered k8s pod.

func (*Pod) Env added in v0.19.0

func (p *Pod) Env() EndpointEnv

func (*Pod) Type added in v0.19.0

func (p *Pod) Type() EndpointType

type PodContainer added in v0.112.0

type PodContainer struct {
	// Name of the container
	Name string `mapstructure:"container_name"`
	// Image of the container
	Image string `mapstructure:"container_image"`
	// ContainerID is the id of the container exposing the Endpoint
	ContainerID string `mapstructure:"container_id"`
	// Pod is the k8s pod in which the container is running
	Pod Pod
}

PodContainer is a discovered k8s pod's container

func (*PodContainer) Env added in v0.112.0

func (p *PodContainer) Env() EndpointEnv

func (*PodContainer) Type added in v0.112.0

func (p *PodContainer) Type() EndpointType

type Port

type Port struct {
	// Name is the name of the container port.
	Name string
	// Pod is the k8s pod in which the container is running.
	Pod Pod
	// Port number of the endpoint.
	Port uint16
	// Transport is the transport protocol used by the Endpoint. (TCP or UDP).
	Transport Transport
}

Port is an endpoint that has a target as well as a port.

func (*Port) Env added in v0.19.0

func (p *Port) Env() EndpointEnv

func (*Port) Type added in v0.19.0

func (p *Port) Type() EndpointType

type Transport added in v0.7.0

type Transport string

Transport defines protocol for ports.

const (
	// ProtocolTCP is the TCP protocol.
	ProtocolTCP Transport = "TCP"
	// ProtocolTCP4 is the TCP4 protocol.
	ProtocolTCP4 Transport = "TCP4"
	// ProtocolTCP6 is the TCP6 protocol.
	ProtocolTCP6 Transport = "TCP6"
	// ProtocolUDP is the UDP protocol.
	ProtocolUDP Transport = "UDP"
	// ProtocolUDP4 is the UDP4 protocol.
	ProtocolUDP4 Transport = "UDP4"
	// ProtocolUDP6 is the UDP6 protocol.
	ProtocolUDP6 Transport = "UDP6"
	// ProtocolUnknown is some other protocol or it is unknown.
	ProtocolUnknown Transport = "Unknown"
)

Directories

Path Synopsis
ecsobserver module
hostobserver module
k8sobserver module

Jump to

Keyboard shortcuts

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