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

Parse escalation condition #42

Merged
merged 6 commits into from
May 8, 2023
Merged

Parse escalation condition #42

merged 6 commits into from
May 8, 2023

Conversation

yhabteab
Copy link
Member

fixes #34

@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label Apr 28, 2023
Copy link
Collaborator

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

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

The combination of filter evaluation and error handling can result in some strange behavior. Take incident_age>=InvalidDurationLiteral as an example. This will be evaluated as EvalExists("incident_age") && !EvalLess("incident_age", "InvalidDurationLiteral"). Here, EvalLess will encounter an error and return false, making the overall expression return true.

Two options for addressing that:

  1. Make all the evaluation return (bool, error).
  2. After parsing, go over all conditions contained in it, and verify that if column is incident_age, the value must be a valid duration literal and if the column is incident_severity, the value must be a valid severity name. That would remove the possibility of an invalid literal showing up during evaluation.

internal/rule/condition.go Outdated Show resolved Hide resolved
@julianbrost
Copy link
Collaborator

I think it would be better to pass an error through the whole filter evaluation, i.e. also add error to the return type of Filter.Eval(...), otherwise you will still end up with strange behavior for !(incident_age<InvalidDurationLiteral) (that one might look constructed but with more available filter variables in the future, that might happen more easily in realistic examples).

@yhabteab
Copy link
Member Author

otherwise you will still end up with strange behavior for !(incident_age<InvalidDurationLiteral)

So what would happen in that case? I don't get it. This expression would be parsed as None(&LessThan(...)) and in Filter.LessThan#Eval() the error is being caught and handled accordingly.

@julianbrost
Copy link
Collaborator

in Filter.LessThan#Eval() the error is being caught and handled accordingly.

In the current implementation, this means it is handled just like a valid expression that was false. (Which means with a negation somewhere, this can become true again)

So what would happen in that case?

I'd expect that if any sub-expression was invalid, i.e. returned an error, the whole filter evaluation returns an error. When handling the overall filter, this will probably be handled similar to a return value, but with an additional "you're doing something broken here" log message.

@yhabteab yhabteab force-pushed the parse-escalation-condition branch 2 times, most recently from 09ea1f0 to 727a27f Compare May 3, 2023 15:43
internal/object/object_test.go Outdated Show resolved Hide resolved
internal/rule/condition.go Outdated Show resolved Hide resolved
internal/listener/listener.go Outdated Show resolved Hide resolved
internal/filter/types.go Outdated Show resolved Hide resolved
@yhabteab yhabteab force-pushed the parse-escalation-condition branch 2 times, most recently from fbe46d0 to 650269f Compare May 4, 2023 08:45
@yhabteab yhabteab requested a review from julianbrost May 4, 2023 08:46
internal/object/object_test.go Outdated Show resolved Hide resolved
internal/filter/types.go Outdated Show resolved Hide resolved
@yhabteab yhabteab force-pushed the parse-escalation-condition branch from 650269f to 170106a Compare May 5, 2023 08:00
@yhabteab yhabteab force-pushed the parse-escalation-condition branch from 170106a to 9355ba5 Compare May 5, 2023 08:00
@julianbrost
Copy link
Collaborator

@yhabteab Please have a look at the changes I added on top.

@yhabteab
Copy link
Member Author

yhabteab commented May 5, 2023

4119344 🤦

@julianbrost
Copy link
Collaborator

Is that supposed to say that I can merge this PR? 😅

@julianbrost julianbrost merged commit f92cf79 into main May 8, 2023
@julianbrost julianbrost deleted the parse-escalation-condition branch May 8, 2023 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Escalation Condition Parsing
3 participants