salt icon indicating copy to clipboard operation
salt copied to clipboard

Offline minions are still reported as being present by the event system

Open wwentland opened this issue 10 years ago • 20 comments

Description of Issue/Question

Minions that have been stopped and are reported as offline are still being reported as being present by the presence event system.

Steps to Reproduce Issue

Accept a minion and turn on presence events by setting presence_events: True in the master config. Wait for minion to be reported as being present in the salt/presence/present. Once the minion has been listed as being present it is stopped and salt-run manage.down is being executed.

The expectation would have been that the minion is no longer included in the list of present minions, but reported as lost in the salt/presence/change event. We do, however, see the following events:

salt/presence/present   {
    "_stamp": "2016-05-24T09:19:17.751376", 
    "present": [
        "salttest-debian-jessie.test"
    ]
}
salt/run/20160524111929009590/new   {
    "_stamp": "2016-05-24T09:19:29.232977", 
    "fun": "runner.manage.down", 
    "jid": "20160524111929009590", 
    "user": "sudo_vagrant"
}
20160524111929250961    {
    "_stamp": "2016-05-24T09:19:29.251123", 
    "minions": [
        "salttest-debian-jessie.test"
    ]
}
salt/job/20160524111929250961/new   {
    "_stamp": "2016-05-24T09:19:29.251205", 
    "arg": [], 
    "fun": "test.ping", 
    "jid": "20160524111929250961", 
    "minions": [
        "salttest-debian-jessie.test"
    ], 
    "tgt": "*", 
    "tgt_type": "glob", 
    "user": "sudo_vagrant"
}
20160524111934259366    {
    "_stamp": "2016-05-24T09:19:34.259689", 
    "minions": [
        "salttest-debian-jessie.test"
    ]
}
salt/job/20160524111934259366/new   {
    "_stamp": "2016-05-24T09:19:34.260658", 
    "arg": [
        "20160524111929250961"
    ], 
    "fun": "saltutil.find_job", 
    "jid": "20160524111934259366", 
    "minions": [
        "salttest-debian-jessie.test"
    ], 
    "tgt": "*", 
    "tgt_type": "glob", 
    "user": "sudo_vagrant"
}
salt/run/20160524111929009590/ret   {
    "_stamp": "2016-05-24T09:19:44.326068", 
    "fun": "runner.manage.down", 
    "jid": "20160524111929009590", 
    "return": [
        "salttest-debian-jessie.test"
    ], 
    "success": true, 
    "user": "sudo_vagrant"
}
salt/presence/present   {
    "_stamp": "2016-05-24T09:20:18.015483", 
    "present": [
        "salttest-debian-jessie.test"
    ]
}

where the minion is obviously being reported as being down, but still included in the present list of the salt/presence/present event. Conversely no salt/presence/change event has been fired.

Versions Report

salt --versions-report

Salt Version: Salt: 2015.8.10

Dependency Versions: Jinja2: 2.7.3 M2Crypto: Not Installed Mako: Not Installed PyYAML: 3.11 PyZMQ: 14.4.0 Python: 2.7.9 (default, Mar 1 2015, 12:57:24) RAET: Not Installed Tornado: 4.2.1 ZMQ: 4.0.5 cffi: 0.8.6 cherrypy: Not Installed dateutil: 2.2 gitdb: 0.5.4 gitpython: 0.3.2 RC1 ioflo: Not Installed libgit2: Not Installed libnacl: Not Installed msgpack-pure: Not Installed msgpack-python: 0.4.2 mysql-python: 1.2.3 pycparser: 2.10 pycrypto: 2.6.1 pygit2: Not Installed python-gnupg: Not Installed smmap: 0.8.2 timelib: Not Installed

System Versions: dist: debian 8.4 machine: x86_64 release: 3.16.0-4-amd64 system: debian 8.4

wwentland avatar May 24 '16 09:05 wwentland

I can confirm that on 2015.8.8.2 on Arch and 2015.8.10 on Debian 8 I see that not all minions that are up are listed in the salt/presence/present present events, and they remain listed even after the minion is stopped.

viq avatar May 24 '16 09:05 viq

Thanks for the report. Does the change event ever fire? I'm wondering if it's lagged or completely broken. Also do the manage.present or manage.not_present commands report the same incorrect result?

whiteinge avatar May 24 '16 16:05 whiteinge

I have not seen a single salt/presence/change at all, so it might very well be completely broken. But even in that case an offline minion shouldn't be listed in:

...
salt/presence/present   {
    "_stamp": "2016-05-24T09:20:18.015483", 
    "present": [
        "salttest-debian-jessie.test"
    ]
}
...

My impression is that the presence status of a minion is never updated anymore.

wwentland avatar May 24 '16 20:05 wwentland

I am seeing this issue as early as 2015.8.1. Was this ever working for you @babilen ?

I also tried the 2015.5* branch but I kept returning an empty list which i believe is related to #26643

I also tested that this is present on 2016.3 as well.

Ch3LL avatar May 25 '16 03:05 Ch3LL

It was definitely working before, but I can't tell you exactly when. It might have been in 2014.* though. Obviously not many people use this feature, but we just ran into something where it would help.

wwentland avatar May 25 '16 04:05 wwentland

I'm observing this as well with a 2016.11.1 master.

If I manually stop the minion service, the master seems to notice reliably (I see the event fired via salt-run state.event pretty=True). But if I disable the network connection on the minion, the event is never fired, and the master never seems to notice.

Salt Version: Salt: 2016.11.1

Dependency Versions: cffi: Not Installed cherrypy: Not Installed dateutil: 1.5 gitdb: 0.5.4 gitpython: 0.3.2 RC1 ioflo: Not Installed Jinja2: 2.7.2 libgit2: Not Installed libnacl: Not Installed M2Crypto: 0.21.1 Mako: 0.9.1 msgpack-pure: Not Installed msgpack-python: 0.3.0 mysql-python: 1.2.3 pycparser: Not Installed pycrypto: 2.6.1 pygit2: Not Installed Python: 2.7.6 (default, Jun 22 2015, 17:58:13) python-gnupg: Not Installed PyYAML: 3.10 PyZMQ: 14.0.1 RAET: Not Installed smmap: 0.8.2 timelib: Not Installed Tornado: 4.2.1 ZMQ: 4.0.4

System Versions: dist: Ubuntu 14.04 trusty machine: x86_64 release: 3.16.0-60-generic system: Linux version: Ubuntu 14.04 trusty

a-wildman avatar Feb 10 '17 00:02 a-wildman

Possible that https://github.com/saltstack/salt/commit/40c89474aae12bd68080fd51dd1cb70d6a4aad5e fixes this issue?

a-wildman avatar Feb 10 '17 22:02 a-wildman

As mentioned above, this is probably fixed by #36126. Marking as such until we can verify.

whiteinge avatar Mar 20 '17 19:03 whiteinge

Thanks for the fix @a-wildman. It worked for us running 2016.3.4

mbom2004 avatar Mar 31 '17 14:03 mbom2004

Thank you!

wwentland avatar Apr 02 '17 13:04 wwentland

Note: The pull request (#36126) mentions it only contains a fix for the zmq case.

Does this ticket require additional fixes? If so, this should probably be reopened.

(I'm seeing the same problems with 2016.11.3 with transport=tcp. #39524)

harmv avatar Apr 11 '17 08:04 harmv

You're right. The TCP transport will need it's own fix.

whiteinge avatar Apr 11 '17 22:04 whiteinge

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Oct 03 '18 23:10 stale[bot]

@Ch3LL ping. Stalebot closed it, even though it says:

Bug, Confirmed, Core, High Severity, P4

Shouldn't stalebot at least take a look at the labels before closing?

dstensnes avatar Jan 04 '19 19:01 dstensnes

Thank you for updating this issue. It is no longer marked as stale.

stale[bot] avatar Jan 04 '19 21:01 stale[bot]

@Ch3LL I have exactly the same issue. Very often event salt/presence/change (for unknown reasons present list in salt/presence/present not contains missing minion) is not generated and after 2nd run list it's cleared https://github.com/saltstack/salt/blob/e04efc315567ef126bdaedc103c40e948b52586c/salt/master.py#L352 so we can't handle minion removal.

I also found that by default connections from lost minions are maintain (because of the tcp_keepalive) so we have minions in the present list.

salt-mast 23737 root   25u  IPv4 230482      0t0  TCP 10.10.11.235:4505->10.10.1.204:30848 (ESTABLISHED)

Even if I disable tcp_keepalive not always salt/presence/change is fired.

What I also noticed that fallowing runners properly list connected and disconnected minions:

  • https://github.com/saltstack/salt/blob/705e8cca0b9ad6441c3884e76798cac1ff7859d7/salt/runners/manage.py#L220
  • https://github.com/saltstack/salt/blob/705e8cca0b9ad6441c3884e76798cac1ff7859d7/salt/runners/manage.py#L254

All implementations base on the same main function: https://github.com/saltstack/salt/blob/e04efc315567ef126bdaedc103c40e948b52586c/salt/utils/minions.py#L622 but list_not_state calculate missing minions based on the accepted keys vs connected minions.

So I think that we could improve here if handle_presence would calculate missing minions similarly https://github.com/saltstack/salt/blob/e04efc315567ef126bdaedc103c40e948b52586c/salt/master.py#L344

dawidmalina avatar Sep 10 '19 16:09 dawidmalina

This is very basic implementation which covers my use case:

    def handle_presence(self, old_present):
        '''
        Fire presence events if enabled
        '''
        # On the first run it may need more time for the EventPublisher
        # to come up and be ready. Set the timeout to account for this.
        if self.presence_events and self.event.connect_pull(timeout=3):
            present = self.ckminions.connected_ids()
            new = present.difference(old_present)
            lost = old_present.difference(present)

            key = salt.key.get_key(self.opts)
            keys = key.list_keys()

            # initially present set is empty
            if len(present) == 0:
              for minion in keys[key.ACC]:
                if minion not in present:
                  lost.add(minion)

            if new or lost:
                # Fire new minions present event
                data = {'new': list(new),
                        'lost': list(lost)}
                self.event.fire_event(data, tagify('change', 'presence'))
            data = {'present': list(present)}
            self.event.fire_event(data, tagify('present', 'presence'))
            old_present.clear()
            old_present.update(present)

dawidmalina avatar Sep 11 '19 09:09 dawidmalina

@Ch3LL, @garethgreenaway what do you think about my proposotion? I can create pull request if needed.

dawidmalina avatar Sep 11 '19 16:09 dawidmalina

@dawidmalina and you are still seeing this on zmq transport and with the settings in this fix: https://github.com/saltstack/salt/commit/40c89474aae12bd68080fd51dd1cb70d6a4aad5e i thought this was fixed but only needed to be fixed for the tcp transport as well

Ch3LL avatar Sep 18 '19 14:09 Ch3LL

closing as this is old - if an issue still exists for the TCP transport please open a new issue and confirm what supported version of salt

sagetherage avatar Apr 20 '21 22:04 sagetherage