-
Notifications
You must be signed in to change notification settings - Fork 4
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
feature/grace seconds #16
feature/grace seconds #16
Conversation
Doesn't work
Output
|
throttler.go
Outdated
|
||
cachedDetectionTime, hasCachedDetectionTime := dc.Get(fmt.Sprintf("%v_detectionTime", ocError.Error())) |
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.
Not in the correct place here. Grace's cache key should be set when Throttle's key is set.
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.
Thank you, let me try it
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.
Hi @chetra-tep,
I have optimized the function and tried different approaches for the Cache key. The key is set in the same function just before the Throttle key. So if I put the function into the Throttle function, then it will be more difficult to check the Grace period on the first iteration.
I think there is not much difference if it's in another function since they are still in the same parent function IsThrottledOrGraced
, and will be executed sequentially. Is there any scenario when the key shouldn't be handled at that place?
Please let me know what you think or if I misunderstood anything
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.
I ll test it first.
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.
Doesn't work
func main() {
os.Setenv("APP_NAME", "123")
os.Setenv("MS_TEAMS_ALERT_ENABLED", "test")
os.Setenv("MS_TEAMS_WEBHOOK", "true")
os.Setenv("THROTTLE_DURATION", "1")
os.Setenv("THROTTLE_GRACE_SECONDS", "5")
t := n.NewThrottler()
t.CleanThrottlingCache()
err := errors.New("ignore 000")
alert := n.NewAlert(err, nil)
alert.Notify() // false, caught by grace
time.Sleep(6 * time.Second) // wait for grace to go over
alert.Notify() // true, first alert
alert.Notify() // false, caught by throttle
time.Sleep(61 * time.Second)
alert.Notify() // false, caught by grace
time.Sleep(6 * time.Second) // wait for grace to go over
alert.Notify() // true
alert.Notify() // false, caught by throttle
}
should alert: false
should alert: true
should alert: false
should alert: false
should alert: false <-- this should be true
should alert: false
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.
thank you, I've adjusted the grace reset, so it should work now
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.
Will test. Thanks.
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.
Looks good
This is a feature to add support for grace duration in seconds. Once grace is set, alerts will be ignored until the seconds are over and then start working usually with throttling. The default for grace is 0 sec.