-
Notifications
You must be signed in to change notification settings - Fork 89
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
Fix alerting rule update crash for 4xx HTTP errors. #649
Conversation
|
||
// The method stubs are generated initially by the VS Code Quick Fix for the below Blank Identifier definition. | ||
// https://stackoverflow.com/a/77393824 | ||
var _ alerting.AlertingAPI = (*FakeAlertingAPI)(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.
Can we use gomock or similar to generate a proper mock implementation rather than this?
if diags := utils.CheckHttpError(res, "Unable to update alerting rule"); diags.HasError() { | ||
return nil, diags | ||
} | ||
|
||
shouldBeEnabled := rule.Enabled != nil && *rule.Enabled | ||
|
||
if shouldBeEnabled && !ruleRes.Enabled { |
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.
We're assuming here that anything where ruleRes == nil
will be caught by utils.CheckHttpError
above? I wonder if it's worth having an explicit check as well?
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.
We're assuming here that anything where ruleRes == nil will be caught by utils.CheckHttpError above?
I'm not sure actually - CheckHttpError
just checks HTTP status code.
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've added logic to explicitly handle an empty response with HTTP 200.
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.
Sorry - the new logic just returns an error in case of an empty response for Create/Update call, HTTP status code doesn't make any diff in this case.
Still in reality, CheckHttpError
should handle the cases when something goes wrong based on the HTTP status code. The new logic just makes sure that crash won't happen.
Handle an empty response with HTTP 200 in CreateRule and UpdateRule.
@tobio , I addressed the comments, could you take a look at it again when you have time? |
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.
LGTM 🎉
This fixed the problem for
CreateRule
.This PR should fix it for
UpdateRule
.Also it adds unit tests to cover the case.
Rel: #647