salt icon indicating copy to clipboard operation
salt copied to clipboard

Custom events not deterministic under multi-master topology

Open larkinrobert opened this issue 11 years ago • 30 comments

http://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.event.html :

There are several examples provided , none of the examples actually result in an event with a custom tag. The event -

salt-call event.send myco/mytag foo=Foo bar=Bar 
  • returns True on the minion , and watching the event on the master I see this:
Event fired at Thu Jan 22 11:57:32 2015
*************************
Tag: 20150122115732463832
Data:
{'_stamp': '2015-01-22T11:57:32.466469',
 'arg': ['myco/mytag', 'foo=Foo', 'bar=Bar'],
 'cmd': '_return',
 'fun': 'event.send',
 'fun_args': ['myco/mytag', 'foo=Foo', 'bar=Bar'],
 'id': 'server',
 'jid': '20150122115732463832',
 'retcode': 0,
 'return': True,
 'success': True,
 'tgt': 'server',
 'tgt_type': 'glob'}
Event fired at Thu Jan 22 11:57:32 2015
*************************
Tag: salt/job/20150122115732463832/ret/server
Data:
{'_stamp': '2015-01-22T11:57:32.466622',
 'arg': ['myco/mytag', 'foo=Foo', 'bar=Bar'],
 'cmd': '_return',
 'fun': 'event.send',
 'fun_args': ['myco/mytag', 'foo=Foo', 'bar=Bar'],
 'id': 'server',
 'jid': '20150122115732463832',
 'retcode': 0,
 'return': True,
 'success': True,
 'tgt': 'server',
 'tgt_type': 'glob'}

###############################

None of the provided examples result in a custom tag, nor any syntax I've imagined and tried.

root@lhops:~# salt-master --versions
           Salt: 2014.7.0
         Python: 2.7.3 (default, Mar 13 2014, 11:03:55)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: Not Installed
       pycrypto: 2.6
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 13.1.0
           RAET: Not Installed
            ZMQ: 3.2.3
           Mako: Not Installed

root@server:~# salt-minion --versions
           Salt: 2014.7.0
         Python: 2.7.3 (default, Mar 13 2014, 11:03:55)
         Jinja2: 2.6
       M2Crypto: 0.21.1
 msgpack-python: 0.1.10
   msgpack-pure: Not Installed
       pycrypto: 2.6
        libnacl: Not Installed
         PyYAML: 3.10
          ioflo: Not Installed
          PyZMQ: 13.1.0
           RAET: Not Installed
            ZMQ: 3.2.3
           Mako: 0.7.0

larkinrobert avatar Jan 22 '15 18:01 larkinrobert

Hrm, I can't reproduce this. Does anything change if you restart your master and minion?

[root@li737-184] [~/salt] [2014.7?]
± salt-call event.send myco/mytag foo=Foo bar=Bar
local:
    True
Event fired at Fri Jan 23 18:12:28 2015
*************************
Tag: myco/mytag
Data:
{'_stamp': '2015-01-23T18:12:28.977863',
 'cmd': '_minion_event',
 'data': {'__pub_fun': 'event.send',
          '__pub_jid': '20150123181228741094',
          '__pub_pid': 4170,
          '__pub_tgt': 'salt-call',
          'bar': 'Bar',
          'foo': 'Foo'},
 'id': 'basepi-debian',
 'pretag': None,
 'tag': 'myco/mytag'}

basepi avatar Jan 23 '15 18:01 basepi

We've spent some days on this, restarting services and scrapping and rebuilding everything with the same results, so I'm going to guess the difference must be a library or some other distribution factor.

We're using Debian Wheezy and the .deb packages from debian.saltstack.com/debian. We're using python-2.7.3. We had to backport these packages from jessie ourselves: python-gevent_1.0.1-1_amd64.deb python-gevent-websocket_0.9.3-1_all.deb python-socketio_0.3.6-2_all.deb python-libcloud_0.14.1-1_all.deb python-botocore_0.62.0-1_all.deb

And we had to pull these packages from the wheezy-backports repo: python-zmq-13.1.0-1~bpo70+1 python-requests-2.0.0-1~bpo70+2

Maybe there is a problem with one or more of these packages. Do you have any intuition if we might have a problem with one of these packages ( and which one )?

larkinrobert avatar Jan 23 '15 18:01 larkinrobert

I mean, I suppose it could be ZMQ, as that's what we use for the event bus. But I can't imagine what would have changed. =\

basepi avatar Jan 27 '15 23:01 basepi

I can repro this all day long

root@virl:~# salt-minion --versions
Salt Version:
           Salt: 2015.2.0-844-g2d0e665

Dependency Versions:
         Jinja2: 2.7.3
       M2Crypto: 0.22
           Mako: 0.9.1
         PyYAML: 3.10
          PyZMQ: 14.0.1
         Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
           RAET: Not Installed
            ZMQ: 4.0.4
          ioflo: Not Installed
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
       pycrypto: 2.6.1

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 3.16.0-33-generic
         system: Ubuntu 14.04 trusty

master: (note --versions was bombing for me until i installed lib sodium )

Salt Version:
           Salt: 2015.2.0-846-g45827bc

Dependency Versions:
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
           Mako: 0.9.1
         PyYAML: 3.10
          PyZMQ: 14.0.1
         Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
           RAET: Not Installed
            ZMQ: 4.0.4
          ioflo: 1.2.1
        libnacl: 1.4.2
   msgpack-pure: 0.1.3
 msgpack-python: 0.4.6
       pycrypto: 2.6.1

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 3.13.0-46-generic
         system: Ubuntu 14.04 trusty

Snergster avatar Mar 27 '15 00:03 Snergster

Well. I guess I can stop holding out hope that 2015.2 is a silver bullet. I can probably stop examining deps too. Snergster, are you using LXC as well?

larkinrobert avatar Mar 27 '15 18:03 larkinrobert

Thats a bit vague.. Do i have container software installed? yes i do. Are either master or minion in this scenario running IN any type of container? No. To whomever wants to try and debug this further I'm more then happy to throw up a webex or the like so you could watch it detonate first hand. Doesn't look like this problem is going anywhere.

Snergster avatar Mar 27 '15 18:03 Snergster

Ah, ok. My minions are running in an lxc container and I was wondering if there was a connection, but it looks like the answer doesn't lie there. Basepi wasn't able to reproduce this...it's a bit mysterious what you and I have in common that is missing from his environment.

larkinrobert avatar Mar 27 '15 19:03 larkinrobert

I don't know about you larkinrobert but on my setup I found one way to easily reproduce this. minion with multiple masters in a list. Video shows just a single master in a list but I just showed a single to highlight the bug https://youtu.be/h22Bx1LuC40 @basepi what more do you need to get this bug off the Cannot reproduce list?

Snergster avatar Apr 04 '15 06:04 Snergster

The addition of "multi-master" is enough. I didn't test with multiple masters.

basepi avatar Apr 06 '15 16:04 basepi

Minion-initiated actions currently have undefined behavior on multi-master. There's been discussion on adding a flag to salt-call to specify which master(s) to send the event/job/whatever back up to.

whiteinge avatar Apr 06 '15 16:04 whiteinge

whiteinge ?? I see no reason why even if i give a directed --master=foo to salt call that it shouldn't work regardless. Thats not specific to this bug...if i point the finger and say go there it should ignore any other settings that may steer it elsewhere random_master multi_master etc.
I would actually understand this being a lower severity issue if that did work properly because I could still make events flow. Albeit in a non ha way. And not for beacons ill bet. I haven't tested but something tells me that if i just put a single dns entry pointed at multiple A's that this would work just fine. But thats broken and with random_master now its something i want to get away from regardless.

Snergster avatar Apr 06 '15 17:04 Snergster

@Snergster not sure I follow. Are you saying using the salt-call --master=foo does not override the list of masters in your minion config?

Sorry my previous comment was rushed and too terse. I'll rephrase. Multi-master was implemented from a master-centric viewpoint; when you run a command from master A the results from minions are returned back to master A. We did not design what should happen if a command is initiated from minion Y -- should the job/event go to both master A and master B, should it go to just one?

This minion-centric omission from multi-master is behavior we need to get sorted, added, and documented in Salt-core. If you watch the event bus on both masters when you fire a custom event, I expect you'll see it show up on one but not the other -- but which one it shows up on is currently undefined behavior. I don't think we have an issue for that discussion yet. @cachedout may know.

Hopefully that is the same issue @larkinrobert is seeing.

whiteinge avatar Apr 06 '15 19:04 whiteinge

@whiteinge (overly trying to be clear...these comments assume a running salt-minion because without that salt-call event.send custom/whatever doesn't work at all period for me ) so env running salt-minion 2014.7 or 2015.2.rc2 talking to master with those same versions with the master: being a list even a list of one (but lets assume multiple for now) salt-call --master=foo event.send custom/tag custom/tag is lost...well you if you look at event stream you see it in the return so its not lost lost.. but its not properly received on master the point i was trying to make was that salt-call --master=foo should be defeating multiple config options by default including at least master: (single, multiple whatever) and random_master. So even if bugs like this did exist --master would avoid them. I GUESS i could pass -C to salt-call and just have a totally sep config tree to get around this bug...but thats pretty gross imho.

ok now on to your new points We did not design what should happen if a command is initiated from minion Y -- should the job/event go to both master A and master B, should it go to just one? That would depend on if i set random_master of course..but lets assume false it should go to A (like any other call) and failover (assuming failover is set) to b if no response.

This minion-centric omission from multi-master is behavior we need to get sorted, added, and documented in Salt-core. If you watch the event bus on both masters when you fire a custom event, I expect you'll see it show up on one but not the other -- but which one it shows up on is currently undefined behavior. I don't think we have an issue for that discussion yet. No, No, NO....I fire custom event I DO see the RETURN come from one or the other (sorry in this test random was set True) but the actual TAG never shows on either.

So again just trying to be clear...for me on ubuntu (because i still haven't tried other os's) having the masters in a list (list of one or multiple) means I NEVER see the custom tag come in on the master, any master in the list...ever.

Snergster avatar Apr 06 '15 19:04 Snergster

@Snergster easy there. I'm sorry this isn't working and we'll get it figured out and fixed. A few related-sounding bug reports have cropped up in the last couple weeks so it's got our attention.

I understand the job comes through on one of the masters but the event does not. My point is that behavior is currently not defined -- you can't expect it to come through on one vs. the other, nor can you expect it to come through on the same master consistently (especially over time and through TCP disconnections/reconnections). This is the problem that needs to be fixed. I'm a little surprised you're not seeing the event on either master, but not overly surprised -- we've seen dropped events before when which master to send data to is ambiguous.

Multi-master does not have a concept of "failover". Each connection to each master is a hot connection. The random_master setting only determines which master the minion connects to first. (The help-text under that option is very misleading, IMO.)

Lastly, it also sounds like you're running into a separate problem which is the --master CLI option is not taking precedence over the values in the config file. Your -c option suggestion is a fine (but you're right: gross) workaround until that can be fixed.

whiteinge avatar Apr 06 '15 20:04 whiteinge

@Snergster we'll fast-track this design decision and follow-up here shortly with a more concrete plan and timeline. (The docs and -c fixes are low-hanging fruit.)

whiteinge avatar Apr 06 '15 20:04 whiteinge

There is at least one issue here that I've found. If salt-call is used without a minion runnning, the original behaviour reported by @larkinrobert can be easily reproduced. Luckily, there is a very simple workaround.

What's happening here is that event.send pushes the event onto the minion event bus, with the expectation that it will be picked up by a running minion. However, in the case of salt-call without a minion running, it is salt-call itself which has initialized the event bus and after the event is published, it tears that bus down and exits, leaving nobody around to handle the abandoned request to forward the publication to the master.

This can be mitigated quite simply by using the preload option to pass in some arbitrary data. This will force the event module to authenticate and send the data synchronously to the master, thus working around the above problem. To modify the original example:

salt-call event.send myco/mytag foo=Foo bar=Bar preload="{'no_minion': True}"

Figuring out how to programatically detect this situation is looking a little tricky at the moment, but this may provide some temporary relief.

Regarding the second set of questions surrounding multi-master, I don't yet have answers for that but I'll do some testing and report back.

cachedout avatar Apr 06 '15 22:04 cachedout

@whiteinge Dont mistake my words as anger...well..I am pissed at myself for not being more clear..not upset at you folks..not at all..

  • you can't expect it to come through on one vs. the other, nor can you expect it to come through on the same master consistently* I don't and I don't so no problem there. *Multi-master does not have a concept of "failover". *
    ok well this got me thinking because i always considered master_type: failover to be multiple master with failover...when technically its not.. so that made me throw another test which also has me shaking my head.
  • I was wrong, its just just masters in a list, it is just multi-master because if you have masters in list with master_type failover the events come through fine.
  • BUT the events come through on the first connected master, if i then force a failover no other master sees a tag any longer.

Also if your interested in doc cleanup I'm happy to file a few issues because how i got multimaster stuck in my head is via http://docs.saltstack.com/en/latest/topics/tutorials/multimaster_pki.html which certainly doesn't make it clear that when you enable failover you are in this weird quasi multimaster state where certain multi master features still apply. First one that can explain the diff between master_shuffle and random_master gets a beer while your at it :) The random_master setting only determines which master the minion connects to first. Well even wording like that is going to lead to confusion.
If i have a minion foo connected to masters A , B, C start salt-minion it connects to A every new salt-call hits the randomizer
This is made even more bizarre if you have failover enabled because then even if your minion has 'logged the failed master and failed over' random_master doesn't take that into account so Y% of your calls will fail as it happily tries to reach the 'known' dead master.

Snergster avatar Apr 06 '15 22:04 Snergster

@cachedout wins the beer for 'less gross then -C workaround' salt-call event.send myco/mytag foo=Foo bar=Bar preload="{'no_minion': True}" while i haven't tested all version combinations does work like a charm 2015.2 minion to 2014.7.2 master

and thanks for that...the thought of having to maintain a sep config tree had me searching for a cat to kick.

Snergster avatar Apr 06 '15 23:04 Snergster

The specific problem that prompted me to open the issue is not that the event isn't sent to the master ( it is ), but that the Tag field is just a time stamp, and the intended tag string shows up in the Data field as the value of 'arg'.

I did check today and in fact I am creating an /etc/salt/minion that defines the master in list form. We experimented with multi-master some time ago, and stopped, but left the format as a list with a single master. We'll check if changing that format fixes how the event shows up on the master.

larkinrobert avatar Apr 06 '15 23:04 larkinrobert

@Snergster thanks for the reply. You've done some good sleuthing here. Looks like I missed the introduction of that doc you linked and you're right, that definitely muddies the waters.

I filed the above issue to start collecting thoughts on some of these questions. You've raised several more good questions that also need answers. :confused:

whiteinge avatar Apr 07 '15 00:04 whiteinge