-
Notifications
You must be signed in to change notification settings - Fork 297
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
refactor SlackMessage.channel_id
(CHAR
field) to SlackMessage.channel
(foreign key relationship)
#5292
refactor SlackMessage.channel_id
(CHAR
field) to SlackMessage.channel
(foreign key relationship)
#5292
Conversation
# Don't send request for permalink if there is no slack_team_identity or slack token has been revoked | ||
if self.cached_permalink or not self.slack_team_identity or self.slack_team_identity.detected_token_revoked: |
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 verified (in production) and don't see any records where slack_team_identity
is null for SlackMessage
(fwiw, I think this field should eventually be dropped from this model and we should use slack_message.organization.slack_team_identity
instead; see comments above)
logger.warning( | ||
f"SlackMessage (pk: {self.pk}) fields _slack_team_identity and organization is None. " | ||
f"It is strange!" | ||
) |
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 wasn't able to find any mentions of this log message for the last 90 days + there's no git history available unfortunately for why this is here. As I am proposing to (eventually) drop slack_team_identity
from this model, I propose to remove this
|
||
def send_slack_notification(self, user, alert_group, notification_policy): |
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 tried removing alert_group
here (since self.alert_group
is a thing..) but it appears that when notifying a user in the Alert Group message thread, the second SlackMessage
that gets persisted (the one that represents the thread notification message) has a null
alert_group
(and I believe it had null
for another field such as organization
?)
# NOTE: the foreign key checks are disabled and re-enabled in this migration | ||
# see the following resources as to why | ||
# | ||
# https://arc.net/l/quote/hgqztayk |
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.
https://arc.net/l/quote/...
TIL 😎
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 this PR does Related to #5287 Few random "clean-ups", type improvements, etc. Additionally, fixes a change made in #5292; we should wait to read from `slack_message.channel.slack_id`, until we've performed the data-migration mentioned in that PR (in the mean-time we should continue to use `slack_message._channel_id`). ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes.
# What this PR does - As a follow-up to #5292, and now that `SlackMessage.channel` has been migrated via [`engine/apps/slack/migrations/0007_migrate_slackmessage_channel_id.py`](https://github.com/grafana/oncall/pull/5292/files#diff-8aebe133401715a4262baad9b2c5c9fc59367c18d6bd6ac2b3c462fcdabafd66), this PR removes reads/writes from `SlackMessage._channel_id` to `SlackMessage.channel`. In a separate PR I will focus on dropping that column from the model/db. - Drops `SlackMessage.active_update_task_id`. There're zero references to this column in the codebase. - Removes two Django `manage.py` commands that're no longer needed: - `engine/engine/management/commands/alertmanager_v2_migrate.py` (and it's associated tests) - `engine/engine/management/commands/batch_migrate_slack_message_channel.py` ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes.
What this PR does
Related to https://github.com/grafana/oncall-private/issues/2947
NOTE
This PR introduces steps 1 and 2 of the 3 part migration proposed here. Step 3, swapping reads to be from the new-column and dropping dual-writes, will be done in a future PR/release.
I’m tackling this work now because ultimately I want to move
AlertReceiveChannel.rate_limited_in_slack_at
toSlackChannel.rate_limited_at
, but first I sorta need to refactorSlackMessage.channel_id
from aCHAR
field to a foreign key relationship (because in the spots where we touch Slack rate limiting, like here for example, we only haveslack_message.channel_id
, which means I need to do extra queries to fetch the appropriateSlackChannel
to then be able to get/setSlackChannel.rate_limited_at
Other minor stuffs:
SlackMessage._slack_team_identity
. We already have a@property
ofSlackMessage.slack_team_identity
(which previously had some hacky logic). I've refactoredSlackMessage.slack_team_identity
to simply point toself.organization.slack_team_identity
+ updated our code to stop settingSlackMessage._slack_team_identity
(will drop this column in future release)Checklist
pr:no public docs
PR label added if not required)release:
). These labels dictate how your PR willshow up in the autogenerated release notes.