-
Notifications
You must be signed in to change notification settings - Fork 260
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
Allow for a hash or string when configuring tags #296
Allow for a hash or string when configuring tags #296
Conversation
This might help with wrapper cookbooks using a composition pattern
Interesting. I thought the template variable was timed differently. This might solve the problem a little more elegantly. |
@miketheman Not entirely. A more flexible solution could be for adding a resource for configuring the agent that allows a wrapping cookbook to format the template however they choose. |
@miketheman I've added support for a hash similarly to #186 with test coverage so it shouldn't be a breaking change. |
I have updated the example in the initial post so this is ready for review and merge. 👍 |
Well this has come full circle now so this more or less duplicates the work in #186 though mine can be merged and passes CI. |
@@ -31,6 +31,9 @@ | |||
default['datadog']['url'] = 'https://app.datadoghq.com' | |||
|
|||
# Add tags as override attributes in your role | |||
# This can be a string of comma separated tags or a hash in this format: | |||
# default['datadog']['tags'] = { 'datacenter' => 'us-east' } | |||
# Thie above outputs a string: 'datacenter:us-east' |
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.
nit: typo
Thanks for your persistence! Can you add a spec test to cover the existing tags as a string behavior? |
@miketheman done! Also added a bonus spec to cover an empty tag not being output. |
@@ -15,7 +15,11 @@ autorestart: <%= node['datadog']['autorestart'] %> | |||
skip_ssl_validation: <%= node['datadog']['web_proxy']['skip_ssl_validation'] %> | |||
<% end -%> | |||
|
|||
<% if node['datadog']['tags'].respond_to?(:each_pair) -%> | |||
tags: <%= node['datadog']['tags'].reject{|k,v| v.empty? }.map{|k,v| "#{k}:#{v}" }.join(',') %> |
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.
Style nitpicks: spacing and unused block arg representation.
Should be node['datadog']['tags'].reject { |_k, v| v.empty? }.map { |k, v| "#{k}:#{v}" }.join(',')
@miketheman Done :) |
Thanks! Putting in merge queue. |
@martinisoft Thanks for working through this! Now merged to master. |
A pattern we're employing with our wrapper cookbooks is to compose the datadog tags attribute so they're rendered out properly in the datadog template. The way it currently is now, the template is rendered at compile time which prevents wrapper cookbooks from modifying the tags during run time. By extracting the attribute to a template variable, we delay the rendering of the template variable until the run phase.
With this patch you will be able to do the following in a recipe:
What this does is composes the current set of tags defined in the attribute with an additional tag by way of merging in a new key and value into the hash. You can still provide a string instead which is the currently shipped default so these changes are fully backward compatible.