|
4 | 4 | from datetime import datetime
|
5 | 5 |
|
6 | 6 | from django.core.cache import cache
|
7 |
| -from django.utils import timezone |
8 | 7 |
|
9 | 8 | from apps.alerts.constants import ActionSource
|
10 | 9 | from apps.alerts.incident_appearance.renderers.constants import DEFAULT_BACKUP_TITLE
|
|
14 | 13 | from apps.slack.chatops_proxy_routing import make_private_metadata, make_value
|
15 | 14 | from apps.slack.constants import CACHE_UPDATE_INCIDENT_SLACK_MESSAGE_LIFETIME
|
16 | 15 | from apps.slack.errors import (
|
17 |
| - SlackAPICantUpdateMessageError, |
18 | 16 | SlackAPIChannelArchivedError,
|
19 |
| - SlackAPIChannelInactiveError, |
20 | 17 | SlackAPIChannelNotFoundError,
|
21 | 18 | SlackAPIError,
|
22 |
| - SlackAPIInvalidAuthError, |
23 | 19 | SlackAPIMessageNotFoundError,
|
24 | 20 | SlackAPIRatelimitError,
|
25 | 21 | SlackAPIRestrictedActionError,
|
26 | 22 | SlackAPITokenError,
|
27 | 23 | )
|
28 | 24 | from apps.slack.scenarios import scenario_step
|
29 |
| -from apps.slack.scenarios.slack_renderer import AlertGroupLogSlackRenderer |
30 | 25 | from apps.slack.slack_formatter import SlackFormatter
|
31 |
| -from apps.slack.tasks import ( |
32 |
| - post_or_update_log_report_message_task, |
33 |
| - send_message_to_thread_if_bot_not_in_channel, |
34 |
| - update_incident_slack_message, |
35 |
| -) |
| 26 | +from apps.slack.tasks import send_message_to_thread_if_bot_not_in_channel, update_incident_slack_message |
36 | 27 | from apps.slack.types import (
|
37 | 28 | Block,
|
38 | 29 | BlockActionType,
|
@@ -95,7 +86,6 @@ def process_signal(self, alert: Alert) -> None:
|
95 | 86 | else:
|
96 | 87 | # check if alert group was posted to slack before posting message to thread
|
97 | 88 | if not alert.group.skip_escalation_in_slack:
|
98 |
| - self._send_log_report_message(alert.group, channel_id) |
99 | 89 | self._send_message_to_thread_if_bot_not_in_channel(alert.group, channel_id)
|
100 | 90 | else:
|
101 | 91 | # check if alert group was posted to slack before updating its message
|
@@ -208,11 +198,6 @@ def _send_debug_mode_notice(self, alert_group: AlertGroup, channel_id: str) -> N
|
208 | 198 | blocks=blocks,
|
209 | 199 | )
|
210 | 200 |
|
211 |
| - def _send_log_report_message(self, alert_group: AlertGroup, channel_id: str) -> None: |
212 |
| - post_or_update_log_report_message_task.apply_async( |
213 |
| - (alert_group.pk, self.slack_team_identity.pk), |
214 |
| - ) |
215 |
| - |
216 | 201 | def _send_message_to_thread_if_bot_not_in_channel(self, alert_group: AlertGroup, channel_id: str) -> None:
|
217 | 202 | send_message_to_thread_if_bot_not_in_channel.apply_async(
|
218 | 203 | (alert_group.pk, self.slack_team_identity.pk, channel_id),
|
@@ -895,76 +880,6 @@ def process_signal(self, log_record: AlertGroupLogRecord) -> None:
|
895 | 880 | message.delete()
|
896 | 881 |
|
897 | 882 |
|
898 |
| -class UpdateLogReportMessageStep(scenario_step.ScenarioStep): |
899 |
| - def process_signal(self, alert_group: AlertGroup) -> None: |
900 |
| - if alert_group.skip_escalation_in_slack or alert_group.channel.is_rate_limited_in_slack: |
901 |
| - return |
902 |
| - |
903 |
| - self.update_log_message(alert_group) |
904 |
| - |
905 |
| - def update_log_message(self, alert_group: AlertGroup) -> None: |
906 |
| - slack_message = alert_group.slack_message |
907 |
| - if slack_message is None: |
908 |
| - logger.info( |
909 |
| - f"Cannot update log message for alert_group {alert_group.pk} because SlackMessage doesn't exist" |
910 |
| - ) |
911 |
| - return None |
912 |
| - |
913 |
| - slack_log_message = alert_group.slack_log_message |
914 |
| - |
915 |
| - if slack_log_message is not None: |
916 |
| - # prevent too frequent updates |
917 |
| - if timezone.now() <= slack_log_message.last_updated + timezone.timedelta(seconds=5): |
918 |
| - return |
919 |
| - |
920 |
| - attachments = AlertGroupLogSlackRenderer.render_incident_log_report_for_slack(alert_group) |
921 |
| - logger.debug( |
922 |
| - f"Update log message for alert_group {alert_group.pk}, slack_log_message {slack_log_message.pk}" |
923 |
| - ) |
924 |
| - try: |
925 |
| - self._slack_client.chat_update( |
926 |
| - channel=slack_message.channel_id, |
927 |
| - text="Alert Group log", |
928 |
| - ts=slack_log_message.slack_id, |
929 |
| - attachments=attachments, |
930 |
| - ) |
931 |
| - except SlackAPIRatelimitError as e: |
932 |
| - if not alert_group.channel.is_rate_limited_in_slack: |
933 |
| - alert_group.channel.start_send_rate_limit_message_task(e.retry_after) |
934 |
| - except SlackAPIMessageNotFoundError: |
935 |
| - alert_group.slack_log_message = None |
936 |
| - alert_group.save(update_fields=["slack_log_message"]) |
937 |
| - except ( |
938 |
| - SlackAPITokenError, |
939 |
| - SlackAPIChannelNotFoundError, |
940 |
| - SlackAPIChannelArchivedError, |
941 |
| - SlackAPIChannelInactiveError, |
942 |
| - SlackAPIInvalidAuthError, |
943 |
| - SlackAPICantUpdateMessageError, |
944 |
| - ): |
945 |
| - pass |
946 |
| - else: |
947 |
| - slack_log_message.last_updated = timezone.now() |
948 |
| - slack_log_message.save(update_fields=["last_updated"]) |
949 |
| - logger.debug( |
950 |
| - f"Finished update log message for alert_group {alert_group.pk}, " |
951 |
| - f"slack_log_message {slack_log_message.pk}" |
952 |
| - ) |
953 |
| - # check how much time has passed since slack message was created |
954 |
| - # to prevent eternal loop of restarting update log message task |
955 |
| - elif timezone.now() <= slack_message.created_at + timezone.timedelta(minutes=5): |
956 |
| - logger.debug( |
957 |
| - f"Update log message failed for alert_group {alert_group.pk}: " |
958 |
| - f"log message does not exist yet. Restarting post_or_update_log_report_message_task..." |
959 |
| - ) |
960 |
| - post_or_update_log_report_message_task.apply_async( |
961 |
| - (alert_group.pk, self.slack_team_identity.pk, True), |
962 |
| - countdown=3, |
963 |
| - ) |
964 |
| - else: |
965 |
| - logger.debug(f"Update log message failed for alert_group {alert_group.pk}: " f"log message does not exist.") |
966 |
| - |
967 |
| - |
968 | 883 | STEPS_ROUTING: ScenarioRoute.RoutingSteps = [
|
969 | 884 | {
|
970 | 885 | "payload_type": PayloadType.INTERACTIVE_MESSAGE,
|
|
0 commit comments