saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.2k stars 5.48k forks source link

[FEATURE REQUEST] Add a way to filter by minion_id in jobs.list_jobs #60182

Open Lesvek opened 3 years ago

Lesvek commented 3 years ago

Is your feature request related to a problem? Please describe. When we want to investigate a problem on a minion, one of the first thing to do is to check if something changed that could cause the problem. To do that, we could use he jobs.list_jobs function. The problem is that, when we use a grain or a pillar as a filter, there is no way to filter using the minion id:

admin@dev-master:~$ salt -G os:ubuntu grains.get os
dev-master:
    Ubuntu
dev-consul:
    Ubuntu
admin@dev-master:~$ sudo salt-run jobs.list_jobs search_target='dev-master' search_function='grains.get'

To get the information we want, we need to know the exact target that was used to call the function:

admin@dev-master:~$ salt -G os:ubuntu grains.get os
dev-master:
    Ubuntu
dev-consul:
    Ubuntu
admin@dev-master:~$ sudo salt-run jobs.list_jobs search_function='grains.get' search_target='os:ubuntu'
20210513171425970846:
    ----------
    Arguments:
        - os
    Function:
        grains.get
    StartTime:
        2021, May 13 17:14:25.970846
    Target:
        os:ubuntu
    Target-type:
        grain
    User:
        admin

On our infrastructure, we have a lot of use-cases that require using different targets to deploy or changes (progressive deployment, apply changes only on minion providing certain services, etc).

Describe the solution you'd like

Add a way to list jobs using the minion_id:

admin@dev-master:~$ sudo salt-run jobs.list_jobs search_function='grains.get' search_minion_target='dev-master'
20210513171425970846:
    ----------
    Arguments:
        - os
    Function:
        grains.get
    Minion-target:
        - dev-consul
        - dev-master
    StartTime:
        2021, May 13 17:14:25.970846
    Target:
        os:ubuntu
    Target-type:
        grain
    User:
        admin

Describe alternatives you've considered

We could index the minion output to an elasticsearch cluster and use that to search the changes instead. One of the difficulty would be to parse the output and adapt it so it can be easily indexed.

There is already an elasticsearch returner but it looks a bit dated and the json output module would need to be adapted.

Additional context

Please Note

Lesvek commented 3 years ago

I'm under the impression that there is a bug that prevents the minion list from being updated when using the default returner.

Could this be the case?