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

Fix alerting rule update crash for 4xx HTTP errors. #649

Merged
merged 8 commits into from
Jun 5, 2024

Conversation

dimuon
Copy link
Contributor

@dimuon dimuon commented May 30, 2024

This fixed the problem for CreateRule.
This PR should fix it for UpdateRule.
Also it adds unit tests to cover the case.

Rel: #647

@dimuon dimuon marked this pull request as ready for review May 30, 2024 14:33
@dimuon dimuon requested review from tobio and a team May 30, 2024 14:39

// 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)
Copy link
Member

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 {
Copy link
Member

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?

Copy link
Contributor Author

@dimuon dimuon May 31, 2024

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@dimuon
Copy link
Contributor Author

dimuon commented Jun 3, 2024

@tobio , I addressed the comments, could you take a look at it again when you have time?

Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@dimuon dimuon merged commit 559478b into elastic:main Jun 5, 2024
18 checks passed
@dimuon dimuon deleted the fix-alerting-crash branch June 5, 2024 08:29
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