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

Improve Slack error handling #3000

Merged
merged 13 commits into from
Sep 12, 2023
Merged

Improve Slack error handling #3000

merged 13 commits into from
Sep 12, 2023

Conversation

vadimkerr
Copy link
Member

@vadimkerr vadimkerr commented Sep 8, 2023

What this PR does

  • Rename SlackClientWithErrorHandling to just SlackClient
  • Add more error classes + improve the way errors are raised based on the Slack error code
  • Add API call retries on Slack server errors (e.g. when Slack returns 5xx errors)
  • Refactor some methods working with Slack API + add tests

Which issue(s) this PR fixes

Checklist

  • Unit, integration, and e2e (if applicable) tests updated
  • Documentation added (or pr:no public docs PR label added if not required)
  • CHANGELOG.md updated (or pr:no changelog PR label added if not required)

@vadimkerr vadimkerr added the pr:no public docs Added to a PR that does not require public documentation updates label Sep 8, 2023
@vadimkerr vadimkerr changed the title Refactor Slack error handling Improve Slack error handling Sep 11, 2023
Comment on lines -55 to -66
except SlackAPIException as e:
if e.response["error"] == "message_not_found": # message deleted from channel
logger.info(f"Skip updating slack message for alert_group {alert_group.pk} due message_not_found")
elif e.response["error"] == "is_inactive": # deleted channel error
logger.info(f"Skip updating slack message for alert_group {alert_group.pk} due to is_inactive")
elif e.response["error"] == "account_inactive":
logger.info(f"Skip updating slack message for alert_group {alert_group.pk} due to account_inactive")
elif e.response["error"] == "channel_not_found":
logger.info(f"Skip updating slack message for alert_group {alert_group.pk} due to channel_not_found")
else:
raise e
logger.info(f"Finished _update_slack_message for alert_group {alert_group.pk}")
Copy link
Member Author

Choose a reason for hiding this comment

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

Removing logging here as errors are already logged in SlackClient.api_call

def __init__(self, msg: str, response: SlackResponse):
super().__init__(msg)
self.response = response
class SlackServerErrorRetryHandler(RetryHandler):
Copy link
Member Author

Choose a reason for hiding this comment

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

⬆️ One of the main changes in the PR

response = super(SlackClientWithErrorHandling, self).api_call(*args, **kwargs)
except SlackApiError as err:
response = err.response
def api_call(self, *args, **kwargs) -> SlackResponse:
Copy link
Member Author

Choose a reason for hiding this comment

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

⬆️ One of the main changes in the PR

body: str


class SlackAPIError(Exception):
Copy link
Member Author

Choose a reason for hiding this comment

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

⬆️ One of the main changes in the PR

@vadimkerr vadimkerr self-assigned this Sep 11, 2023
Comment on lines -133 to -134
# Trying same request with access token. It is required due to migration to granular permissions
# and can be removed after clients reinstall their bots
Copy link
Member Author

Choose a reason for hiding this comment

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

can be removed after clients reinstall their bots

The switch to granular permissions happened a long time ago so I think it's safe to remove this

@vadimkerr vadimkerr marked this pull request as ready for review September 11, 2023 15:40
@vadimkerr vadimkerr requested a review from a team September 11, 2023 15:40
Copy link
Contributor

@matiasb matiasb left a comment

Choose a reason for hiding this comment

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

LGTM, a couple of minor questions.

engine/apps/slack/client.py Outdated Show resolved Hide resolved
@vadimkerr vadimkerr added this pull request to the merge queue Sep 12, 2023
Merged via the queue into dev with commit 8b2212c Sep 12, 2023
19 of 20 checks passed
@vadimkerr vadimkerr deleted the vadimkerr/slack-errors branch September 12, 2023 09:54
Copy link
Contributor

@joeyorlando joeyorlando left a comment

Choose a reason for hiding this comment

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

awesome cleanup/deduplication of the error handling logic 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:no public docs Added to a PR that does not require public documentation updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants