Skip to content

Commit

Permalink
[datadog_monitor] Fix crash for jmx integrations with init_config att…
Browse files Browse the repository at this point in the history
…ributes set (#869)

Fixes a crash when the init_config attribute for a jmx integration (such asignite, jboss_wildfly) is set.

Previously, the init_config attribute would be merged in-place (through the merge! method) with another hash: { 'is_jmx': true, 'collect_default_metrics': true }. This would cause a crash if init_config is defined in attributes, because chef attributes cannot be modified that way:

================================================================================
Error executing action `add` on resource 'datadog_monitor[jboss_wildfly]'
================================================================================

Chef::Exceptions::ImmutableAttributeModification
------------------------------------------------
Node attributes are read-only when you do not specify which precedence level to set. To set an attribute use code like `node.default["key"] = "value"'

Cookbook Trace: (most recent call first)
----------------------------------------
/tmp/kitchen/cache/cookbooks/datadog/resources/monitor.rb:67:in `block (2 levels) in class_from_file'
/tmp/kitchen/cache/cookbooks/datadog/resources/monitor.rb:43:in `block in class_from_file'

This PR fixes this by not merging the attributes in-place. It also adds a kitchen test which exhibits the previous faulty behavior.
  • Loading branch information
KSerrania authored Feb 17, 2023
1 parent d224c08 commit 07a3c59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,16 @@ suites:
instances:
- host: localhost
port: 49112

- name: datadog_jboss_wildfly
run_list:
- recipe[datadog::jboss_wildfly]
attributes:
datadog:
<<: *DATADOG
jboss_wildfly:
init_config:
custom_jar_paths: ["/opt/wildfly/bin/client/jboss-client.jar"]
instances:
- jmx_url: localhost:9990
tools_jar_path: /opt/wildfly/bin/client/jboss-client.jar
2 changes: 1 addition & 1 deletion resources/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
init_config = new_resource.init_config
if new_resource.is_jmx
init_config ||= {}
init_config.merge!({ 'is_jmx': true, 'collect_default_metrics': true })
init_config = init_config.merge({ 'is_jmx': true, 'collect_default_metrics': true })
end

variables(
Expand Down

0 comments on commit 07a3c59

Please sign in to comment.