Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[autodiscovery] Add ignore_autodiscovery_tags config parameter #4521

Merged
merged 4 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions pkg/autodiscovery/configresolver/configresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,36 @@ 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 {
if err := SubstituteTemplateVariables(&resolvedConfig, templateVariables, svc); err != nil {
return resolvedConfig, err
}

err = SubstituteTemplateVariables(&resolvedConfig, templateVariables, svc)
if err != nil {
return resolvedConfig, err
}

err = SubstituteTemplateEnvVars(&resolvedConfig)
if err != nil {
if err := SubstituteTemplateEnvVars(&resolvedConfig); err != nil {
// We add the service name to the error here, since SubstituteTemplateEnvVars doesn't know about that
return resolvedConfig, fmt.Errorf("%s, skipping service %s", err, svc.GetEntity())
}

if !tpl.IgnoreAutodiscoveryTags {
if err := addServiceTags(&resolvedConfig, svc); err != nil {
return resolvedConfig, fmt.Errorf("unable to add tags for service '%s', err: %s", svc.GetEntity(), err)
}
}

return resolvedConfig, nil
}

func addServiceTags(resolvedConfig *integration.Config, svc listeners.Service) error {
tags, err := svc.GetTags()
if err != nil {
return err
}
for i := 0; i < len(resolvedConfig.Instances); i++ {
err = resolvedConfig.Instances[i].MergeAdditionalTags(tags)
if err != nil {
return resolvedConfig, err
return err
}
}
return resolvedConfig, nil
return nil
}

func getHost(tplVar []byte, svc listeners.Service) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/autodiscovery/configresolver/configresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func TestResolve(t *testing.T) {
ADIdentifiers: []string{"redis"},
Instances: []integration.Data{integration.Data("host: %%FOO%%")},
},
errorString: "yaml: found character that cannot start any token",
errorString: "unable to add tags for service 'a5901276aed1', err: yaml: found character that cannot start any token",
},
}
validTemplates := 0
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
IgnoreAutodiscoveryTags bool `json:"ignore_autodiscovery_tags"` // Use to ignore tags coming from autodiscovery
}

// 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
IgnoreAutodiscoveryTags bool `yaml:"ignore_autodiscovery_tags"` // Use to ignore tags coming from autodiscovery
}

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_autodiscovery_tags parameter
config.IgnoreAutodiscoveryTags = cf.IgnoreAutodiscoveryTags

// 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_autodiscovery_tags` parameter config check.

In some cases, a check should not receive tags coming from the autodiscovery listeners.
By default `ignore_autodiscovery_tags` is set to false which doesn't change the behavior of the checks.
The first check that will use it is `kubernetes_state`.