Skip to content

fix: Fully mutual exclusive data and expr filters - #1446

Closed
bygui86 wants to merge 5 commits into
argoproj:masterfrom
bygui86:feature/mutual-exclusive-filter
Closed

bygui86 wants to merge 5 commits into
argoproj:masterfrom
bygui86:feature/mutual-exclusive-filter

Conversation

@bygui86

@bygui86 bygui86 commented Dec 1, 2021

Copy link
Copy Markdown
Contributor

@whynowy here we go with the PR for the issue #1442

Checklist:

…ngly

Signed-off-by: Matteo Baiguini <mbaiguini@swissblock.net>
…ngly - Added some missing testing use cases

Signed-off-by: Matteo Baiguini <mbaiguini@swissblock.net>
Signed-off-by: Matteo Baiguini <mbaiguini@swissblock.net>
@bygui86
bygui86 force-pushed the feature/mutual-exclusive-filter branch from cf55cd2 to 965acff Compare December 1, 2021 15:52
@bygui86 bygui86 changed the title Fully mutual exclusive data and expr filters bug: Fully mutual exclusive data and expr filters Dec 1, 2021
@bygui86 bygui86 changed the title bug: Fully mutual exclusive data and expr filters fix: Fully mutual exclusive data and expr filters Dec 1, 2021
Signed-off-by: Matteo Baiguini <mbaiguini@swissblock.net>
@bygui86
bygui86 force-pushed the feature/mutual-exclusive-filter branch from 07ffef1 to 9ebf485 Compare December 1, 2021 16:45
Comment thread USERS.md Resolved
Signed-off-by: Matteo Baiguini <mbaiguini@swissblock.net>
@whynowy

whynowy commented Dec 2, 2021

Copy link
Copy Markdown
Member

Before I started reviewing the PR, I read through the related issue one more time, I think I have pointed the wrong direction at the beginning, and I apologize. Basically the list of filters are in AND condition, so it's expected that it fails when encountering any error or false.

@whynowy

whynowy commented Dec 2, 2021

Copy link
Copy Markdown
Member

And I think for your case, you can try with Multiple Paths to solve the issue.

@bygui86

bygui86 commented Dec 2, 2021

Copy link
Copy Markdown
Contributor Author

@whynowy I think I was pretty clear and detailed in my description, right to avoid any waste of time... maybe I was wrong...

now that I have a better understanding of how it's intended to work, I would like to point out couple of things:

  1. the Filter documentation:
    • is really incomplete
    • examples are too simple (it would be good to have a real example based for example on GitHub and GitLab events)
    • should have a dedicated section and not be placed only under "tutorials", as imo it's a really important feature of Argo Events
  2. I suggest to add an option to change the evaluation process of the list of filters and conditions under each filter, offering possibility to specify if evaluated in AND or in OR, because:
    • there is no option to have multiple conditions under a filter evaluated in OR. I'm forced to create multiple sensors, increasing complexity (more yaml manifests) and costs of maintainability and resources in the cluster (more sensors = more resource consumption)
    • Multiple paths could fast become really complex and it's completely not flexible as Expr (see examples of differences below)
    • declaring or-conditions in Multiple paths is complex and limited, because based on regex

The Filter doc is really incomplete because:

  • Nowhere is documented that "the list of filters is evaluated in AND condition"
  • Nowhere is documented that "the list of conditions under a filter is evaluated in AND condition"
  • There are 4 types of filter, not 3. Expr filter is completely missing and it's one of the most important and flexible
  • Data filter Multiple path example is not really clear and probably wrong
  • There is no clear example for Context filter (like for Data filter)
  • There is no clear example for Time filter (like for Data filter)
  • There is no real examples or use case, for example filtering an event coming from GitHub or GitLab webhook

"Data filter Multiple paths" is not comparable to "Expr filter", for example:

  • declaring multiple conditions within a regex becomes fast really complex and error prone
  • declaring something like b != "" is not so easy together with other conditions
  • it's not possible to declare conditions in || (OR)
  • it's not possible to declare a condition like b > 2.5 as number or b == true as bool
  • no "Parenthesis to control order of evaluation" available (based on https://github.com/Knetic/govaluate)
  • no "Arrays" available (based on https://github.com/Knetic/govaluate)
    For these reasons (and others I didn't list), I don't consider "Data filter Multiple paths" a valid alternative to "Expr filter". And for sure also not a valid, easy, fast alternative to have conditions under a filter evaluated in OR.

@whynowy if you have time, can we have a call so I can better describe everything to you?

@alexec maybe we can discuss about this in the call we scheduled, what do you think?

@bygui86

bygui86 commented Dec 2, 2021

Copy link
Copy Markdown
Contributor Author

@whynowy here I try to shortly describe my use case.

I configured a GitLab webhook and Argo Events on a GKE cluster.

I want to filter GitLab events based on our simple requirements:

  • trigger a workflow (Argo Workflow) on each commit on the main/master branch
  • trigger a workflow (Argo Workflow) on each new tag
  • trigger a workflow (Argo Workflow) on specific actions on PR/MR:
    • new PR/MR opened
    • update on source branch of the PR/MR
    • draft/wip PR/MR mark as "ready"

For those requirements I'm forced to declare 4 sensors:

  • a sensor for "main/master branch" and "tags"
  • a sensor for "new PR/MR opened"
  • a sensor for "update on source branch of the PR/MR"
  • a sensor for " draft/wip PR/MR mark as ready"

Here the partial yaml manifests.

sensor for "main/master branch" and "tags"

# ...

  dependencies:
    - name: gitlab-dependency
      eventSourceName: gitlab
      eventName: gitlab-event
      filters:
        data:
          - path: body.event_name
            type: string
            value:
              - "push"
              - "tag_push"

# ...

sensor for "new PR/MR opened"

# ...

  dependencies:
    - name: gitlab-dependency
      eventSourceName: gitlab
      eventName: gitlab-event
      filters:
        exprs:
          - expr: event_type == "merge_request" && work_in_progress == false && state == "opened" && action == "open"
            fields:
              - name: event_type
                path: body.event_type
              - name: work_in_progress
                path: body.object_attributes.work_in_progress
              - name: state
                path: body.object_attributes.state
              - name: action
                path: body.object_attributes.action

# ...

sensor for "update on source branch of the PR/MR"

# ...

  dependencies:
    - name: gitlab-dependency
      eventSourceName: gitlab
      eventName: gitlab-event
      filters:
        exprs:
          - expr: event_type == "merge_request" && work_in_progress == false && state == "opened" && action == "update" && oldrev != ""
            fields:
              - name: event_type
                path: body.event_type
              - name: work_in_progress
                path: body.object_attributes.work_in_progress
              - name: state
                path: body.object_attributes.state
              - name: action
                path: body.object_attributes.action
              - name: oldrev
                path: body.object_attributes.oldrev

# ...

sensor for " draft/wip PR/MR mark as ready"

# ...

  dependencies:
    - name: gitlab-dependency
      eventSourceName: gitlab
      eventName: gitlab-event
      filters:
        exprs:
          - expr: event_type == "merge_request" && work_in_progress == false && state == "opened" && action == "update" && title_previous =~ "Draft:"
            fields:
              - name: event_type
                path: body.event_type
              - name: work_in_progress
                path: body.object_attributes.work_in_progress
              - name: state
                path: body.object_attributes.state
              - name: action
                path: body.object_attributes.action
              - name: title_previous
                path: body.changes.title.previous

# ...

What I would like to have is the possibility to choose between AND or OR filter evaluation (and evaluation of conditions under each filter), so I can define only one single sensor for all above requirements.

@whynowy

whynowy commented Dec 5, 2021

Copy link
Copy Markdown
Member

@bygui86 - I'm surprised you have looked into the filter part of code so deeply, and thanks for all the detailed information. Please ping me on slack @whynowy, I'd like to have a discussion with you.

@bygui86

bygui86 commented Dec 5, 2021

Copy link
Copy Markdown
Contributor Author

@whynowy with pleasure, tomorrow (Monday 6.12.) I will ping you

@whynowy

whynowy commented Dec 17, 2021

Copy link
Copy Markdown
Member

Closing it as per the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants