-
Notifications
You must be signed in to change notification settings - Fork 14
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
Standardize DD_TAGS format #162
Merged
Merged
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3466a11
parse DD_TAGS using DD_TAGS_SEP as delimiter, defaults to comma
NouemanKHAL d611a15
update compile & supply scripts
NouemanKHAL a8ba46b
add ruby script to update the datadog.yaml config tags and dogstatsd_…
NouemanKHAL 352173d
update get_tags.py script to export tags comma-separated
NouemanKHAL 49744c5
unset DD_TAGS when starting agents + update DD_TAGS export logic
NouemanKHAL 5666364
fix typo in DD_NODE_AGENT_TAGS name + cleanup
NouemanKHAL 90949a0
update README
NouemanKHAL 43b3dd5
update bin/compile to match bin/supply
NouemanKHAL a306ed3
Apply suggestions from code review
NouemanKHAL 2dff705
small cleanup: remove LEGACY_TAGS_FORMAT
NouemanKHAL 20e11b4
apply suggestion
NouemanKHAL 859be6b
Update README.md
NouemanKHAL 037f502
Add `buildpack_version` tag to logs, traces and metrics (#164)
NouemanKHAL e1b3995
Revert "Add `buildpack_version` tag to logs, traces and metrics (#164)"
NouemanKHAL cd4656b
Merge branch 'master' into noueman/standardize-dd-tags-format
NouemanKHAL fafbd81
remove extra line
NouemanKHAL 60cd53a
cleanup merge
NouemanKHAL 3d3bbdb
keep the tags separator logic backward-compatible
NouemanKHAL 4870178
fix parse_tags method
NouemanKHAL bcc889b
writing ruby array via .to_yaml + trimming file contents on read
NouemanKHAL b83e5bb
remove the .to_yaml
NouemanKHAL 682dece
.trim -> .strip
NouemanKHAL df319a0
some fixes and improvements in the ruby scripts
NouemanKHAL 72e9fa5
fix race condition when updating datadog config and logs config tags
NouemanKHAL 8927419
fix unbound variables in prepare.sh
NouemanKHAL 6a54dca
update README
NouemanKHAL 13f0036
Update README.md
NouemanKHAL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,19 @@ | |
|
||
require 'json' | ||
|
||
# if DD_TAGS[0] is comma or space, then set is as delimiter | ||
# else continue as usual | ||
NODE_AGENT_TAGS_FILE = "/home/vcap/app/.datadog/node_agent_tags.txt" | ||
|
||
def parse_tags(tags) | ||
delimiter = ',' | ||
delimiter = ' ' if tags.count(' ') > tags.count(',') | ||
begin | ||
delimiter = ',' | ||
delimiter = ' ' if tags.count(' ') > tags.count(',') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sarah-witt keeping this line will keep this change backwards-compatible |
||
if !ENV["DD_TAGS_SEP"].nil? | ||
delimiter = ENV["DD_TAGS_SEP"] | ||
end | ||
return tags.split(delimiter) | ||
rescue Exception => e | ||
puts "there was an issue parsing the tags in #{tags.__name__}: #{e}" | ||
puts "there was an issue parsing the tags in '#{tags}': #{e.message}" | ||
return [] | ||
end | ||
end | ||
|
||
|
@@ -38,7 +41,17 @@ def parse_tags(tags) | |
# we do this to separate commas inside json values from tags separator commas | ||
node_agent_tags = node_agent_tags.gsub(",\"", ";\"") | ||
all_node_agent_tags = parse_tags(node_agent_tags) | ||
tags += all_node_agent_tags.reject { |tag| tag.include?(';') } | ||
if !all_node_agent_tags.empty? | ||
tags += all_node_agent_tags.keep_if { |tag| !tag.include?(';') } | ||
end | ||
end | ||
|
||
node_agent_tags_file = File.file?(NODE_AGENT_TAGS_FILE) ? File.read(NODE_AGENT_TAGS_FILE).strip : nil | ||
if node_agent_tags_file | ||
node_agent_tags = parse_tags(node_agent_tags_file) | ||
if !node_agent_tags.empty? | ||
tags += node_agent_tags | ||
end | ||
end | ||
|
||
vcap_variables.each do |vcap_var_name| | ||
|
@@ -63,7 +76,7 @@ def parse_tags(tags) | |
user_tags = parse_tags(user_tags) | ||
tags += user_tags | ||
rescue Exception => e | ||
puts "there was an issue parsing the tags in TAGS: #{e}" | ||
puts "there was an issue parsing the tags in TAGS: #{e.message}" | ||
end | ||
end | ||
|
||
|
@@ -73,21 +86,17 @@ def parse_tags(tags) | |
user_tags = parse_tags(user_tags) | ||
tags += user_tags | ||
rescue Exception => e | ||
puts "there was an issue parsing the tags in DD_TAGS: #{e}" | ||
puts "there was an issue parsing the tags in DD_TAGS: #{e.message}" | ||
end | ||
end | ||
|
||
version_file = '/home/vcap/app/.datadog/VERSION' | ||
if File.exist?(version_file) | ||
buildpack_version = File.open(version_file, 'r') { |file| file.read.chomp } | ||
tags << "buildpack_version:#{buildpack_version}" | ||
buildpack_version = File.open(version_file, 'r') { |file| file.read.strip } | ||
tags << "buildpack_version:#{buildpack_version.strip}" | ||
end | ||
|
||
tags = tags.map { |tag| tag.gsub(' ', '_') }.uniq | ||
tags = tags.map { |tag| tag.gsub(' ', '_') } | ||
tags = tags.uniq | ||
|
||
legacy_tags = ENV['LEGACY_TAGS_FORMAT'] || false | ||
if legacy_tags | ||
puts tags.join(',') | ||
else | ||
puts tags.join(' ') | ||
end | ||
puts tags.join(',') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. | ||
# This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
# Copyright 2022-Present Datadog, Inc. | ||
|
||
#!/usr/bin/env ruby | ||
|
||
require 'yaml' | ||
|
||
NODE_AGENT_TAGS_FILE = "/home/vcap/app/.datadog/node_agent_tags.txt" | ||
DD_TAGS_FILE = "/home/vcap/app/.datadog/.dd_tags.txt" | ||
|
||
def sanitize(tags_env_var, delimiter) | ||
tags_list = tags_env_var.gsub(",\"", ";\"").split(delimiter) | ||
tags_list.keep_if { |element| !element.include?(";") } | ||
tags_list = tags_list.map { |tag| tag.gsub(" ", "_") } | ||
return tags_list.uniq | ||
end | ||
|
||
def read_yaml_file(file_path) | ||
yaml_file = File.read(file_path) | ||
return YAML.load(yaml_file) | ||
end | ||
|
||
def write_yaml_file(file_path, data) | ||
File.write(file_path, YAML.dump(data)) | ||
end | ||
|
||
def get_tags() | ||
dd_tags = ENV['DD_TAGS'] || File.file?(DD_TAGS_FILE) ? File.read(DD_TAGS_FILE).strip : nil | ||
dd_node_agent_tags = File.file?(NODE_AGENT_TAGS_FILE) ? File.read(NODE_AGENT_TAGS_FILE).strip : nil | ||
|
||
tags = [] | ||
|
||
if !dd_tags.nil? | ||
tags += sanitize(dd_tags, ",") | ||
NouemanKHAL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
if !dd_node_agent_tags.nil? | ||
tags += sanitize(dd_node_agent_tags, ",") | ||
end | ||
|
||
return tags.uniq | ||
end | ||
|
||
def main | ||
tags = get_tags() | ||
|
||
if !tags.empty? | ||
file_path = '/home/vcap/app/.datadog/dist/datadog.yaml' | ||
|
||
puts "updating datadog.yaml with the tags: '#{tags}'" | ||
|
||
data = read_yaml_file(file_path) | ||
|
||
data['tags'] = tags | ||
data['dogstatsd_tags'] = tags | ||
|
||
write_yaml_file(file_path, data) | ||
end | ||
end | ||
|
||
main |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also include a note about where the custom tags are included?