listeners

package
v0.0.0-...-c4caace Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

README

package listeners

This package is providing the ServiceListener concept to the agent. A ServiceListener listens for events related to services the agent should monitor.

Service

Service represents an application/device we can run an integration against. It should be matched with a config template by the ConfigResolver.

Services can be:

  • Docker containers
  • Containerd containers
  • Kubelet containers
  • Kubelet pods
  • ECS containers
  • Kubernetes Service objects
  • Kubernetes Endpoints objects
  • CloudFoundry containers
  • Network devices

ServiceListener

ServiceListener monitors events related to Service lifecycles. It then formats and transmits this data to AutoConfig.

Note: It's important to enable only one ServiceListener per Service type, for example, in Kubernetes ContainerListener and KubeletListener must not run together because they watch the same containers.

ContainerListener

ContainerListener first gets current running containers and send these to the AutoConfig. Then it starts watching workloadmeta container events and pass by Services mentioned in start/stop events to the AutoConfig through the corresponding channel.

ECSListener

The ECSListener relies on the ECS metadata APIs available within the agent container. We're listening on changes on the container list exposed through the API to discover new Services. This listener is enabled on ECS Fargate only, on ECS EC2 we use the docker listener.

KubeletListener

The KubeletListener relies on the Kubelet API. We're listening on changes on the container list exposed through the API (/pods) to discover new Services. KubeletListener creates Services for containers and pods.

KubeServiceListener

The KubeServiceListener relies on the Kubernetes API server to watch service objects and creates the corresponding Autodiscovery Services. The Datadog Cluster Agent runs this ServiceListener.

KubeEndpointsListener

The KubeEndpointsListener relies on the Kubernetes API server to watch endpoints and service objects, and creates corresponding Autodiscovery Services. The Datadog Cluster Agent runs this ServiceListener.

CloudFoundryListener

The CloudFoundryListener relies on the Cloud Foundry BBS API to detect container changes, and creates corresponding Autodiscovery Services.

SNMPListener

TODO

Listeners & auto-discovery

Template variable support
Listener AD identifiers Host Port Tag Pid Env Hostname
Docker
Containerd
ECS
Kubelet
KubeService
KubeEndpoints

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = errors.New("AD: variable not supported by listener")

ErrNotSupported is thrown if listener doesn't support the asked variable

View Source
var ServiceListenerFactories = make(map[string]ServiceListenerFactory)

ServiceListenerFactories holds the registered factories

Functions

func ComputeContainerServiceIDs

func ComputeContainerServiceIDs(entity string, image string, labels map[string]string) []string

ComputeContainerServiceIDs takes an entity name, an image (resolved to an actual name) and labels and computes the service IDs for this container service.

func Register

func Register(name string, factory ServiceListenerFactory)

Register registers a service listener factory

Types

type ContainerListener

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

ContainerListener listens to container creation through a subscription to the workloadmeta store.

type ContainerPort

type ContainerPort struct {
	Port int
	Name string
}

ContainerPort represents a network port in a Service.

type ECSFargateListener

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

ECSFargateListener listens to container creation through a subscription to the workloadmeta store.

type EnvironmentListener

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

EnvironmentListener implements a ServiceListener based on current environment

func (*EnvironmentListener) Listen

func (l *EnvironmentListener) Listen(newSvc chan<- Service, delSvc chan<- Service)

Listen starts the goroutine to detect checks based on environment

func (*EnvironmentListener) Stop

func (l *EnvironmentListener) Stop()

Stop has nothing to do in this case

type EnvironmentService

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

EnvironmentService represents services generated from EnvironmentListener

func (*EnvironmentService) GetADIdentifiers

func (s *EnvironmentService) GetADIdentifiers(context.Context) ([]string, error)

GetADIdentifiers return the single AD identifier for an environment service

func (*EnvironmentService) GetCheckNames

func (s *EnvironmentService) GetCheckNames(context.Context) []string

GetCheckNames is not supported

func (*EnvironmentService) GetCreationTime

func (s *EnvironmentService) GetCreationTime() integration.CreationTime

GetCreationTime is always before for environment service

func (*EnvironmentService) GetEntity

func (s *EnvironmentService) GetEntity() string

GetEntity returns the unique entity name linked to that service

func (*EnvironmentService) GetExtraConfig

func (s *EnvironmentService) GetExtraConfig(key []byte) ([]byte, error)

GetExtraConfig is not supported

func (*EnvironmentService) GetHostname

func (s *EnvironmentService) GetHostname(context.Context) (string, error)

GetHostname returns nil and an error because port is not supported in this listener

func (*EnvironmentService) GetHosts

func (s *EnvironmentService) GetHosts(context.Context) (map[string]string, error)

GetHosts is not supported

func (*EnvironmentService) GetPid

func (s *EnvironmentService) GetPid(context.Context) (int, error)

GetPid inspect the container and return its pid Not relevant in this listener

func (*EnvironmentService) GetPorts

GetPorts returns nil and an error because port is not supported in this listener

func (*EnvironmentService) GetTaggerEntity

func (s *EnvironmentService) GetTaggerEntity() string

GetTaggerEntity returns the tagger entity

func (*EnvironmentService) GetTags

func (s *EnvironmentService) GetTags() ([]string, string, error)

GetTags retrieves a container's tags

func (*EnvironmentService) HasFilter

func (s *EnvironmentService) HasFilter(filter containers.FilterType) bool

HasFilter is not supported

func (*EnvironmentService) IsReady

func (s *EnvironmentService) IsReady(context.Context) bool

IsReady is always true

type KubeletListener

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

KubeletListener listens to pod creation through a subscription to the workloadmeta store.

type SNMPListener

type SNMPListener struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SNMPListener implements SNMP discovery

func (*SNMPListener) Listen

func (l *SNMPListener) Listen(newSvc chan<- Service, delSvc chan<- Service)

Listen periodically refreshes devices

func (*SNMPListener) Stop

func (l *SNMPListener) Stop()

Stop queues a shutdown of SNMPListener

type SNMPService

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

SNMPService implements and store results from the Service interface for the SNMP listener

func (*SNMPService) GetADIdentifiers

func (s *SNMPService) GetADIdentifiers(context.Context) ([]string, error)

GetADIdentifiers returns a set of AD identifiers

func (*SNMPService) GetCheckNames

func (s *SNMPService) GetCheckNames(context.Context) []string

GetCheckNames returns nil

func (*SNMPService) GetCreationTime

func (s *SNMPService) GetCreationTime() integration.CreationTime

GetCreationTime returns the creation time of the Service

func (*SNMPService) GetEntity

func (s *SNMPService) GetEntity() string

GetEntity returns the unique entity ID linked to that service

func (*SNMPService) GetExtraConfig

func (s *SNMPService) GetExtraConfig(key []byte) ([]byte, error)

GetExtraConfig returns data from configuration

func (*SNMPService) GetHostname

func (s *SNMPService) GetHostname(context.Context) (string, error)

GetHostname returns nothing - not supported

func (*SNMPService) GetHosts

func (s *SNMPService) GetHosts(context.Context) (map[string]string, error)

GetHosts returns the device IP

func (*SNMPService) GetPid

func (s *SNMPService) GetPid(context.Context) (int, error)

GetPid returns nil and an error because pids are currently not supported

func (*SNMPService) GetPorts

func (s *SNMPService) GetPorts(context.Context) ([]ContainerPort, error)

GetPorts returns the device port

func (*SNMPService) GetTaggerEntity

func (s *SNMPService) GetTaggerEntity() string

GetTaggerEntity returns the unique entity ID linked to that service

func (*SNMPService) GetTags

func (s *SNMPService) GetTags() ([]string, string, error)

GetTags returns the list of container tags - currently always empty

func (*SNMPService) HasFilter

func (s *SNMPService) HasFilter(filter containers.FilterType) bool

HasFilter returns false on SNMP

func (*SNMPService) IsReady

func (s *SNMPService) IsReady(context.Context) bool

IsReady returns true

type Service

type Service interface {
	GetEntity() string                                   // unique entity name
	GetTaggerEntity() string                             // tagger entity name
	GetADIdentifiers(context.Context) ([]string, error)  // identifiers on which templates will be matched
	GetHosts(context.Context) (map[string]string, error) // network --> IP address
	GetPorts(context.Context) ([]ContainerPort, error)   // network ports
	GetTags() ([]string, string, error)                  // tags and tags hash
	GetPid(context.Context) (int, error)                 // process identifier
	GetHostname(context.Context) (string, error)         // hostname.domainname for the entity
	GetCreationTime() integration.CreationTime           // created before or after the agent start
	IsReady(context.Context) bool                        // is the service ready
	GetCheckNames(context.Context) []string              // slice of check names defined in kubernetes annotations or container labels
	HasFilter(containers.FilterType) bool                // whether the service is excluded by metrics or logs exclusion config
	GetExtraConfig([]byte) ([]byte, error)               // Extra configuration values
}

Service represents an application we can run a check against. It should be matched with a check template by the ConfigResolver using the ADIdentifiers field.

type ServiceListener

type ServiceListener interface {
	Listen(newSvc, delSvc chan<- Service)
	Stop()
}

ServiceListener monitors running services and triggers check (un)scheduling

It holds a cache of running services, listens to new/killed services and updates its cache, and the AutoConfig with these events.

func NewContainerListener

func NewContainerListener() (ServiceListener, error)

NewContainerListener returns a new ContainerListener.

func NewECSFargateListener

func NewECSFargateListener() (ServiceListener, error)

NewECSFargateListener returns a new ECSFargateListener.

func NewEnvironmentListener

func NewEnvironmentListener() (ServiceListener, error)

NewEnvironmentListener creates an EnvironmentListener

func NewKubeletListener

func NewKubeletListener() (ServiceListener, error)

NewKubeletListener returns a new KubeletListener.

func NewSNMPListener

func NewSNMPListener() (ServiceListener, error)

NewSNMPListener creates a SNMPListener

type ServiceListenerFactory

type ServiceListenerFactory func() (ServiceListener, error)

ServiceListenerFactory builds a service listener

Jump to

Keyboard shortcuts

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