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

Refactor AlertGroup.slack_message #2957

Merged
merged 15 commits into from
Sep 4, 2023
Merged

Conversation

vstpme
Copy link
Member

@vstpme vstpme commented Sep 4, 2023

What this PR does

Refactors the foreign key relationship between AlertGroup and SlackMessage models (see https://github.com/grafana/oncall-private/issues/1867 for more info).

Which issue(s) this PR fixes

https://github.com/grafana/oncall-private/issues/1867

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)

@vstpme vstpme added pr:no public docs Added to a PR that does not require public documentation updates pr:no changelog labels Sep 4, 2023
Comment on lines +13 to +18
operations = [
common.migrations.remove_field.RemoveFieldState(
model_name='AlertGroup',
name='slack_message',
),
]
Copy link
Member Author

Choose a reason for hiding this comment

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

Remove AlertGroup.slack_message so the only FK left is SlackMessage.alert_group

Comment on lines -64 to -79
if e.response["error"] == "message_not_found":
logger.info(f"message_not_found for alert_group {alert_group.pk}, trying to post new message")
result = self._slack_client.api_call(
"chat.postMessage", channel=slack_message.channel_id, attachments=attachments, blocks=blocks
)
slack_message_updated = SlackMessage(
slack_id=result["ts"],
organization=slack_message.organization,
_slack_team_identity=slack_message.slack_team_identity,
channel_id=slack_message.channel_id,
alert_group=alert_group,
)
slack_message_updated.save()
alert_group.slack_message = slack_message_updated
alert_group.save(update_fields=["slack_message"])
logger.info(f"Message has been posted 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 this logic completely because it's hard to maintain with the new FK structure.
I think it makes more sense to just ignore deleted AG Slack messages instead of trying to post a new message (why post a message one more time if the user already decided they don't want to see it and deleted it?)

@vstpme vstpme marked this pull request as ready for review September 4, 2023 15:14
@vstpme vstpme requested a review from a team September 4, 2023 15:14
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.

I see you are removing the field following the guideline 👍 , so I guess there will be a PR later removing the column from the DB, right?

@vstpme
Copy link
Member Author

vstpme commented Sep 4, 2023

@matiasb yes, the DB field will be dropped in a future release.

@vstpme vstpme added this pull request to the merge queue Sep 4, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 4, 2023
@vstpme vstpme added this pull request to the merge queue Sep 4, 2023
Merged via the queue into dev with commit a2851d3 Sep 4, 2023
@vstpme vstpme deleted the vadimkerr/slack-alert-group-fks branch September 4, 2023 18:09
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.

2 participants