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: mysql error alerts when the auto ops rule is already triggered #196

Merged
merged 2 commits into from
Jan 27, 2023

Conversation

cre8ivejp
Copy link
Member

@cre8ivejp cre8ivejp commented Jan 27, 2023

If the user schedule to turn on a flag, and before the auto ops run, he enables the flag, it will treat it as an error, so I'm changing the ExecuteOperation to return nil if the operation is already done.

Things done

  • Changed to check if the ops have been triggered outside of the transaction
  • Changed not to treat as an error if no rows were affected
  • Split the logs in the operation to make debugging easier

@@ -836,6 +833,13 @@ func (s *AutoOpsService) ExecuteAutoOps(
if err := s.validateExecuteAutoOpsRequest(req, localizer); err != nil {
return nil, err
}
triggered, err := s.checkIfHasAlreadyTriggered(ctx, localizer, req.Id, req.EnvironmentNamespace)
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to move this implementation from the transaction to check if it had already been triggered because the response returns the AlreadyTriggered boolean.

https://github.com/bucketeer-io/bucketeer/pull/196/files#diff-13112ed94680ecaec33373531ff5c65e48cecae142657203e04d967a185684d5L862-L864

handler := command.NewAutoOpsCommandHandler(editor, autoOpsRule, s.publisher, req.EnvironmentNamespace)
if err := handler.Handle(ctx, req.ChangeAutoOpsRuleTriggeredAtCommand); err != nil {
return err
}
if err = autoOpsRuleStorage.UpdateAutoOpsRule(ctx, autoOpsRule, req.EnvironmentNamespace); err != nil {
if err == v2as.ErrAutoOpsRuleUnexpectedAffectedRows {
Copy link
Member Author

Choose a reason for hiding this comment

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

If there are no affected rows, it will not treat as an error. Otherwise, it might trigger the alert.

logger.Warn(
"Failed to disable feature",
if err != nil {
if code := status.Code(err); code == codes.FailedPrecondition {
Copy link
Member Author

Choose a reason for hiding this comment

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

I split the implementation to print warning and error levels to make debugging easier.

@cre8ivejp cre8ivejp requested a review from masaaania January 27, 2023 12:13
@cre8ivejp cre8ivejp changed the title chore: change no changes error handling in the auto ops fix: mysql error alerts when the auto ops rule is already triggered Jan 27, 2023
Copy link
Contributor

@masaaania masaaania left a comment

Choose a reason for hiding this comment

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

lgtm!

@cre8ivejp cre8ivejp merged commit cdd8cb6 into main Jan 27, 2023
@cre8ivejp cre8ivejp deleted the chore-autoops-error-handling branch January 27, 2023 12:25
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