Skip to content

Commit

Permalink
add support for collect_ec2_tags and collect_security_groups options (
Browse files Browse the repository at this point in the history
  • Loading branch information
arbll authored Feb 8, 2018
1 parent b219d79 commit ca6610b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ func init() {

// ECS
Datadog.SetDefault("ecs_agent_url", "") // Will be autodetected
Datadog.SetDefault("collect_ec2_tags", false)
Datadog.SetDefault("collect_security_groups", false)

// Cloud Foundry
Datadog.SetDefault("cloud_foundry", false)
Expand Down
8 changes: 7 additions & 1 deletion pkg/legacy/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ func FromAgentConfig(agentConfig Config) error {
config.Datadog.Set("default_integration_http_timeout", value)
}

// TODO: collect_ec2_tags
if enabled, err := isAffirmative(agentConfig["collect_ec2_tags"]); err == nil {
config.Datadog.Set("collect_ec2_tags", enabled)
}

if enabled, err := isAffirmative(agentConfig["collect_security_groups"]); err == nil {
config.Datadog.Set("collect_security_groups", enabled)
}

// config.Datadog has a default value for this, do nothing if the value is empty
if agentConfig["additional_checksd"] != "" {
Expand Down
1 change: 1 addition & 0 deletions pkg/legacy/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
"forwarder_timeout",
"default_integration_http_timeout",
"collect_ec2_tags",
"collect_security_groups",
"additional_checksd",
"exclude_process_args",
"histogram_aggregates",
Expand Down
6 changes: 3 additions & 3 deletions pkg/legacy/tests/datadog.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ default_integration_http_timeout: 7
create_dd_check_tags: False

# Collect AWS EC2 custom tags as agent tags (requires an IAM role associated with the instance)
collect_ec2_tags: False
collect_ec2_tags: True
# Incorporate security-groups into tags collected from AWS EC2
# collect_security_groups: False
collect_security_groups: True

# Enable Agent Developer Mode
# Agent Developer Mode collects and sends more fine-grained metrics about agent and check performance
Expand Down Expand Up @@ -295,4 +295,4 @@ collect_instance_metadata: False
[trace.ignore]
# a blacklist of regular expressions can be provided to disable certain traces based on their resource name
# all entries must be surrounded by double quotes and separated by comas
# resource="GET|POST /healthcheck","GET /V1"
# resource="GET|POST /healthcheck","GET /V1"
32 changes: 26 additions & 6 deletions pkg/metadata/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ func GetMeta() *Meta {

func getHostTags() *tags {
hostTags := config.Datadog.GetStringSlice("tags")
var gceTags []string

ec2Tags, err := ec2.GetTags()
if err != nil {
log.Debugf("No EC2 host tags %v", err)
if config.Datadog.GetBool("collect_ec2_tags") {
ec2Tags, err := getEC2Tags()
if err != nil {
log.Debugf("No EC2 host tags %v", err)
} else {
hostTags = append(hostTags, ec2Tags...)
}
}
hostTags = append(hostTags, ec2Tags...)

gceTags, err = gce.GetTags()
gceTags, err := gce.GetTags()
if err != nil {
log.Debugf("No GCE host tags %v", err)
}
Expand All @@ -95,6 +97,24 @@ func getHostTags() *tags {
}
}

func getEC2Tags() ([]string, error) {
ec2Tags, err := ec2.GetTags()
if err != nil {
return ec2Tags, err
}

if !config.Datadog.GetBool("collect_security_groups") {
// remove the `security_group_name` tag if present
for i, s := range ec2Tags {
if strings.HasPrefix(s, "security_group_name:") {
ec2Tags = append(ec2Tags[:i], ec2Tags[i+1:]...)
}
}
}

return ec2Tags, nil
}

func getSystemStats() *systemStats {
var stats *systemStats
key := buildKey("systemStats")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
Add support for collect_ec2_tags and collect_security_groups configuration options.

0 comments on commit ca6610b

Please sign in to comment.