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

Support space-separated DD_TAGS #289

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion lib/datadog/statsd/serialization/tag_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def escape_tag_content(tag)
def dd_tags(env = ENV)
return {} unless dd_tags = env['DD_TAGS']

to_tags_hash(dd_tags.split(','))
to_tags_hash(dd_tags.split(' '))

Choose a reason for hiding this comment

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

To address concerns about backwards-compatibility, this could be changed to allow spaces or commas as the separator:

Suggested change
to_tags_hash(dd_tags.split(' '))
to_tags_hash(dd_tags.split(/[, ]/))

Copy link
Author

Choose a reason for hiding this comment

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

great idea: 120c0d4

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem here is that if someone has spaces in their tag names then they will be split with this change. This could cause alerts to fire if they are monitoring a particular metric with a tag that has space in it.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I thought about that too. What about parsing it as CSV, including quote delimiters? It might slow things down - I'm not sure how often this gets called.

Copy link
Author

Choose a reason for hiding this comment

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

And it would still require people to add quotes since they weren't there before.

Copy link
Author

Choose a reason for hiding this comment

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

In the DD docs it seems like spaces are not supported in tag names.

Copy link
Contributor

Choose a reason for hiding this comment

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

Spaces count as other special characters so will be converted to underscores once they are sent back to DD.

From the docs:

Other special characters are converted to underscores.

Copy link
Author

Choose a reason for hiding this comment

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

@carlosroman what if it's conditional - if DD_TAGS has a , in it, split on that. Otherwise split on spaces?

Copy link
Author

Choose a reason for hiding this comment

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

end

def default_tags(env = ENV)
Expand Down
2 changes: 1 addition & 1 deletion spec/statsd/serialization/tag_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
context 'when testing DD_TAGS' do
around do |example|
ClimateControl.modify(
'DD_TAGS' => 'ghi,team:qa'
'DD_TAGS' => 'ghi team:qa'
) do
example.run
end
Expand Down
2 changes: 1 addition & 1 deletion spec/statsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
'DD_ENV' => 'staging',
'DD_SERVICE' => 'billing-service',
'DD_VERSION' => '0.1.0-alpha',
'DD_TAGS' => 'ghi,team:qa'
'DD_TAGS' => 'ghi team:qa'
) do
example.run
end
Expand Down