-
Notifications
You must be signed in to change notification settings - Fork 490
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
Resetting alert levels #740
Resetting alert levels #740
Conversation
This is what I think of, however I believe it needs more improvements. Will make some more changes in the next days : ) |
@@ -116,6 +116,8 @@ type AlertNode struct { | |||
critsTriggered *expvar.Int | |||
|
|||
bufPool sync.Pool | |||
|
|||
level_resets []stateful.Expression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go is an opinionated language and prefers camelCase names. Can you change this to levelResets
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. I've changed the variables to camelCase format. : )
@nathanielc I've just pushed a test with its sample data. Please have a look at them to see it's the expected behavior of this feature.
Say first we have a data point with a value of Let's examine another data point with a value of |
@minhdanh Thanks for the detailed example. I think we are on the same page. Your example makes sense to me, (I probably inverted the logic earlier when I was talking about the true/false value of the reset expression) To make sure we are on the same page here are a few more examples:
Given the above criteria the following data points create the following alert levels.
Now for a slightly different example
This is how I would expect it to work. |
@nathanielc I updated the test and its sample data with the values in your first example. I could make the test pass on my machine. Should I write another test for the latter example, or just add another tick script and call the same functions in |
@minhdanh I'd prefer each test to test a single aspect of the behavior, so creating another test is fine. I took a quick look at the tests and they look good. |
@@ -4110,7 +4110,7 @@ stream | |||
} | |||
} | |||
|
|||
func TestStream_Alert_WithReset(t *testing.T) { | |||
func TestStream_Alert_WithReset_0(t *testing.T) { | |||
requestCount := int32(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nathanielc I'm not sure how to name two test functions of the same feature so I split them into TestStream_Alert_WithReset_0
and TestStream_Alert_WithReset_1
. What do you think?
@nathanielc I've implemented your new way. All the tests pass except Here is the output for that test:
|
} else if !pass { | ||
return currentLevel | ||
} else { | ||
if newLevel, err := a.findFirstMatchLevel(currentLevel-1, OKAlert, now, fields, tags); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try this. The change is that if the reset expression does not exist then we need to check the rest of the normal expressions below or equal to our current level.
if higherLevel, err := a.findFirstMatchLevel(CritAlert, currentLevel-1, now, fields, tags); err == nil {
return higherLevel
}
if rse := a.levelResets[currentLevel]; rse != nil {
if pass, err := EvalPredicate(rse, a.lrScopePools[currentLevel], now, fields, tags); err != nil {
a.logger.Printf("E! error evaluating reset expression for current level %v: %s", currentLevel, err)
} else if !pass {
return currentLevel
}
// fall through to check the rest of the levels.
}
if newLevel, err := a.findFirstMatchLevel(currentLevel, OKAlert, now, fields, tags); err == nil {
return newLevel
}
return OKAlert
Also there is some error handling missing for the last bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works like a charm. Thank you so much 💃
@nathanielc I've just applied the fixes and updated CHANGELOG.md. Is there anything else need to be done? |
@minhdanh OK, I have re-reviewed the entire PR. I just have two small recommendations:
Thanks a ton! |
@nathanielc I changed the error type to bool type to indicate that if a match was found. The function |
@minhdanh LGTM, thanks for all the work! |
My pleasure. I couldn't make it without your help. Thank you very much. |
Good stuff! Thanks @minhdanh and @nathanielc ! |
In regard to this issue #614
This pull request should enable lowering alert levels using lamda expressions.
Only WARN and CRIT levels are supported, INFO level is not.
I'm still trying to come up with some tests for this.