From 357b5c47c6034c1fb556dbdbf5540fb49fcab8b4 Mon Sep 17 00:00:00 2001 From: Michael Derynck Date: Fri, 8 Nov 2024 19:42:11 -0700 Subject: [PATCH] Limit slack block text length when rendering alert group timeline (#5246) # What this PR does Limit length of text in block being posted to slack when showing alert group timeline. ## Which issue(s) this PR closes Related to [issue link here] ## 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. --- engine/apps/slack/scenarios/alertgroup_timeline.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/engine/apps/slack/scenarios/alertgroup_timeline.py b/engine/apps/slack/scenarios/alertgroup_timeline.py index 08f74b88..7ca3a56f 100644 --- a/engine/apps/slack/scenarios/alertgroup_timeline.py +++ b/engine/apps/slack/scenarios/alertgroup_timeline.py @@ -2,6 +2,7 @@ import typing from apps.api.permissions import RBACPermission from apps.slack.chatops_proxy_routing import make_private_metadata +from apps.slack.constants import BLOCK_SECTION_TEXT_MAX_SIZE from apps.slack.scenarios import scenario_step from apps.slack.scenarios.slack_renderer import AlertGroupLogSlackRenderer from apps.slack.types import ( @@ -47,9 +48,13 @@ class OpenAlertGroupTimelineDialogStep(AlertGroupActionsMixin, scenario_step.Sce future_log_report = AlertGroupLogSlackRenderer.render_alert_group_future_log_report_text(alert_group) blocks: typing.List[Block.Section] = [] if past_log_report: - blocks.append({"type": "section", "text": {"type": "mrkdwn", "text": past_log_report}}) + blocks.append( + {"type": "section", "text": {"type": "mrkdwn", "text": past_log_report[:BLOCK_SECTION_TEXT_MAX_SIZE]}} + ) if future_log_report: - blocks.append({"type": "section", "text": {"type": "mrkdwn", "text": future_log_report}}) + blocks.append( + {"type": "section", "text": {"type": "mrkdwn", "text": future_log_report[:BLOCK_SECTION_TEXT_MAX_SIZE]}} + ) view: ModalView = { "blocks": blocks,