Skip to content

Commit

Permalink
chore: remove deprecated slack_channel and heartbeat integration …
Browse files Browse the repository at this point in the history
…types (#5270)

# What this PR does

See [Slack
discussion](https://raintank-corp.slack.com/archives/C06K1MQ07GS/p1732110700877869)
for more context

## 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.
  • Loading branch information
joeyorlando authored Nov 20, 2024
1 parent 336b924 commit fda05a6
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 133 deletions.
2 changes: 1 addition & 1 deletion dev/helm-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ engine:
replicaCount: 1
celery:
replicaCount: 1
worker_beat_enabled: false
worker_beat_enabled: true

externalGrafana:
url: http://grafana:3000
Expand Down
18 changes: 5 additions & 13 deletions engine/apps/alerts/models/alert_receive_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,29 +525,21 @@ def short_name(self):
)

@property
def short_name_with_maintenance_status(self):
if self.maintenance_mode is not None:
return (
self.short_name + f" *[ on "
f"{AlertReceiveChannel.MAINTENANCE_MODE_CHOICES[self.maintenance_mode][1]}"
f" :construction: ]*"
)
else:
return self.short_name

@property
def created_name(self):
def created_name(self) -> str:
return f"{self.get_integration_display()} {self.smile_code}"

@property
def web_link(self) -> str:
return UIURLBuilder(self.organization).integration_detail(self.public_primary_key)

@property
def is_maintenace_integration(self) -> bool:
return self.integration == AlertReceiveChannel.INTEGRATION_MAINTENANCE

@property
def integration_url(self) -> str | None:
if self.integration in [
AlertReceiveChannel.INTEGRATION_MANUAL,
AlertReceiveChannel.INTEGRATION_SLACK_CHANNEL,
AlertReceiveChannel.INTEGRATION_INBOUND_EMAIL,
AlertReceiveChannel.INTEGRATION_MAINTENANCE,
]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.16 on 2024-11-20 15:39

from django.db import migrations
import django_migration_linter as linter


class Migration(migrations.Migration):

dependencies = [
('heartbeat', '0002_delete_heartbeat'),
]

operations = [
linter.IgnoreMigration(),
migrations.RemoveField(
model_name='integrationheartbeat',
name='actual_check_up_task_id',
),
migrations.RemoveField(
model_name='integrationheartbeat',
name='last_checkup_task_time',
),
]
10 changes: 0 additions & 10 deletions engine/apps/heartbeat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ class IntegrationHeartBeat(models.Model):
Stores the latest received heartbeat signal time
"""

last_checkup_task_time = models.DateTimeField(default=None, null=True)
"""
Deprecated. This field is not used. TODO: remove it
"""

actual_check_up_task_id = models.CharField(max_length=100)
"""
Deprecated. Stored the latest scheduled `integration_heartbeat_checkup` task id. TODO: remove it
"""

previous_alerted_state_was_life = models.BooleanField(default=True)
"""
Last status of the heartbeat. Determines if integration was alive on latest checkup
Expand Down
6 changes: 0 additions & 6 deletions engine/apps/heartbeat/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ def _get_timeout_expression() -> ExpressionWrapper:
return f"Found {expired_count} expired and {restored_count} restored heartbeats"


@shared_dedicated_queue_retry_task()
def integration_heartbeat_checkup(heartbeat_id: int) -> None:
"""Deprecated. TODO: Remove this task after this task cleared from queue"""
pass


@shared_dedicated_queue_retry_task()
def process_heartbeat_task(alert_receive_channel_pk):
IntegrationHeartBeat.objects.filter(
Expand Down
2 changes: 0 additions & 2 deletions engine/apps/heartbeat/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@


class IntegrationHeartBeatFactory(factory.DjangoModelFactory):
actual_check_up_task_id = "none"

class Meta:
model = IntegrationHeartBeat
5 changes: 1 addition & 4 deletions engine/apps/integrations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ def create_alertmanager_alerts(alert_receive_channel_pk, alert, is_demo=False, r
from apps.alerts.models import Alert, AlertReceiveChannel

alert_receive_channel = AlertReceiveChannel.objects_with_deleted.get(pk=alert_receive_channel_pk)
if (
alert_receive_channel.deleted_at is not None
or alert_receive_channel.integration == AlertReceiveChannel.INTEGRATION_MAINTENANCE
):
if alert_receive_channel.deleted_at is not None or alert_receive_channel.is_maintenace_integration:
logger.info("AlertReceiveChannel alert ignored if deleted/maintenance")
return

Expand Down
1 change: 0 additions & 1 deletion engine/apps/public_api/tests/test_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,6 @@ def test_get_list_integrations_link_and_inbound_email(

if integration_type in [
AlertReceiveChannel.INTEGRATION_MANUAL,
AlertReceiveChannel.INTEGRATION_SLACK_CHANNEL,
AlertReceiveChannel.INTEGRATION_MAINTENANCE,
]:
assert integration_link is None
Expand Down
5 changes: 2 additions & 3 deletions engine/apps/slack/alert_group_slack_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ def __init__(
self._slack_client = SlackClient(slack_team_identity)

def update_alert_group_slack_message(self, alert_group: "AlertGroup") -> None:
from apps.alerts.models import AlertReceiveChannel

logger.info(f"Update message for alert_group {alert_group.pk}")

try:
self._slack_client.chat_update(
channel=alert_group.slack_message.channel_id,
Expand All @@ -47,7 +46,7 @@ def update_alert_group_slack_message(self, alert_group: "AlertGroup") -> None:
)
logger.info(f"Message has been updated for alert_group {alert_group.pk}")
except SlackAPIRatelimitError as e:
if alert_group.channel.integration != AlertReceiveChannel.INTEGRATION_MAINTENANCE:
if not alert_group.channel.is_maintenace_integration:
if not alert_group.channel.is_rate_limited_in_slack:
alert_group.channel.start_send_rate_limit_message_task(e.retry_after)
logger.info(
Expand Down
18 changes: 1 addition & 17 deletions engine/apps/slack/scenarios/distribute_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,6 @@ def _post_alert_group_to_slack(
channel_id=channel_id,
)

# If alert was made out of a message:
if alert_group.channel.integration == AlertReceiveChannel.INTEGRATION_SLACK_CHANNEL:
channel = json.loads(alert.integration_unique_data)["channel"]
result = self._slack_client.chat_postMessage(
channel=channel,
thread_ts=json.loads(alert.integration_unique_data)["ts"],
text=":rocket: <{}|Incident registered!>".format(alert_group.slack_message.permalink),
team=slack_team_identity,
)
alert_group.slack_messages.create(
slack_id=result["ts"],
organization=alert_group.channel.organization,
_slack_team_identity=self.slack_team_identity,
channel_id=channel,
)

alert.delivered = True
except SlackAPITokenError:
alert_group.reason_to_skip_escalation = AlertGroup.ACCOUNT_INACTIVE
Expand All @@ -172,7 +156,7 @@ def _post_alert_group_to_slack(
logger.info("Not delivering alert due to channel is archived.")
except SlackAPIRatelimitError as e:
# don't rate limit maintenance alert
if alert_group.channel.integration != AlertReceiveChannel.INTEGRATION_MAINTENANCE:
if not alert_group.channel.is_maintenace_integration:
alert_group.reason_to_skip_escalation = AlertGroup.RATE_LIMITED
alert_group.save(update_fields=["reason_to_skip_escalation"])
alert_group.channel.start_send_rate_limit_message_task(e.retry_after)
Expand Down
29 changes: 0 additions & 29 deletions engine/config_integrations/heartbeat.py

This file was deleted.

44 changes: 0 additions & 44 deletions engine/config_integrations/slack_channel.py

This file was deleted.

2 changes: 0 additions & 2 deletions engine/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,11 +878,9 @@ class BrokerTypes:
"config_integrations.formatted_webhook",
"config_integrations.kapacitor",
"config_integrations.elastalert",
"config_integrations.heartbeat",
"config_integrations.inbound_email",
"config_integrations.maintenance",
"config_integrations.manual",
"config_integrations.slack_channel",
"config_integrations.zabbix",
"config_integrations.direct_paging",
# Actually it's Grafana 8 integration.
Expand Down
1 change: 0 additions & 1 deletion engine/settings/celery_task_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"common.oncall_gateway.tasks.delete_oncall_connector_async": {"queue": "default"},
"common.oncall_gateway.tasks.create_slack_connector_async_v2": {"queue": "default"},
"common.oncall_gateway.tasks.delete_slack_connector_async_v2": {"queue": "default"},
"apps.heartbeat.tasks.integration_heartbeat_checkup": {"queue": "default"},
"apps.heartbeat.tasks.process_heartbeat_task": {"queue": "default"},
"apps.labels.tasks.update_labels_cache": {"queue": "default"},
"apps.labels.tasks.update_instances_labels_cache": {"queue": "default"},
Expand Down

0 comments on commit fda05a6

Please sign in to comment.