Bug #4487
Environment column in hosts table updating incorrectly
| Status: | Closed | Start date: | 08/06/2010 | |
|---|---|---|---|---|
| Priority: | High | Due date: | ||
| Assignee: | - | % Done: | 0% | |
| Category: | stored configuration | |||
| Target version: | 2.6.9 | |||
| Affected Puppet version: | 2.6.0 | Branch: | https://github.com/ody/puppet/tree/tickets/2.6.x/4487 | |
| Keywords: | storeconfigs, mysql, environment, hosts table | |||
Description
Posted on puppet-users at thread/7237b49342ff9890
Below I null out the environment column, show that it’s null for a particular host, then run puppetd a few times on the host.
mysql for root@localhost on indadm1> select * from hosts where name like 'iad-web2%'; +----+---------------------+---------------+-------------+---------------------+-----------------+-------------+---------------------+----------------+---------------------+ | id | name | ip | environment | last_compile | last_freshcheck | last_report | updated_at |source_file_id | created_at | +----+---------------------+---------------+-------------+---------------------+-----------------+-------------+---------------------+----------------+---------------------+ | 9 | iad-web2.indeed.net | 10.24.186.136 | NULL | 2010-08-06 03:31:23 | NULL | NULL | 2010-08-06 03:31:23 | NULL | 2010-06-08 19:47:22 | +----+---------------------+---------------+-------------+---------------------+-----------------+-------------+---------------------+----------------+---------------------+ 1 row in set (0.00 sec) mysql for root@localhost on indadm1> select * from hosts where name like'iad-web2%'; +----+---------------------+---------------+----------------+---------------------+-----------------+-------------+---------------------+----------------+---------------------+ | id | name | ip | environment | last_compile | last_freshcheck | last_report | updated_at | source_file_id | created_at | +----+---------------------+---------------+----------------+---------------------+-----------------+-------------+---------------------+----------------+---------------------+ | 9 | iad-web2.indeed.net | 10.24.186.136 | --- production | 2010-08-06 03:31:23 | NULL | NULL | 2010-08-06 03:32:42 | NULL | 2010-06-08 19:47:22 | +----+---------------------+---------------+----------------+---------------------+-----------------+-------------+---------------------+----------------+---------------------+ 1 row in set (0.00 sec) mysql for root@localhost on indadm1> select * from hosts where name like 'iad-web2%'; +----+---------------------+---------------+----------------------+---------------------+-----------------+-------------+---------------------+----------------+---------------------+ | id | name | ip | environment | last_compile | last_freshcheck | last_report | updated_at | source_file_id | created_at | +----+---------------------+---------------+----------------------+---------------------+-----------------+-------------+---------------------+----------------+---------------------+ | 9 | iad-web2.indeed.net | 10.24.186.136 | --- "--- production" | 2010-08-06 03:32:50 | NULL | NULL | 2010-08-06 03:32:50 | NULL | 2010-06-08 19:47:22 | +----+---------------------+---------------+----------------------+---------------------+-----------------+-------------+---------------------+----------------+---------------------+ 1 row in set (0.00 sec)
Related issues
History
#1
Updated by Markus Roberts almost 3 years ago
- Status changed from Unreviewed to Investigating
I’m assuming that the prior / expected behavior was just to store the name. Will look into it.
#2
Updated by Markus Roberts almost 3 years ago
- Status changed from Investigating to In Topic Branch Pending Review
- Assignee set to Markus Roberts
- Priority changed from Normal to High
- Branch set to MarkusQ:tickets/2.6.x/4487
Jason —
Could you try this out & see if it fixes it?
— Markus
#3
Updated by Jason Koppe almost 3 years ago
Markus, I’d love to test your patch. Is this in your own clone or in the puppet repository?
Also, this looks like the root cause might impact more than just the environment column. My environment argument isn’t working when I have storedconfigs enabled.
#4
Updated by Markus Roberts almost 3 years ago
- Branch changed from MarkusQ:tickets/2.6.x/4487 to http://github.com/MarkusQ/puppet/tree/ticket/2.6.x/4487
Jason —
Sorry, I used our internal shorthand for referring to github branches instead of a more widely understood URL. It’s in my github fork of puppet. I’ve updated the branch field to show this more clearly.
— Markus
P.S. I’m not sure I understood your second paragraph about the problem possibly being more wide-spread.
#5
Updated by Jason Koppe almost 3 years ago
Good too know, maybe the shorthand should be added to http://docs.puppetlabs.com/guides/from_source.html?
Re: second paragraph. I noticed that puppetd —environment jkoppe completely stopped working. As soon as I disabled storedconfigs, puppetd —environment jkoppe started working again.
#6
Updated by Jason Koppe almost 3 years ago
That doesn’t seem to make a difference.
#7
Updated by Markus Roberts almost 3 years ago
- Status changed from In Topic Branch Pending Review to Accepted
- Branch changed from http://github.com/MarkusQ/puppet/tree/ticket/2.6.x/4487 to http://github.com/MarkusQ/puppet/tree/ticket/2.6.x/4487
#8
Updated by Jesse Wolfe almost 3 years ago
- Target version set to 2.6.2
#9
Updated by Markus Roberts almost 3 years ago
- Status changed from Accepted to In Topic Branch Pending Review
In the branch naming flail I wound up with two branches tickets/2.6.x/4487 and ticket/2.6.x/4487 in my github repo. One had my proposed fix and and the other didn’t (it was just 2.6.x). It isn’t clear from the above which branch was tested.
Both branches now should be identical, and both should contain the fix.
#10
Updated by Matt Robinson over 2 years ago
- Assignee changed from Markus Roberts to Matt Robinson
I’m reviewing this. Looks like there’s no tests for a simple patch, so I’ll see if I can write one. Also, this was never sent to the list. I’ll ping Markus about that once I get a test written.
#11
Updated by Matt Robinson over 2 years ago
I’m not sure Markus' patch fixes anything since I can’t find a code path that touches the code that was changed. But I’m also unable to reproduce the problem, so I could be off.
Markus, did you ever hear back from Jason Koppe on if your change helped him? I wanted to add him as a watcher but he’s not in the dropdown. I forgot how to add people there. For now I’ll just email him separately to ask if your patch worked for him.
I’ll keep looking, but when I run storeconfigs and get the hosts to update, it happens via this code path:
“/Users/matthewrobinson/work/puppet/lib/puppet/indirector/facts/active_record.rb:34:in save'",
"/Users/matthewrobinson/work/puppet/lib/puppet/node/facts.rb:15:insave'”,
“/Users/matthewrobinson/work/puppet/lib/puppet/indirector.rb:64:in save'",
"/Users/matthewrobinson/work/puppet/lib/puppet/indirector/catalog/compiler.rb:27:inextract_facts_from_request'”,
I started writing a test, but then thought I’d reproduce the problem since I got to wondering if the stubbed out node object we were describing in tests wasn’t what it actually looked like when we got to the code in question in lib/puppet/rails/host.rb.
Here’s the spec I started for host_spec.rb
+ describe "when storing the host in the database" do
+ before :each do
+ @resource1 = stub_everything 'res1'
+ @resource2 = stub_everything 'res2'
+ @resources = [ @resource1, @resource2 ]
+ Puppet::Rails::Host.stubs(:transaction).yields
+ Puppet::Rails::Host.expects(:find_by_name).with("foo").returns @host
+ end
+ it "should set parameters and then call save" do
+ @host.expects(:merge_facts)
+ @host.expects(:merge_resources)
+# @host.expects(:environment=)
+# @host.expects(:ip=)
+ @host.expects(:last_compile=)
+ @host.expects(:save)
+ Puppet::Rails::Host.store(@node, @resources).should == @host
+ end
+ end
#12
Updated by Jason Koppe over 2 years ago
I had tested MarkusQ/tickets/2.6.x/4487. I just started puppet master on tickets/2.6.x/4487 and tested it again. Here’s what the host environment column looks like now:
mysql for root@localhost on localhost> select * from hosts where name like '%name%'\G
*************************** 1. row ***************************
environment: --- &id006 !ruby/object:Puppet::Node::Environment
cache_timestamp: 2010-09-20 19:31:14.984732 -05:00
known_resource_types: &id001 !ruby/object:Puppet::Resource::TypeCollection
definitions:
luceneslave::profile_cron_indexsync: !ruby/object:P
1 row in set (0.00 sec)
#13
Updated by Jason Koppe over 2 years ago
I just started puppet master on 2.6.1rc4 and I’m no longer seeing the problem I initially reported.
#14
Updated by Matt Robinson over 2 years ago
I looks like a lot of the code in lib/puppet/rails/host.rb became obsolete with Luke’s commit b9c95ebf81eeb78297003de2d0ed4ca048412393, and code that actually called the .store method was removed in 863c50b1273a7fa48d74fb74948938214b45967c when Puppet was version 0.24.8.
I haven’t proven this yet, but I’ll pick this back up tomorrow to see if that’s true and we can remove a bunch of that code.
Markus, were you able to reproduce the initial bug in this ticket? I never could. Also, did you see your change make a difference in code execution, or was your change just based on reading through the code for suspicious lines?
#15
Updated by Markus Roberts over 2 years ago
It was based on code reading; I could not reproduce the problem, so that’s all I had to go on.
It appears from the note above that Jason’s no longer seeing it either as of 2.6.1.
Should we then close this as resolved and open a new one aimed at 2.7.x for dead code removal?
#16
Updated by Matt Robinson over 2 years ago
- Status changed from In Topic Branch Pending Review to Rejected
Nobody has been able to reproduce the issue. I’m assuming Jason may have seen this issue on an intermediate release candidate and that the issue went away in subsequent release candidates as I tried this on 0.25.x, 2.6.0 and 2.6.1.
However, this ticket did point out some dead code. I’m rejecting this ticket since we can’t reproduce the problem and opened ticket #4813 to remove the dead code.
#17
Updated by Jordan Sissel over 2 years ago
I can reproduce this problem.
mysql> select count(*) from hosts where length(environment) > 2000; +----------+ | count(*) | +----------+ | 5 | +----------+ 1 row in set (0.00 sec) mysql> select environment from hosts where length(environment) > 2000 group by environment \G *************************** 1. row *************************** environment: --- "--- \"--- \\\"--- \\\\\\\"--- \\\\\\\\\\\\\\\"--- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"--- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"--- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"--- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"--- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#18
Updated by Jordan Sissel over 2 years ago
Seems to only affect some servers – I’ll see if I can find differences.
mysql> select substring_index(name, ".", 2), length(environment) from hosts order by length(environment) ; ... | solr45-1.staging1 | 10 | | membase1.staging1 | 10 | | ip-10-196-39-192.ec2 | 10 | | ip-10-196-39-192.staging1 | 10 | | solr00-4.prod | 14 | | solr00-2.prod | 96 | | solr00-3.prod | 556 | | solr45-2.prod | 65535 | | solr45-1.prod | 65535 | | solr00-1.prod | 65535 | | solr13-1.prod | 65535 | | solr13-2.prod | 65535 | +-------------------------------+---------------------+ 37 rows in set (0.00 sec)
#19
Updated by Dan Trainor over 2 years ago
Hi –
For what its worth, I was seeing this exact same problem. I ended up updating to ruby-mysql 2.8.2 which seems to have fixed this. I’m testing this out a little more, wanting the puppet client to restart a few dozen more times before calling this resolved (in my case anyway), but that may help you out in your situation. It certainly fixed my instance of the problem.
I’m using CentOS 5.5 with a bunch of rebuilt gems and things like that (we rebuild everything, and re-tag/sign them), so most of them are all fairly new. I suspect that you followed the setup instructions listed in Redmine, as I did, that called for specific versions, which may not apply any more in the 2.6 branch, which I’m using (2.6.2, to be exact).
Hope that helps.
#20
Updated by Nigel Kersten over 2 years ago
Thanks for the update Dan, and thanks even more for letting us know about your workaround.
#21
Updated by Dan Trainor over 2 years ago
Hi –
My pleasure. I’m not a great developer, so I’m hoping that someone can eventually confirm from a programmatic standpoint that this is indeed the proper solution to the given problem.
#22
Updated by Jordan Sissel over 2 years ago
mysql> select substring_index(name;, ".", 2), length(environment), substring(environment,1,20) from hosts where environment like "%---%" order by length(environment); +-------------------------------+---------------------+-----------------------------+ | substring_index(name, ".", 2) | length(environment) | substring(environment,1,20) | +-------------------------------+---------------------+-----------------------------+ | solr45-2.prod | 65535 | --- "--- \"--- \\\"- | | solr13-1.prod | 65535 | --- "--- \"--- \\\"- | | solr13-2.prod | 65535 | --- "--- \"--- \\\"- | | solr45-1.prod | 65535 | --- "--- \"--- \\\"- | | solr00-1.prod | 65535 | --- "--- \"--- \\\"- | +-------------------------------+---------------------+-----------------------------+
Seems like there’s some bad yaml encapsulation going on. I don’t think this is a mysql rubygem bug.
#23
Updated by Jordan Sissel over 2 years ago
- Status changed from Rejected to Re-opened
- Target version deleted (
2.6.2)
Marking this re-opened.
#24
Updated by Geoff Robertson over 2 years ago
Hi,
Experiencing a similar issue where 0.24.8 set the storeconfigs puppet db (MySQL) environment column value to “production”, 2.6.2 sets the value to “—– production”.
“/var/lib/gems/1.8/bin/puppetmasterd —configprint environment” returns “production”
Cheers Geoff
#25
Updated by Dan Trainor over 2 years ago
Hi –
I’ll be honest, I’ve been kind of lazy in regards to updating classes of configuration directives in puppet.conf; puppetd opposed to the new “agent”, puppetmasterd instead of the new “master”, etc etc.
I tested and confirmed that this only happens when using the new class name of “master” instead of my previously used “puppetmasterd” configuration class. This is the only time that I can absolutely reproduce this.
If someone else can attempt the same test to further confirm, I suspect this will help a great deal. Simply change [master] to [puppetmasterd]. It will still work, albeit deprecated so you’ll want to keep an eye on it for future releases, but still.
Thanks -dant
#26
Updated by Jordan Sissel over 2 years ago
I should note now that I am using puppet in a masterless deployment.
#27
Updated by Jordan Sissel over 2 years ago
This isn’t specific to mysql. I found this while debugging puppet with minstrel:
% RUBYLIB=lib RUBY_INSTRUMENT=ActiveRecord::ConnectionAdapters::SQLite3Adapter FACTER_funfact="new fact" bin/minstrel puppet apply --storeconfigs --dblocation ./storeconfigs.sqlite -e 'notice($funfact)' ... enter ActiveRecord::ConnectionAdapters::SQLite3Adapter#update_without_query_dirty(["UPDATE \"hosts\" SET \"environment\" = '--- \"--- \\\"--- \\\\\\\"--- \\\\\\\\\\\\\\\"--- production\\\\\\\\\\\\\\\"\\\\\\\"\\\"\"', \"last_compile\" = '2010-11-15 15:55:48.458498', \"updated_at\" = '2010-11-15 15:55:48.623126' WHERE (\"hosts\".\"id\" = 1)"])
As above, this is with sqlite3, not mysql.
#28
Updated by Marek Wodzinski over 2 years ago
I can confirm that. In my case it occurs on both backends: mysql and sqlite. In case of using sqlite, it looks like there is no limit for length of this field, so puppet agent which tries to use stored variables eats all memory after some time. I’m using puppet from debian lenny-backports (puppet 2.6.2-1~bpo50+1)
mysql> select name, length(environment) from hosts;
+----------------------+---------------------+
| name | length(environment) |
+----------------------+---------------------+
| debian-1.example.com | 65535 |
| debian-3.example.com | 65535 |
| debian-4.example.com | 65535 |
| debian-2.example.com | 65535 |
+----------------------+---------------------+
4 rows in set (0.00 sec)
#29
Updated by Cody Herriges over 2 years ago
This looks like an incompatibility of Puppet 2.6.x and older rails/activerecord/mysql gem versions. Reproducible with Centos 5.5 and Debian Lenny running rails 2.2.1 and 2.2.0. Installed Ruby EE 1.8.7 on Centos 5.5, installed rails through gems instead of through yum and the errors subside completely.
#30
Updated by Jordan Sissel over 2 years ago
Cody,
My systems use newer versions than 2.2.x:
- activerecord (3.0.3)
- ruby-mysql (2.9.3)
Also observed this problem with the non-pure-ruby mysql gem ‘mysql’ latest version.
#31
Updated by Cody Herriges over 2 years ago
- File 0001-Fixes-4487.patch
added
I have found the issue and a fix but don’t 100% understand why the current code is not functional. The patch I have attached fixes the issue.
node.parameter[“environment”] will return a string. node.environment is an object that contains yaml. If you do a .to_s on the object you will get the environment name prepended with —– and someplace in the active_record terminus and rails code for puppet it gets put in the database as is. Just using the parameter which is always a properly formatted string works. I am interested more in where the database call happens and tracking down why the previous code doesn’t work.
I would change the branch in Redmine if I could get the branch to push…I will change it when I figure out why it won’t push.
#32
Updated by Cody Herriges over 2 years ago
- Branch changed from http://github.com/MarkusQ/puppet/tree/ticket/2.6.x/4487 to https://github.com/ody/puppet/tree/tickets/2.6.x/4487
#33
Updated by Cody Herriges over 2 years ago
- Keywords changed from storedconfig, mysql, environment, hosts table to storeconfigs, mysql, environment, hosts table
#34
Updated by Cody Herriges over 2 years ago
- Status changed from Re-opened to Accepted
#35
Updated by Nick Lewis over 2 years ago
- Status changed from Accepted to Merged - Pending Release
Merged to 2.6.next in commit:167e84d39d5cdd6b628d4d681b918406e7c896e6.
#36
Updated by James Turnbull over 2 years ago
- Target version set to 2.6.5
#37
Updated by Nick Lewis over 2 years ago
- Status changed from Merged - Pending Release to Closed
#38
Updated by Mark Washeim over 2 years ago
Cody Herriges wrote:
I have found the issue and a fix but don’t 100% understand why the current code is not functional. The patch I have attached fixes the issue.
node.parameter[“environment”] will return a string. node.environment is an object that contains yaml. If you do a .to_s on the object you will get the environment name prepended with —– and someplace in the active_record terminus and rails code for puppet it gets put in the database as is. Just using the parameter which is always a properly formatted string works. I am interested more in where the database call happens and tracking down why the previous code doesn’t work.
I would change the branch in Redmine if I could get the branch to push…I will change it when I figure out why it won’t push.
Just noting that I’ve applied this patch to a 2.6.2 (gentoo) and it works.
#39
Updated by Richard Crowley over 2 years ago
- Status changed from Closed to Re-opened
I can easily reproduce this bug on the 2.6.x branch. Here’s all it takes:
- Fire up the master.
- Run the agent.
touch puppet.conf- Run the agent again.
On the second agent run, the environment is read from the storeconfigs database, converted to a Puppet::Node::Environment object, and later written to the database, at which point ActiveRecord converts it to YAML.
On the third agent run, the same thing happens, escaping the YAML from the second run, and so on.
The part I can’t explain is why reparsing puppet.conf triggers the issue. I’d love anyone with more knowledge of exactly what gets invalidated on reparse to explain that.
This branch/commit in my GitHub fork fixes and tests the problem: https://github.com/rcrowley/puppet/tree/ticket/2.6.x/4487 https://github.com/rcrowley/puppet/commit/caae93c6b84595cffce7d347184b5a66fe61a001
#40
Updated by James Turnbull over 2 years ago
- Status changed from Re-opened to Accepted
- Assignee changed from Matt Robinson to Nigel Kersten
- Target version changed from 2.6.5 to 2.6.x
Nigel – thoughts?
#41
Updated by Nigel Kersten about 2 years ago
Just poked at this for a while. I thought it might be due to us specially handling environment when parsing the config file, but that doesn’t appear to be the case.
Getting review eyes onto the code now.
#42
Updated by Richard Crowley about 2 years ago
- Status changed from Accepted to In Topic Branch Pending Review
- Assignee changed from Nigel Kersten to Markus Roberts
I can reproduce this at-will on 2.6.x but not on 2.6.next.
https://github.com/puppetlabs/puppet/compare/2.6.x...2.6.next
Nothing in there looks to be remotely related to this bug, stored configs, or environments.
#43
Updated by Nigel Kersten about 2 years ago
I can reproduce at-will on 2.6.x and 2.6.next
ii libmysql-ruby1.8 2.8.2-1 ii rails-ruby1.8 2.3.5-1.2
#44
Updated by Matt Robinson about 2 years ago
- Assignee changed from Markus Roberts to Matt Robinson
#45
Updated by Matt Robinson about 2 years ago
- Assignee deleted (
Matt Robinson)
I just haven’t had the time to look at this, so I’m unassigning it from myself. This will have to get prioritized with all the other stuff going on right now.
#46
Updated by Josh Cooper about 2 years ago
- Status changed from In Topic Branch Pending Review to Merged - Pending Release
We committed a modified version of Richard’s patch in 2.6.next, see commit:ddc4e148689233058827f32832195daa935a99e2
#47
Updated by James Turnbull almost 2 years ago
- Status changed from Merged - Pending Release to Closed
- Target version changed from 2.6.x to 2.6.9
#48
Updated by James Turnbull over 1 year ago
- Category set to stored configuration