From 61d456ce3cfadb032ac3fb42c7f358eeb5a7c0bf Mon Sep 17 00:00:00 2001 From: Michael Derynck Date: Wed, 31 May 2023 07:49:40 -0600 Subject: [PATCH] Limit on Attach To action in Slack (#2049) # What this PR does Reduce number of alert groups returned for grouping on slack request to 20 to avoid event trigger expiry. ## Which issue(s) this PR fixes https://github.com/grafana/oncall-private/issues/1835 ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --------- Co-authored-by: Joey Orlando --- CHANGELOG.md | 1 + engine/apps/slack/scenarios/distribute_alerts.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40232600..17700252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Properly address `Organization.DoesNotExist` exceptions thrown which result in HTTP 500 for the Slack `interactive_api_endpoint` endpoint by @joeyorlando ([#2040](https://github.com/grafana/oncall/pull/2040)) - Fix issue when trying to sync Grafana contact point and config receivers miss a key ([#2046](https://github.com/grafana/oncall/pull/2046)) +- Reduce number of alert groups returned by `Attach To` in slack to avoid event trigger timeout @mderynck ([#2049](https://github.com/grafana/oncall/pull/2049)) ### Changed diff --git a/engine/apps/slack/scenarios/distribute_alerts.py b/engine/apps/slack/scenarios/distribute_alerts.py index a916255d..7b67a991 100644 --- a/engine/apps/slack/scenarios/distribute_alerts.py +++ b/engine/apps/slack/scenarios/distribute_alerts.py @@ -37,6 +37,8 @@ from common.utils import clean_markup, is_string_with_visible_characters from .step_mixins import CheckAlertIsUnarchivedMixin, IncidentActionsAccessControlMixin +ATTACH_TO_ALERT_GROUPS_LIMIT = 20 + logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) @@ -398,7 +400,7 @@ class SelectAttachGroupStep( .order_by("-pk") ) - for alert_group_to_attach in alert_groups_queryset[:60]: + for alert_group_to_attach in alert_groups_queryset[:ATTACH_TO_ALERT_GROUPS_LIMIT]: # long_verbose_name_without_formatting was removed from here because it increases queries count due to # alerts.first(). # alert_group_to_attach.alerts.exists() and alerts.all()[0] don't make additional queries to db due to @@ -435,7 +437,7 @@ class SelectAttachGroupStep( "text": "Attach to...", }, "action_id": AttachGroupStep.routing_uid(), - "options": collected_options[:60], + "options": collected_options[:ATTACH_TO_ALERT_GROUPS_LIMIT], }, "label": { "type": "plain_text",