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

Range rules #154

Merged
merged 9 commits into from
Nov 20, 2023
Merged

Range rules #154

merged 9 commits into from
Nov 20, 2023

Conversation

BuJo
Copy link
Member

@BuJo BuJo commented Nov 13, 2023

  • Add a when rule to be able to match on when the alert happened.
  • Add more expressive rules, making it possible to express a
    greater than on numerical values. See README for details.
  • Breaking configuration changes:
    • The what rules are now combined via AND with label rules.
      This streamlines the behaviour, making it behave like the label
      rules themselves. It also makes it possible e.g. to express that
      a rule matcher only applies when the alert is old.

Rule changes:

  • what rules will combine as AND with label rules.
  • new when rules will combine with AND with label and what rules.

The default is to match the value in the configuration as a regular expression.
However, this can be changed by specifying an operator.

  • ~= string: Explicitly require a regular expression to be matched
  • = string: Require the string to exactly match
  • > number: Require both configuration and the value in the alert to be a
    numerical value and that the value in the alert to be bigger than the
    configured number.
    This also applies to the <, >=, <= operators.

pkg/aggregation/aggregator.go Outdated Show resolved Hide resolved
pkg/aggregation/aggregator.go Outdated Show resolved Hide resolved
pkg/aggregation/aggregator.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@DerGeras DerGeras left a comment

Choose a reason for hiding this comment

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

A few points for discussion, but overall it LGTM.

README.md Outdated Show resolved Hide resolved
pkg/aggregation/aggregator.go Show resolved Hide resolved
// meaning the rules are combined via `AND`.
matchCount := 0
for a, b := range res {
if b.MatchString(a) {
for val, matcher := range matchers {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit of nitpicking, val is used as a keyword in some programming languages, which did confuse me as well while skipping over the changes at first.
Would you consider renaming the variable?

}

func ParseRuleMatcher(label, s string) RuleMatcher {
if strings.HasPrefix(s, "~= ") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Depending on how strict you want to be here, it might be nice to use whitespaces as delimiters, instead of static prefix/startAtSymbolX. This would allow the user to i.e. align their config values.
Nice to have, being strict is fine as well.

} else if strings.HasPrefix(s, "> ") {
return newNumberMatcher(gt, s[2:])
} else if strings.HasPrefix(s, "= ") {
if _, err := strconv.ParseFloat(s[2:], 64); err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this warrants at least a note in the documentation, that "=" on numbers is not an exact equals, but, due to the nature of floats, is an approximation.

@BuJo BuJo merged commit 6dc73cb into main Nov 20, 2023
1 check passed
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.

2 participants