Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'multiple' operator to allow complex criteria matching on payload items #5482

Merged
merged 4 commits into from
Jan 24, 2022

Conversation

erceth
Copy link
Contributor

@erceth erceth commented Dec 6, 2021

The new "multiple" operator is similar to "search" except it adds some additional features. It allows multiple evaluations of the same payload item by a rule. This solves a problem brought up in #2656

Now evaluations such as the following are possible:

trigger.body.location.latitude:
  type: multiple
  condition: all2any
  pattern:
    item.value:
      type: "lessthan"
      pattern: 40
    item.value#2:
      type: "greaterthan"
      pattern: 50
trigger.body.location.longitude:
  type: multiple
  condition: all2any
  pattern:
    item.value:
      type: "greaterthan"
      pattern: -90
    item.value#2:
      type: "lessthan"
      pattern: -100

In this example the action for this criteria would occur when the latitude and longitude payload data falls outside the area specified, creating a simple box geo-fence.

There are four different criteria conditions:

  • all2all - true if all payload items match all criteria items
  • all2any - true if all payload items match any criteria items
  • any2any - true if any payload items match any criteria items
  • any2all - true if any payload items match all criteria items

When specifying payload data in the rule, the "#" symbol and text after it are ignored. This allows dictionary keys to be unique but refer to the same field. Any text can go after the hash.

Using the four different criteria conditions, inclusive or exclusive ranges for the same field are possible.

See tests for more examples.

The multiple operator could eventually replace the search operator.

Closes #2656

@pull-request-size pull-request-size bot added the size/XL PR that changes 500-999 lines. Consider splitting work into several ones that easier to review. label Dec 6, 2021
@erceth
Copy link
Contributor Author

erceth commented Dec 13, 2021

@armab, @nzlosh ,@cognifloyd
I was wondering if you had a chance to look at this pull request yet. I'm a first time contributor. Is there anything else I need to do to get it ready for review?

@erceth
Copy link
Contributor Author

erceth commented Dec 28, 2021

@armab , @nzlosh , @cognifloyd
I was wondering if you had a chance to look at this. Is this even a change that is wanted? I would like some feedback.

@arm4b arm4b requested a review from m4dcoder January 5, 2022 17:15
@arm4b arm4b added the feature label Jan 5, 2022
Copy link
Member

@arm4b arm4b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! 👍
This looks like an interesting feature cc @m4dcoder.

Added a couple of comments and questions.

st2reactor/st2reactor/rules/filter.py Outdated Show resolved Hide resolved
st2common/st2common/operators.py Outdated Show resolved Hide resolved
Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make the search operator much more useable. Thanks!

The multiple name is my only hangup with this. I like the idea of adding this functionality to search as it will make it much more useful and useable.
Thanks!

Also, I'll edit the PR description to add closes annotations.

st2common/st2common/operators.py Outdated Show resolved Hide resolved
st2reactor/st2reactor/rules/filter.py Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/L PR that changes 100-499 lines. Requires some effort to review. and removed size/XL PR that changes 500-999 lines. Consider splitting work into several ones that easier to review. labels Jan 17, 2022
@erceth erceth force-pushed the multiple-operator branch 2 times, most recently from 89003aa to b4f00aa Compare January 17, 2022 23:59
Copy link
Member

@arm4b arm4b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes!

Left a couple more comments.
Think about this PR just as adding 2 new criteria.

Please prepare the corresponding documentation for the new criteria in the https://docs.stackstorm.com/rules.html#advanced-comparison so we could merge everything in one go.
Additionally, we'll need a changelog for this PR: https://github.com/StackStorm/st2/blob/master/CHANGELOG.rst

st2common/st2common/operators.py Outdated Show resolved Hide resolved
st2common/st2common/operators.py Outdated Show resolved Hide resolved
@erceth erceth force-pushed the multiple-operator branch from b4f00aa to c742b2f Compare January 19, 2022 18:39
@erceth
Copy link
Contributor Author

erceth commented Jan 19, 2022

I believe I have made all the changes asked of me. Here is a link to the documentation pull request. StackStorm/st2docs#1106

Copy link
Member

@cognifloyd cognifloyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow. That's a lot simpler. That really helps me to see the diff with search.
Looks fantastic!

@cognifloyd cognifloyd requested a review from arm4b January 20, 2022 03:55
@arm4b arm4b added this to the 3.7.0 milestone Jan 21, 2022
Copy link
Member

@arm4b arm4b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, everyone! 👍

Just waiting for st2docs final adjustments to merge this.

@erceth
Copy link
Contributor Author

erceth commented Jan 24, 2022

Docs updated

@arm4b arm4b merged commit 956a13f into StackStorm:master Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature size/L PR that changes 100-499 lines. Requires some effort to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow multiple evaluations of the same field in a rule
3 participants