From 872f1e35e19523101b0fad2e5f431a8d991af6bc Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Mon, 6 Jan 2025 16:35:39 -0500 Subject: [PATCH] fix: update direct paging integration non-default route data (#5397) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Which issue(s) this PR closes This is a quick db migration follow-up to https://github.com/grafana/oncall/pull/5382. It's mostly just an enhancement. Basically #5382 had created a new/non-default route for each Direct Paging integration. However, I overlooked actually setting the chatops/escalation chain data for this new route: ![Screenshot 2025-01-06 at 3 55 19 PM](https://github.com/user-attachments/assets/6c9e68c3-64b7-47e2-9de6-34edd151b505) This PR simply updates the recently created non-default direct paging integration route, such that, to start, direct paging a team has no escalation/notification difference whether the user doing the direct paging sets important = True or False. From here, teams can modify these routes to their needs (ex. setup and assign different escalation chains for these different routes). ## Checklist - [ ] 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. --- ...t_paging_integration_non_default_routes.py | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 engine/apps/alerts/migrations/0073_update_direct_paging_integration_non_default_routes.py diff --git a/engine/apps/alerts/migrations/0073_update_direct_paging_integration_non_default_routes.py b/engine/apps/alerts/migrations/0073_update_direct_paging_integration_non_default_routes.py new file mode 100644 index 000000000..8696c6ad1 --- /dev/null +++ b/engine/apps/alerts/migrations/0073_update_direct_paging_integration_non_default_routes.py @@ -0,0 +1,56 @@ +# Generated by Django 4.2.17 on 2025-01-06 15:48 + +import logging + +from django.db import migrations +from django.db.models import Subquery, OuterRef + +logger = logging.getLogger(__name__) + + +def update_direct_paging_integration_non_default_routes(apps, schema_editor): + """ + If any of the original Direct Paging integration default routes had chatops settings or escalation chains + associated with them, simply set the non-default route to have the same settings. This will avoid any functional + differences should users start paging a team using the "important" functionality. + """ + ChannelFilter = apps.get_model("alerts", "ChannelFilter") + + logger.info("Starting update_direct_paging_integration_non_default_routes migration...") + + # Subquery that selects the matching "default" channel filter for each non-default filter + default_route_subquery = ChannelFilter.objects.filter( + alert_receive_channel=OuterRef("alert_receive_channel"), + is_default=True + ) + + # Perform a bulk update on all non-default routes in one go + updated_count = ( + ChannelFilter.objects + .filter( + alert_receive_channel__integration="direct_paging", + is_default=False + ) + .update( + escalation_chain_id=Subquery(default_route_subquery.values("escalation_chain_id")[:1]), + telegram_channel_id=Subquery(default_route_subquery.values("telegram_channel_id")[:1]), + notify_in_telegram=Subquery(default_route_subquery.values("notify_in_telegram")[:1]), + slack_channel_id=Subquery(default_route_subquery.values("slack_channel_id")[:1]), + notify_in_slack=Subquery(default_route_subquery.values("notify_in_slack")[:1]), + notification_backends=Subquery(default_route_subquery.values("notification_backends")[:1]), + ) + ) + + logger.info(f"Updated {updated_count} non-default direct paging integration routes") + logger.info("Finished update_direct_paging_integration_non_default_routes migration.") + + +class Migration(migrations.Migration): + + dependencies = [ + ("alerts", "0072_upsert_direct_paging_integration_routes"), + ] + + operations = [ + migrations.RunPython(update_direct_paging_integration_non_default_routes, migrations.RunPython.noop), + ]