autodiscovery

package
v0.0.0-...-2ef719b Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

README

package autodiscovery

This package manages configuration for dynamic entities like pods and containers.

Architecture

The high-level architecture of this package is implemented by the AutoConfig type, and looks like this:

Kubernetes
    API──────┐
             │
Cluster      │ ┌────────────────┐
  Agent────┐ │ │ Workload Meta  │
           │ │ └──┬──────────┬──┘
 Static    │ │    │          │
  Files──┐ │ │    │          │
         │ │ │    │          │
    ┌────▼─▼─▼────▼──┐    ┌──▼─────────────┐
    │Config Providers│    │   Listeners    │
    └──┬─────┬───────┘    └────────┬───────┘
       │     │                     │
       │     │                     │
       │     │templates    services│
       │     └────────► │ ◄────────┤
       │                │          │
       │            reconcile      │
       │                │          │
       │non-template    │          │
       │configs         │          │
       │                │          │
       │                ▼          │
       │         ┌─────────────┐   │
       └────────►│metascheduler│◄──┘
                 └─────────────┘

Config Providers

The config providers draw configuration information from many sources

  • Kubernetes (for Endpoints and Services, run only on the cluster agent)
  • cluster agent (for cluster checks and endpoints checks);
  • static files (conf.d/<integration>.d/conf.yaml); and
  • the workloadmeta service.

The providers extract configuration from entities' tags, labels, etc. in the form of integration.Config values.

Some configs are "templates", meaning that they must be resolved with a service to generate a full, non-template config. Other configs are not templates, and simply contain settings and options for the agent. Specifically, a config is considered a template if it has AD identifiers attached. These are strings that identify the services to which the config applies.

Listeners and Services

The listeners monitor entities, known as "services" in this package, such as pods, containers, or tasks.

Each service has two entity identifiers: the AD service ID (from svc.GetServiceID()) and the Tagger entity (svc.GetTaggerEntity()). These both uniquely identify an entity, but using different syntax.

Service Service ID Tagger Entity
workloadmeta.KindContainer <runtime>://<sha> container_id://<sha>
workloadmeta.KindGardenContainer garden_container://<sha> container_id://<sha>
workloadmeta.KindKubernetesPod kubernetes_pod://<uid> kubernetes_pod_uid://<uid>
workloadmeta.KindECSTask ecs_task://<task-id> ecs_task://<task-id>
CloudFoundry LRP <processGuid>/<svcName>/<instanceGuid> or <appGuid>/<svcName> <processGuid>/<svcName>/<instanceGuid> or <appGuid>/<svcName>
Container runtime or orchestrator _<name> e.g., _containerd (none)
Kubernetes Endpoint kube_endpoint_uid://<namespace>/<name>/<ip> kube_endpoint_uid://<namespace>/<name>/<ip>
Kubernetes Service kube_service://<namespace>/<name> kube_service://<namespace>/<name>
SNMP Config config hash config hash

MetaScheduler

The metascheduler handles notifying consumers of new or removed configs. It can notify in three circumstances:

  1. When a config provider detects a non-template configuration, that is published immediately by the metascheduler.
  2. Whenever template configurations or services change, these are reconciled by matching AD identifiers, any new or removed configs are published by the metascheduler.
  3. For every service, a "service config" -- one with no provider and no configuration -- is published by the metascheduler. Only service configs have an entity defined.

Resolving Templates

Entities that contain their own configuration are reconciled using an AD identifier unique to that entity. For example, a new container might be detected first by a listener, creating a new service with an AD identifier containing its SHA. Soon after, the relevant config provider detects the container, extracts configuration from its labels, and creates an integration.Config containing the same AD identifier.

The reconciliation process combines the service and the Config, resolving the template, and schedules the resolved config. In the process, template variables are expanded based on values from the service. The resulting config is then scheduled with the MetaScheduler.

Documentation

Overview

Package autodiscovery implements the agent's autodiscovery mechanism.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfigErrors

func GetConfigErrors() map[string]string

GetConfigErrors gets the config errors

func GetResolveWarnings

func GetResolveWarnings() map[string][]string

GetResolveWarnings get the resolve warnings/errors

Types

type AutoConfig

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

AutoConfig implements the agent's autodiscovery mechanism. It is responsible to collect integrations configurations from different sources and then "schedule" or "unschedule" them by notifying subscribers. See the module README for details.

func NewAutoConfig

func NewAutoConfig(scheduler *scheduler.MetaScheduler, secretResolver secrets.Component) *AutoConfig

NewAutoConfig creates an AutoConfig instance and starts it.

func NewAutoConfigNoStart

func NewAutoConfigNoStart(scheduler *scheduler.MetaScheduler, secretResolver secrets.Component) *AutoConfig

NewAutoConfigNoStart creates an AutoConfig instance.

func (*AutoConfig) AddConfigProvider

func (ac *AutoConfig) AddConfigProvider(provider providers.ConfigProvider, shouldPoll bool, pollInterval time.Duration)

AddConfigProvider adds a new configuration provider to AutoConfig. Callers must pass a flag to indicate whether the configuration provider expects to be polled and at which interval or it's fine for it to be invoked only once in the Agent lifetime. If the config provider is polled, the routine is scheduled right away

func (*AutoConfig) AddListeners

func (ac *AutoConfig) AddListeners(listenerConfigs []config.Listeners)

AddListeners tries to initialise the listeners listed in the given configs. A first try is done synchronously. If a listener fails with a ErrWillRetry, the initialization will be re-triggered later until success or ErrPermaFail.

func (*AutoConfig) AddScheduler

func (ac *AutoConfig) AddScheduler(name string, s scheduler.Scheduler, replayConfigs bool)

AddScheduler a new scheduler to receive configurations.

Previously scheduled configurations that have not subsequently been unscheduled can be replayed with the replayConfigs flag. This replay occurs immediately, before the AddScheduler call returns.

func (*AutoConfig) ForceRanOnceFlag

func (ac *AutoConfig) ForceRanOnceFlag()

ForceRanOnceFlag sets the ranOnce flag. This is used for testing other components that depend on this value.

func (*AutoConfig) GetAllConfigs

func (ac *AutoConfig) GetAllConfigs() []integration.Config

GetAllConfigs returns all resolved and non-template configs known to AutoConfig.

func (*AutoConfig) GetAutodiscoveryErrors added in v0.9.0

func (ac *AutoConfig) GetAutodiscoveryErrors() map[string]map[string]providers.ErrorMsgSet

GetAutodiscoveryErrors fetches AD errors from each ConfigProvider. The resulting data structure maps provider name to resource name to a set of unique error messages. The resource names do not match other identifiers and are only intended for display in diagnostic tools like `agent status`.

func (*AutoConfig) GetIDOfCheckWithEncryptedSecrets

func (ac *AutoConfig) GetIDOfCheckWithEncryptedSecrets(checkID checkid.ID) checkid.ID

GetIDOfCheckWithEncryptedSecrets returns the ID that a checkID had before decrypting its secrets. Returns empty if the check with the given ID does not have any secrets.

func (*AutoConfig) GetUnresolvedTemplates

func (ac *AutoConfig) GetUnresolvedTemplates() map[string][]integration.Config

GetUnresolvedTemplates returns all templates in the cache, in their unresolved state.

func (*AutoConfig) HasRunOnce added in v0.9.0

func (ac *AutoConfig) HasRunOnce() bool

HasRunOnce returns true if the AutoConfig has ran once.

func (*AutoConfig) LoadAndRun

func (ac *AutoConfig) LoadAndRun(ctx context.Context)

LoadAndRun loads all of the integration configs it can find and schedules them. Should always be run once so providers that don't need polling will be queried at least once

func (*AutoConfig) LoadedConfigs added in v0.9.0

func (ac *AutoConfig) LoadedConfigs() []integration.Config

LoadedConfigs returns a slice of all loaded configs. Loaded configs are non-template configs, either as received from a config provider or as resolved from a template and a service. They do not include service configs.

The returned slice is freshly created and will not be modified after return.

func (*AutoConfig) MapOverLoadedConfigs added in v0.9.0

func (ac *AutoConfig) MapOverLoadedConfigs(f func(map[string]integration.Config))

MapOverLoadedConfigs calls the given function with the map of all loaded configs (those that would be returned from LoadedConfigs).

This is done with the config store locked, so callers should perform minimal work within f.

func (*AutoConfig) RemoveScheduler

func (ac *AutoConfig) RemoveScheduler(name string)

RemoveScheduler allows to remove a scheduler from the AD system.

func (*AutoConfig) Stop

func (ac *AutoConfig) Stop()

Stop just shuts down AutoConfig in a clean way. AutoConfig is not supposed to be restarted, so this is expected to be called only once at program exit.

Directories

Path Synopsis
common
types
Package types implements common structs used in the Autodiscovery code.
Package types implements common structs used in the Autodiscovery code.
utils
Package utils implements helper methods used in the Autodiscovery code.
Package utils implements helper methods used in the Autodiscovery code.
Package configresolver resolves config templates using information from a service.
Package configresolver resolves config templates using information from a service.
Package integration contains the type that represents a configuration.
Package integration contains the type that represents a configuration.
names
Package names defines the name of each config provider ("container", "cluster-checks", "file", etc.).
Package names defines the name of each config provider ("container", "cluster-checks", "file", etc.).
Package scheduler provides the `Scheduler` interface that should be implemented for any scheduler that wants to plug in `autodiscovery`.
Package scheduler provides the `Scheduler` interface that should be implemented for any scheduler that wants to plug in `autodiscovery`.
Package telemetry defines the Autodiscovery telemetry metrics.
Package telemetry defines the Autodiscovery telemetry metrics.

Jump to

Keyboard shortcuts

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