Stop posting new slack log reports (#4750)

Stop posting a new message, as it is available from the button
(https://github.com/grafana/oncall/pull/4641)
This is an intermediate step, so we will only update posted messages but
not post new ones
Once the majority of messages are updated, we can remove this step
(https://github.com/grafana/oncall/pull/4686)
This commit is contained in:
Ildar Iskhakov 2024-07-29 20:16:36 +08:00 committed by GitHub
parent e5075315d1
commit 5a9f124ba7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 49 deletions

View file

@ -902,54 +902,6 @@ class UpdateLogReportMessageStep(scenario_step.ScenarioStep):
self.update_log_message(alert_group)
def post_log_message(self, alert_group: AlertGroup) -> None:
slack_message = alert_group.slack_message
if slack_message is None:
logger.info(f"Cannot post log message for alert_group {alert_group.pk} because SlackMessage doesn't exist")
return None
slack_log_message = alert_group.slack_log_message
if slack_log_message is None:
logger.debug(f"Start posting new log message for alert_group {alert_group.pk}")
try:
result = self._slack_client.chat_postMessage(
channel=slack_message.channel_id,
thread_ts=slack_message.slack_id,
text="Building escalation plan... :thinking_face:",
)
except SlackAPIRatelimitError as e:
if not alert_group.channel.is_rate_limited_in_slack:
alert_group.channel.start_send_rate_limit_message_task(e.retry_after)
logger.info(
f"Log message has not been posted for alert_group {alert_group.pk} due to slack rate limit."
)
except (
SlackAPITokenError,
SlackAPIChannelNotFoundError,
SlackAPIInvalidAuthError,
SlackAPIChannelArchivedError,
):
pass
else:
logger.debug(f"Create new slack_log_message for alert_group {alert_group.pk}")
slack_log_message = alert_group.slack_messages.create(
slack_id=result["ts"],
organization=self.organization,
_slack_team_identity=self.slack_team_identity,
channel_id=slack_message.channel_id,
last_updated=timezone.now(),
)
alert_group.slack_log_message = slack_log_message
alert_group.save(update_fields=["slack_log_message"])
logger.debug(
f"Finished post new log message for alert_group {alert_group.pk}, "
f"slack_log_message with pk '{slack_log_message.pk}' was created."
)
else:
self.update_log_message(alert_group)
def update_log_message(self, alert_group: AlertGroup) -> None:
slack_message = alert_group.slack_message
if slack_message is None:

View file

@ -305,7 +305,10 @@ def post_or_update_log_report_message_task(alert_group_pk, slack_team_identity_p
if update: # flag to prevent multiple posting log message to slack
step.update_log_message(alert_group)
else:
step.post_log_message(alert_group)
# don't post a new message, as it is available from the button
# this is an intermediate step, so we will only update posted messages but not post new ones
# once majority of messages are updated, we can remove this step (https://github.com/grafana/oncall/pull/4686)
pass
logger.debug(f"Finish post_or_update_log_report_message_task for alert_group {alert_group_pk}")