Skip to content

Commit

Permalink
[autodiscovery] Add ignore_listener_tags config parameter
Browse files Browse the repository at this point in the history
In some cases, a check should not receive tags coming from the
autodiscovery listeners.
By default `ignore_listener_tags` is set to false which doesn't
change the behavior of the checks.
The first check that will use it is `kubernetes_state`.
  • Loading branch information
clamoriniere committed Nov 28, 2019
1 parent 75ca74a commit 6788551
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
10 changes: 7 additions & 3 deletions pkg/autodiscovery/configresolver/configresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ func Resolve(tpl integration.Config, svc listeners.Service) (integration.Config,
return resolvedConfig, errors.New("unable to resolve, service not ready")
}

tags, err := svc.GetTags()
if err != nil {
return resolvedConfig, err
tags := []string{}
var err error
if !tpl.IgnoreListenerTags {
tags, err = svc.GetTags()
if err != nil {
return resolvedConfig, err
}
}

err = SubstituteTemplateVariables(&resolvedConfig, templateVariables, svc)
Expand Down
27 changes: 14 additions & 13 deletions pkg/autodiscovery/integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ const (

// Config is a generic container for configuration files
type Config struct {
Name string `json:"check_name"` // the name of the check
Instances []Data `json:"instances"` // array of Yaml configurations
InitConfig Data `json:"init_config"` // the init_config in Yaml (python check only)
MetricConfig Data `json:"metric_config"` // the metric config in Yaml (jmx check only)
LogsConfig Data `json:"logs"` // the logs config in Yaml (logs-agent only)
ADIdentifiers []string `json:"ad_identifiers"` // the list of AutoDiscovery identifiers (optional)
Provider string `json:"provider"` // the provider that issued the config
Entity string `json:"-"` // the entity ID (optional)
TaggerEntity string `json:"-"` // the tagger entity ID (optional)
ClusterCheck bool `json:"cluster_check"` // cluster-check configuration flag
NodeName string `json:"node_name"` // node name in case of an endpoint check backed by a pod
CreationTime CreationTime `json:"-"` // creation time of service
Source string `json:"source"` // the source of the configuration
Name string `json:"check_name"` // the name of the check
Instances []Data `json:"instances"` // array of Yaml configurations
InitConfig Data `json:"init_config"` // the init_config in Yaml (python check only)
MetricConfig Data `json:"metric_config"` // the metric config in Yaml (jmx check only)
LogsConfig Data `json:"logs"` // the logs config in Yaml (logs-agent only)
ADIdentifiers []string `json:"ad_identifiers"` // the list of AutoDiscovery identifiers (optional)
Provider string `json:"provider"` // the provider that issued the config
Entity string `json:"-"` // the entity ID (optional)
TaggerEntity string `json:"-"` // the tagger entity ID (optional)
ClusterCheck bool `json:"cluster_check"` // cluster-check configuration flag
NodeName string `json:"node_name"` // node name in case of an endpoint check backed by a pod
CreationTime CreationTime `json:"-"` // creation time of service
Source string `json:"source"` // the source of the configuration
IgnoreListenerTags bool `json:"ignore_listener_tags"` // Use to ignore tags coming from the listener
}

// CommonInstanceConfig holds the reserved fields for the yaml instance data
Expand Down
18 changes: 11 additions & 7 deletions pkg/autodiscovery/providers/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
)

type configFormat struct {
ADIdentifiers []string `yaml:"ad_identifiers"`
ClusterCheck bool `yaml:"cluster_check"`
InitConfig interface{} `yaml:"init_config"`
MetricConfig interface{} `yaml:"jmx_metrics"`
LogsConfig interface{} `yaml:"logs"`
Instances []integration.RawMap
DockerImages []string `yaml:"docker_images"` // Only imported for deprecation warning
ADIdentifiers []string `yaml:"ad_identifiers"`
ClusterCheck bool `yaml:"cluster_check"`
InitConfig interface{} `yaml:"init_config"`
MetricConfig interface{} `yaml:"jmx_metrics"`
LogsConfig interface{} `yaml:"logs"`
Instances []integration.RawMap
DockerImages []string `yaml:"docker_images"` // Only imported for deprecation warning
IgnoreListenerTags bool `yaml:"ignore_listener_tags"` // Use to ignore tags coming from the listener
}

type configPkg struct {
Expand Down Expand Up @@ -302,6 +303,9 @@ func GetIntegrationConfigFromFile(name, fpath string) (integration.Config, error
// Copy cluster_check status
config.ClusterCheck = cf.ClusterCheck

// Copy ignore_listener_tags parameter
config.IgnoreListenerTags = cf.IgnoreListenerTags

// DockerImages entry was found: we ignore it if no ADIdentifiers has been found
if len(cf.DockerImages) > 0 && len(cf.ADIdentifiers) == 0 {
return config, errors.New("the 'docker_images' section is deprecated, please use 'ad_identifiers' instead")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Each section from every releasenote are combined when the
# CHANGELOG.rst is rendered. So the text needs to be worded so that
# it does not depend on any information only available in another
# section. This may mean repeating some details, but each section
# must be readable independently of the other.
#
# Each section note must be formatted as reStructuredText.
---
enhancements:
- |
Add `ignore_listener_tags` parameter config check.
In some cases, a check should not receive tags coming from the autodiscovery listeners.
By default `ignore_listener_tags` is set to false which doesn't change the behavior of the checks.
The first check that will use it is `kubernetes_state`.

0 comments on commit 6788551

Please sign in to comment.