saltstack / saltstack/salt

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

Open
#60,182 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending-discussion
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the jobs.list_jobs runner entry point and trace how search_target and search_function filters are applied. Determine where minion IDs are available for matching and how job results are formatted. Done means search_minion_target filters jobs independently of the original target and reports the matching minion IDs in the output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, devops
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.