librato / statsd-cookbook

Chef cookbook to install Statsd
Apache License 2.0
26 stars 36 forks source link

Allows for extra configuration with the 'graphite' key. #29

Closed maraca closed 10 years ago

maraca commented 10 years ago

A Chef node considers hash keys as strings, by having symbols and strings the hash can not merge properly and as a result, adding another graphite key to the extra_config results in a hash with two graphite keys. The result is that there is no way at the moment to add any more values to the graphite key (see https://github.com/etsy/statsd/blob/master/docs/namespacing.md for more examples)

To go around this problem the first thing to do is to remove symbols from the config_hash hash and turn them into strings. The second thing is to then do a "deep merge" since a regular merge will only go down one level in the hash. To accomplish this we take advantage of the Chef Mixins.

config_hash should really be a node attribute to prevent this type of behavior and let Chef handle the deep merges but for the sake of backward compatibility it was left as is. However this should be considered when bumping the cookbook to a major release.

This allows the user to do things like this:

node.default['statsd']['extra_config'] = {
  'graphite' => {
    'globalPrefix' => 'something'
  },
}

And the output of the config.js will be

  "graphite": {
    "legacyNamespace": false,
    "globalPrefix": "something"
  },
mheffner commented 10 years ago

@maraca Looks good, thanks!

maraca commented 10 years ago

@mheffner thanks for merging quickly. Do you mind cutting a new release for this? 0.3.3

mheffner commented 10 years ago

@maraca Sure, done!