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

work around 'Exception::ImmutableAttributeModification' #14

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

anatolijd
Copy link

Running this recipe under chef-11.8.0 I get this:

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:
---------------
  /var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:23:in `block in from_file'
  /var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:22:in `each'
  /var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:22:in `from_file'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:

 16:  end
 17:  
 18:  user node['jmxtrans']['user']
 19:  
 20:  # merge stock jvm queries w/ container specific ones into single array
 21:  servers = node['jmxtrans']['servers']
 22:  servers.each do |server|
 23>>   server['queries'] = node['jmxtrans']['default_queries']['jvm']
 24:    case server['type']
 25:    when 'tomcat'
 26:      server['queries'] << node['jmxtrans']['default_queries']['tomcat']
 27:    end
 28:    server['queries'].flatten!
 29:  end
 30:  
 31:  ark "jmxtrans" do
 32:    url node['jmxtrans']['url']

Since it is the only place where we refer to node['jmxtrans']['servers'] attribute in recipe - .dup can be used to work it around (I hope).

Running this recipe under Chef-11.8 I get this:

```
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:
---------------
  /var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:23:in `block in from_file'
  /var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:22:in `each'
  /var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:22:in `from_file'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:

 16:  end
 17:  
 18:  user node['jmxtrans']['user']
 19:  
 20:  # merge stock jvm queries w/ container specific ones into single array
 21:  servers = node['jmxtrans']['servers']
 22:  servers.each do |server|
 23>>   server['queries'] = node['jmxtrans']['default_queries']['jvm']
 24:    case server['type']
 25:    when 'tomcat'
 26:      server['queries'] << node['jmxtrans']['default_queries']['tomcat']
 27:    end
 28:    server['queries'].flatten!
 29:  end
 30:  
 31:  ark "jmxtrans" do
 32:    url node['jmxtrans']['url']
```
node['jmxtrans']['servers'] may already have custom queries defined in attribute. Append default jvm queries to preserve custom ones.
@anatolijd
Copy link
Author

forgot to mention -a fix from PR #13 did not work for me, I get another exception:

================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/jmxtrans_rf/recipes/default.rb
================================================================================


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:
---------------
  /var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:28:in `block in from_file'
  /var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:22:in `each'
  /var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:22:in `from_file'
  /var/chef/cache/cookbooks/jmxtrans_rf/recipes/default.rb:11:in `from_file'


Relevant File Content:
----------------------
/var/chef/cache/cookbooks/jmxtrans/recipes/default.rb:

 21:  servers = node.default['jmxtrans']['servers']
 22:  servers.each do |server|
 23:    server['queries'] = node['jmxtrans']['default_queries']['jvm']
 24:    case server['type']
 25:    when 'tomcat'
 26:      server['queries'] << node['jmxtrans']['default_queries']['tomcat']
 27:    end
 28>>   server['queries'].flatten!
 29:  end
 30:  
 31:  ark "jmxtrans" do
 32:    url node['jmxtrans']['url']
 33:    checksum node['jmxtrans']['checksum']
 34:    version "latest"
 35:    prefix_root '/opt'
 36:    prefix_home '/opt'
 37:    owner node['jmxtrans']['user']

I know about collectd jmx plugin, the problem is that it produces 'unfriendly' graphite names for JMX metrics, and even with chain mangling I can't separate GenericJMX-- with '.' (I can, but it gets replaced back by write_graphite plugin ).

anatolijd and others added 4 commits March 19, 2014 18:29
jmxtrans.sh and /etc/init.d/jmxtrans depend on 'source' bashism
next line '<<' operator fails if container does not have any custom query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant