Skip to content

Service Discovery

Kavashen Pather edited this page May 26, 2019 · 4 revisions

Flex Auto Container Discovery

  • Flex has the capability to auto discovery containers in your surrounding environment, and dynamically monitor them regardless of changing IP addresses and ports
  • See flexContainerDiscovery/ for examples

Also note as an alternative in a Kubernetes environment, service environment variables are passed to every container, so your flex container will have access. Therefore you could even simply use environment variable substitution in a normal config file without using this container discovery feature. Environment variables can be passed into config files by simply using a double dollar sign eg. $$MY_ENVIRONMENT_VAR

Configuration

  -container_discovery
        Enable container auto discovery
  -container_discovery_dir string
        Set directory of auto discovery config files (default "flexContainerDiscovery/")
  -docker_api_version string
        Force Docker client API version

Flex Auto Container Discovery

  • Requires access to /var/run/docker.sock (same as the New Relic Infrastructure Agent, so it is convenient to bake flex into the newrelic/infrastructure image)
  • Add a label or annotation that contains the keyword - "flexDiscovery"
  • For Kubernetes add it as an environment variable
  • To that same label or annotation add a flex discovery configuration eg. "t=redis,c=redis,tt=img,tm=contains"
  • Complete example flexDiscoveryRedis="t=redis,c=redis,tt=img,tm=contains"
  • You could have varying configs on one container as well like flexDiscoveryRedis1, flexDiscoveryZookeeper etc.
  • Flex Container Discovery Configs are placed within "flexContainerDiscovery/" directory
  • For an example see "flexContainerDiscovery/redis.yml"
  • Use ${auto:host} and ${auto:port} anywhere in your config, this will dynamically be substituted per container discovered
  • This makes it possible to have multiple containers re-use the same config with different ip/port configurations
  • You can also instead opt to apply the same environment variable(s) to the Flex container itself, this allows you to monitor other containers without modifying your existing environment
  • If you have configs that overlap between something set on a container, and something set on the Flex container itself, the Flex container will take precedence.
  • Flex uses the environment variables that are presented to the Docker Engine, if you have modified the discovery environment variable(s) after deployment for whatever reason, the Docker Engine will be unaware of these changes.

Flex Discovery Configuration Parameters

  • tt=targetType - are we targeting an img = image or cname = containerName? (default "img")
  • t=target - the keyword to target based on the targetType eg. "redis"
  • tm=targetMode - contains, prefix or regex to match the target (default "contains")
  • c=config - which config file will we use to create the dynamic configs from eg. "redis" .yml (defaults to the "target value")
  • p=port - force set a chosen target port
  • ip=ipMode - default private can be set to public
  • If config is nil, use the target (t), as the yaml file to look up, eg. if target (t) = redis, lookup the config (c) redis.yml if config not set
Clone this wiki locally