autodiscovery

package
v0.0.0-...-1d9613f Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

README

package autodiscovery

This package is a core piece of the agent. It is responsible for collecting checks configurations from different sources (see package config providers) and then create, update or destroy check instances with the help of the Collector.

It is also responsible for listening to container-related events and trigger check scheduling decisions based on them.

AutoConfig

As a central component, AutoConfig owns and orchestrates several key modules:

  • it owns a reference to the Collector that it uses to (un)schedule checks when template or container updates warrant them
  • it stores a list of ConfigProviders and poll them according to their policy
  • it owns and uses check loaders to load configurations into Check objects
  • it owns listeners that it uses to listen to container lifecycle events
  • it runs the ConfigResolver that resolves a configuration template to an actual configuration based on data it extracts from a service that matches it the template

TODO:

  • pollConfigs needs to send collected templates to ConfigResolver.FreshTemplates.
  • processTemplates needs to work on partial updates and not just full template lists.

ConfigResolver

ConfigResolver resolves configuration templates with services and asks AutoConfig to schedule checks based on this resolving.

To fulfill its task, it stores a cache of services (containers) and templates. It also keeps a live map of how they apply to each other and of the checks that it scheduled as a result.

It also listens on three channels, one for fresh configuration templates, and two for newly started/stopped services.

TODO:

  • ConfigResolver is responsible for too many things. Scheduling should go back to AutoConfig, or get its own module.
  • getters for template variables are all placeholder, they need to be implemented. Tags should just return svc.Tags, host and port should consider key/idx
  • IsConfigMatching is too simple. We need to re-implement the logic of agent5 matching

Documentation

Index

Constants

View Source
const UnknownProvider string = "Unknown provider"

UnknownProvider is used if we can't match the config back to its original provider

Variables

This section is empty.

Functions

func GetConfigErrors

func GetConfigErrors() map[string]string

GetConfigErrors gets the config errors

func GetLoaderErrors

func GetLoaderErrors() map[string]LoaderErrors

GetLoaderErrors gets the errors from the loaderErrors struct

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 is responsible to collect checks configurations from different sources and then create, update or destroy check instances. It owns and orchestrates several key modules:

  • it owns a reference to the `collector.Collector` that it uses to schedule checks when template or container updates warrant them
  • it holds a list of `providers.ConfigProvider`s and poll them according to their policy
  • it holds a list of `check.Loader`s to load configurations into `Check` objects
  • it holds a list of `listeners.ServiceListener`s` used to listen to container lifecycle events
  • it runs the `ConfigResolver` that resolves a configuration template to an actual configuration based on data it extracts from a service that matches it the template

Notice the `AutoConfig` public API speaks in terms of `check.Config`, meaning that you cannot use it to schedule check instances directly.

func NewAutoConfig

func NewAutoConfig(collector *collector.Collector) *AutoConfig

NewAutoConfig creates an AutoConfig instance.

func (*AutoConfig) AddListener

func (ac *AutoConfig) AddListener(listener listeners.ServiceListener)

AddListener adds a service listener to AutoConfig.

func (*AutoConfig) AddLoader

func (ac *AutoConfig) AddLoader(loader check.Loader)

AddLoader adds a new Loader that AutoConfig can use to load a check.

func (*AutoConfig) AddProvider

func (ac *AutoConfig) AddProvider(provider providers.ConfigProvider, shouldPoll bool)

AddProvider adds a new configuration provider to AutoConfig. Callers must pass a flag to indicate whether the configuration provider expects to be polled or it's fine for it to be invoked only once in the Agent lifetime.

func (*AutoConfig) GetChecksByName

func (ac *AutoConfig) GetChecksByName(checkName string) []check.Check

GetChecksByName returns any Check instance we can load for the given check name

func (*AutoConfig) GetProviderLoadedConfigs

func (ac *AutoConfig) GetProviderLoadedConfigs() map[string][]check.Config

GetProviderLoadedConfigs returns configs loaded by provider

func (*AutoConfig) GetUnresolvedTemplates

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

GetUnresolvedTemplates returns templates in cache yet to be resolved

func (*AutoConfig) LoadAndRun

func (ac *AutoConfig) LoadAndRun()

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

func (*AutoConfig) StartPolling

func (ac *AutoConfig) StartPolling()

StartPolling starts the goroutine responsible for polling the providers

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.

type ConfigResolver

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

ConfigResolver stores services and templates in cache, and matches services it hears about with templates to create valid configs. It is also responsible to send scheduling orders to AutoConfig

func (*ConfigResolver) ResolveTemplate

func (cr *ConfigResolver) ResolveTemplate(tpl check.Config) []check.Config

ResolveTemplate attempts to resolve a configuration template using the AD identifiers in the `check.Config` struct to match a Service.

The function might return more than one configuration for a single template, for example when the `ad_identifiers` section of a config.yaml file contains multiple entries, or when more than one Service has the same identifier, e.g. 'redis'.

The function might return an empty list in the case the configuration has a list of Autodiscovery identifiers for services that are unknown to the resolver at this moment.

func (*ConfigResolver) Stop

func (cr *ConfigResolver) Stop()

Stop shuts down the config resolver

type LoaderErrors

type LoaderErrors map[string]string

LoaderErrors is just an alias for a loader->error map

type TemplateCache

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

TemplateCache is a data structure to store configuration templates

func NewTemplateCache

func NewTemplateCache() *TemplateCache

NewTemplateCache creates a new cache

func (*TemplateCache) Del

func (cache *TemplateCache) Del(tpl check.Config) error

Del removes a template from the cache

func (*TemplateCache) Get

func (cache *TemplateCache) Get(adID string) ([]check.Config, error)

Get retrieves a template from the cache

func (*TemplateCache) GetProviderFromDigest

func (cache *TemplateCache) GetProviderFromDigest(digest string) string

GetProviderFromDigest returns the provider name from the config digest

func (*TemplateCache) GetUnresolvedTemplates

func (cache *TemplateCache) GetUnresolvedTemplates() map[string]check.Config

GetUnresolvedTemplates returns templates yet to be resolved

func (*TemplateCache) Set

func (cache *TemplateCache) Set(tpl check.Config, provider string) error

Set stores or updates a template in the cache

Jump to

Keyboard shortcuts

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