-
Notifications
You must be signed in to change notification settings - Fork 299
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 orphaned messages in Slack #2023
Conversation
98b9b64
to
153072d
Compare
@@ -80,7 +80,8 @@ def get_alert_group(self): | |||
self.alert_group.slack_message = self | |||
self.alert_group.save(update_fields=["slack_message"]) | |||
return self.alert_group | |||
return self.alert.group |
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.
There's no alert
field on SlackMessage
@@ -217,32 +218,3 @@ def send_slack_notification(self, user, alert_group, notification_policy): | |||
pass | |||
else: | |||
raise e | |||
|
|||
@classmethod | |||
def get_alert_group_from_slack_message_payload(cls, slack_team_identity, payload): |
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.
REQUIRED_PERMISSIONS = [] | ||
ACTION_VERBOSE = "" |
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.
ACTION_VERBOSE
is not needed anymore, it was used to send messages to AG thread with information about interaction attempt. Now it's a simple warning popup in case of authorization failure.
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, nice 👍
"alert_group_pk": alert_group_pk, | ||
"message_ts": message_ts, | ||
"alert_group_pk": alert_group.pk, | ||
"message_ts": payload.get("message_ts") or payload["container"]["message_ts"], |
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.
👍
self._get_alert_group_from_action(payload) # Try to get alert_group_pk from PRESSED button | ||
or self._get_alert_group_from_message(payload) # Try to use alert_group_pk from ANY button in message | ||
or self._get_alert_group_from_slack_message_in_db(slack_team_identity, payload) # Fetch message from DB | ||
) |
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.
❤️
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
def _alert_group_action_value(self, **kwargs): | ||
""" | ||
Store organization and alert group IDs in Slack button or select menu values. | ||
alert_group_pk is used in apps.slack.scenarios.step_mixins.AlertGroupActionsMixin to get the right alert group | ||
when handling AG actions in Slack. | ||
""" | ||
|
||
data = { | ||
"organization_id": self.alert_group.channel.organization_id, | ||
"alert_group_pk": self.alert_group.pk, | ||
**kwargs, | ||
} | ||
return json.dumps(data) # Slack block elements allow to pass value as string only (max 2000 chars) |
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.
nice 👍
@@ -80,7 +80,8 @@ def get_alert_group(self): | |||
self.alert_group.slack_message = self | |||
self.alert_group.save(update_fields=["slack_message"]) | |||
return self.alert_group | |||
return self.alert.group | |||
else: |
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.
what does _alert_group
(a few lines above) refer to? I see an alert_group
reference defined, but no _alert_group
What this PR does
Reworks Slack handlers for buttons and select menus for AG Slack messages.
Current implementation
SlackMessage
instance in the DB. For such messages, clicking buttons will result in an exception and HTTP 500. See private repo issue for more info.Changes in this PR
SlackMessage
model to figure out the alert group being interacted on, instead embedalert_group_pk
to every button and use it when receiving interaction requests from Slack.SlackMessage
instance will be created on interaction). This is possible because some buttons already havealert_group_pk
embedded, and it's possible to get this data on button clicks (even if the clicked button itself doesn't havealert_group_pk
embedded).AlertGroupSlackRenderer
checking that correct data is embedded into buttons.incident
toAlert Group
.Which issue(s) this PR fixes
Related to https://github.com/grafana/oncall-private/issues/1841
Checklist
pr:no public docs
PR label added if not required)CHANGELOG.md
updated (orpr:no changelog
PR label added if not required)