salt icon indicating copy to clipboard operation
salt copied to clipboard

Using mine.get while targeting grain returns data from dead minions

Open numkem opened this issue 11 years ago • 45 comments

Hello,

I'm currently running 2014.7.2 and after removing some minions that were VMs using Foreman with the foreman-salt plugging (hence deleting their keys), the data I get from mine while targeting using grain is always from the minions that are now gone.

I've tried using salt-run cache.clear_all tgt='*', salt '*' saltutil.clear_cache and salt '*' mine.flush and nothing seems to change the outcome.

What I'm trying to run is salt-call mine.get 'kernel:Linux' backend_ip_addr grain in a template so it looks like {% for host, ips in salt['mine.get']('kernel:Linux', 'backend_ip_addr', 'grain').items() %}.

If I do salt-call mine.get '*' backend_ip_addr I get data without the dead minions. Weirdly enough If do something like salt-call mine.get 'os:Ubuntu' backend_ip_addr grain. I only get data from the same host as the minion I'm running this on even if there is many more minions that are running Ubuntu.

I've tried to target minions using pillar and I get either nothing or things that doesn't make sense...

Thank you.

numkem avatar Mar 25 '15 14:03 numkem

What I ended up having to do was to go in /var/cache/salt/master and delete all the minions that are dead by removing the whole directory. Than running salt '*' saltutil.clear_cache. This seemed to finally worked and the data I receive is the correct one.

numkem avatar Mar 25 '15 14:03 numkem

Hi @numkem - Thanks for reporting this bug! It looks to me like there are two things happening here that need to be addressed to fix this bug:

  • The foreman-salt plugin should probably remove that mine data
  • mine.flush and the other cache function should probably be clearing that out as well.

rallytime avatar Mar 27 '15 16:03 rallytime

Hmm, I'm having a little trouble reproducing this. In my testing, using salt-run cache.clear_all tgt='*' performs its intended function and the "dead" minions no longer appear in a mine query.

You've said here that after manually removing the master's cache directory that things work as expected. Could you please try again to use the cache runner to clear the cache and then before deleting this directory by hand, see if the "dead" minion data has been removed? If not, there may be some sort of strange bug in the cache cleaner.

cachedout avatar Apr 07 '15 17:04 cachedout

I tried using salt-run cache.clear_all tgt='*' and while it did feel like some things changed as some of the bad data went away, some stayed and I ended up having to resort to deleting the content of /var/cache/salt/master anyway.

Also salt '*' saltutil.clear_cache doesn't change anything either.

numkem avatar Apr 21 '15 16:04 numkem

@numkem Yes, those two commands operate on completely different caches. The runner command is the one we want here. Can you please try this again and after running salt-run cache.clear_all tgt='*' post the contents of /var/cache/salt/minions/<dead_minion_in_question>?

cachedout avatar May 05 '15 15:05 cachedout

@cachedout I don't see any difference after using salt-run cache.clear_all tgt='*'.

The problem is really when doing a mine.get while targeting with either grains or pillar.

I don't have a folder like you mentionned but I did find /var/cache/salt/master/minions containing 2 files for the dead minion.

How can I send this to you as it looks like its containing "private" things?

numkem avatar May 08 '15 18:05 numkem

@cachedout Anything I can do to help to get this issue fixed?

numkem avatar May 29 '15 14:05 numkem

Not sure if "+1"s are useful, but I think I'm experiencing the same problem; even after running salt-run cache.clear_all tgt='*' I still have lots of (some dead, some not) minions listed in /var/cache/salt/master/minions/

Let me know if I can provide some useful other info.

kevinbowman-ta avatar Jun 17 '15 09:06 kevinbowman-ta

+1

joshughes avatar Jul 21 '15 02:07 joshughes

I can confirm that after upgrading to 2015.5.2 from 2014.7.5 that whenever I destroy an minion its data stays in the salt mine cache... this was not the case with the previous version

joshughes avatar Jul 21 '15 02:07 joshughes

This workaround works for me, 2015.5.2:

clean_mine_cache:
  cmd.run:
    - name: |
        salt-run cache.clear_mine tgt='*' && \
        salt '*' mine.update

I added this to orchestrate state and it is executed each time before other steps.

komljen avatar Jul 21 '15 08:07 komljen

Actually, it seems it doesn't work if any of minions are down. Tested on two environments:

Env 1, all minions up:

$ find /var/cache/salt/master/minions -name mine.p | wc -l
42
$ sudo salt-run cache.clear_mine tgt='*'
$ find /var/cache/salt/master/minions -name mine.p | wc -l
0

Env 2, 10 minions down:

$ find /var/cache/salt/master/minions -name mine.p | wc -l
16
$ sudo salt-run cache.clear_mine tgt='*'
$ find /var/cache/salt/master/minions -name mine.p | wc -l
16

Same version of salt on both nodes:

$ salt-call --versions-report
                  Salt: 2015.5.2
                Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
                Jinja2: 2.7.2
              M2Crypto: 0.21.1
        msgpack-python: 0.3.0
          msgpack-pure: Not Installed
              pycrypto: 2.6.1
               libnacl: Not Installed
                PyYAML: 3.10
                 ioflo: Not Installed
                 PyZMQ: 14.0.1
                  RAET: Not Installed
                   ZMQ: 4.0.4
                  Mako: 0.9.1
 Debian source package: 2015.5.2+ds-1trusty1

However, this works, simple and effective:

clean_mine_cache:
  cmd.run:
    - name: |
        rm /var/cache/salt/master/minions/*/mine.p && \
        salt '*' mine.update

komljen avatar Jul 21 '15 14:07 komljen

Also it now seems like two servers come up in any compound match...

root@inf-use1a-pr-01-salt-salt-0001:~# salt-call mine.get 'G@roles:elasticsearch and G@elasticsearch:cluster_name:inf-kibana-cluster' network.ip_addrs compound
local:
    ----------
    dev-use1b-pr-01-utopia-madb-0001:
        - 10.10.50.250
    dev-use1e-pr-01-utopia-madb-0001:
        - 10.10.60.60
    inf-use1a-pr-01-kibana-kibana-0001:
        - 10.40.100.5
    inf-use1b-pr-01-kibana-esdb-0001:
        - 10.40.50.84
    inf-use1b-pr-01-kibana-kibana-0001:
        - 10.40.110.245
    inf-use1e-pr-01-kibana-esdb-0001:
        - 10.40.60.108

joshughes avatar Jul 22 '15 15:07 joshughes

@joshughes I'm running into the exact same issue.

What I end up doing is to delete everything under /var/cache/salt/master/minions/ and restart the salt-master and all the salt-minion service on all minions.

numkem avatar Jul 22 '15 15:07 numkem

It is also worth noting that I do have some minions that are still running 2014.7.5... I hessitent to upgrade them because I am at the point where I think i will be rolling back...

Also I opened this issue... https://github.com/saltstack/salt/issues/25613

It seems to me that salt-mine should return results correctly even if there is somehow stale data.

joshughes avatar Jul 22 '15 16:07 joshughes

@numkem

I am seeing my compound queries return all of my minions now... Which might be better for helping track this bug down but basically makes salt mine useless for me...

salt-call mine.get 'G@roles:mariadb and G@mariadb:cluster_name:adfasd_utopia' network.ip_addrs compound

That should only return 6 servers but instead is returning all of my servers now... Wondering if you see similar behavior if your try a compound query

joshughes avatar Jul 22 '15 16:07 joshughes

@joshughes I really do, it's not only when targeting with grains its with any kind of compound query. If I try using I@roles with pillar I get the same erratic result until I restart the minion.

numkem avatar Jul 22 '15 18:07 numkem

@numkem so I restarted my minions and my salt-mine is completely hosed at this point. With any compound query I get all my minions and any other query returns nothing... I downgraded to salt v2014.7.5 and it doing the same thing... so I am at a loss for what could be causing the issue... unless it is the v2015.5.2 minion that are reporting data the make the whole thing break down.

joshughes avatar Jul 22 '15 19:07 joshughes

@joshughes I remember having the issue with 2014.7.5 as well. It just seems like the data reported to mine can only be added or modified but not removed. I has to be by design since it would make sens in some way but one thing for sure the behavior that you are seeing is as bad as it gets.

I can't recall exactly what I did to make it work again but I know that deleting minions cached data and restarting master/minions ended up correcting the problem. I also put a lot of pillar data inside mine so refreshing pillar was necessary as well.

numkem avatar Jul 22 '15 19:07 numkem

Ya I am not seeing the issue that dead minions are reporting... but that the salt mine is just not working at all for me anymore, now that I deleted the minion cache and restarted everything.

joshughes avatar Jul 22 '15 20:07 joshughes