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

Add support for collect_ec2_tags and collect_security_groups options #1194

Merged
merged 4 commits into from
Feb 8, 2018
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
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:") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arbll if you look at the A5 logic: https://github.com/DataDog/dd-agent/blob/5.21.2/utils/cloud_metadata.py#L212-L214 it looks like the security_group_name tag is not part of the tags that are returned by the AWS API, but that we extract the tag from the instance metadata and append it to the list of tags. So we should probably do the same thing in A6 so that users who do have the collect_security_groups option enabled have the tag with A6.

What do you think?

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.