Skip to content

notify/slack: copy initial message as thread reply when updating in place - #5622

Open
ilyaluk wants to merge 1 commit into
prometheus:mainfrom
ilyaluk:slack-thread-keep-initial-message
Open

ilyaluk wants to merge 1 commit into
prometheus:mainfrom
ilyaluk:slack-thread-keep-initial-message

Conversation

@ilyaluk

@ilyaluk ilyaluk commented Oct 1, 2026

Copy link
Copy Markdown

With both update_message and post_updates_to_thread set, the first notification for an alert group posts a message to the channel. Every later notification for that group edits that message in place and posts the same content as a reply in its thread.

The in-place edit discards the original text, so for a group that fires once and then resolves, the channel ends up with the root message showing the resolved state and a single thread reply with exactly the same content, and the firing notification is gone. With more updates the loss is smaller, but the first state of the group still disappears from the thread.

This PR makes the first notification also post a copy of the initial message as the first reply in its own thread, right after the root message is created. Later notifications still edit the root and append replies, so the thread holds the full history: the original notification followed by each update. Nothing changes when only one of the two options is set.

If posting the copy fails, the notification fails and is retried, same as when a thread reply fails. The root message's ts and channel are stored by then, so the retry goes through the update path and posts the reply to the existing thread instead of creating a new root message. Fallback behaviour on unrecoverable errors was left out, as discussed in the #5540 review.

I could put this behind its own option if you prefer, but I'm afraid of complicating the Slack configuration too much.

Another alternative is to post the original text as a reply only right before the first update is sent to the thread. That avoids the odd look of a fresh message that immediately has a reply with the same content, but the reply's timestamp would then be the time of the first update rather than of the original notification, and the message content would need to be retrieved from the Slack API or stored in nflog.

Pull Request Checklist

Please check all the applicable boxes.

Which user-facing changes does this PR introduce?

[ENHANCEMENT] slack: Post the initial message as the first thread reply when `update_message` and `post_updates_to_thread` are both set.

…g in place

With update_message and post_updates_to_thread both set, every notification
after the first edits the root message in place and posts the same content
as a thread reply. The edit discards the original text: a group that fires
and then resolves ends up as a resolved root message plus one identical
resolved reply, and the firing notification is gone.

Post a copy of the initial message as the first thread reply right after
the root message is created, so the thread keeps the full history.

Signed-off-by: Ilya Lukyanov <ilya@luk.moe>
@ilyaluk
ilyaluk requested a review from a team as a code owner October 1, 2026 18:58
@coderabbitai

coderabbitai Bot commented Oct 1, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: prometheus/alertmanager/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: a41fdef2-054e-49fb-8954-12c3546447fc

📥 Commits

Reviewing files that changed from the base of the PR and between 61ba43d and 6e231f2.

📒 Files selected for processing (4)
  • docs/configuration.md
  • notify/slack/config.go
  • notify/slack/slack.go
  • notify/slack/slack_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

When Slack message updates and thread posting are both enabled, the notifier posts the initial message and then copies it as the first reply in its thread. Tests cover thread-copy retries, operation without a store, and firing and resolution sequences.

Changes

Slack thread notifications

Layer / File(s) Summary
Initial post and thread copy
notify/slack/slack.go, notify/slack/config.go, docs/configuration.md
The notifier returns a failed initial-post verdict. When both options are enabled and a store is available, it posts the initial message as the first thread reply. The configuration comments describe this behavior.
Retry and refiring coverage
notify/slack/slack_test.go
Tests cover a failed thread copy followed by retry, posting without a store, and initial firing, refiring, and resolution requests.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Notifier as Slack notifier
  participant Store as nflog store
  participant Slack as Slack API
  Notifier->>Slack: Post initial message
  Slack-->>Notifier: Return post result and timestamp
  Notifier->>Store: Check for stored thread identifiers
  Store-->>Notifier: Return identifier availability
  Notifier->>Slack: Post initial message as thread reply
Loading

Merge Risk: ⚪ Minimal · up to 6e231

The initial notification is preserved as a thread reply when both options are enabled. Retry handling and existing notification modes remain intact; no actionable merge-blocking risk was identified. Merge after normal checks pass.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the Slack area and the primary change: copying the initial message as a thread reply when updating in place.
Description check ✅ Passed The description explains the current behavior, the problem, the implementation, retry behavior, unchanged cases, tests, documentation, sign-off, and release notes. It also identifies the related issue…
Linked Issues check ✅ Passed Issue #3221 is closed and completed. It supplies historical context only. No active directly linked issue supplies coding requirements for this pull request.
Out of Scope Changes check ✅ Passed The changes stay within Slack thread notification behavior. The implementation adds the initial thread reply, failure retry coverage, and behavior for missing stores. The documentation and tests suppo…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ilyaluk

ilyaluk commented Oct 1, 2026

Copy link
Copy Markdown
Author

Example:

Before After

@SoloJacobs SoloJacobs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, interesting. I guess the trade-off here is whether we want to send an additional http request here vs. how much nicer this new way is to read. You could probably achieve the same history by turning off update_message, I guess?

@ilyaluk

ilyaluk commented Oct 1, 2026

Copy link
Copy Markdown
Author

I guess the trade-off here is whether we want to send an additional http request here vs. how much nicer this new way is to read.

Yeah, exactly

You could probably achieve the same history by turning off update_message, I guess?

Almost! What I'm trying to get is:

  • the full history of an alert group in one thread
  • the current state of each group visible by skimming the channel

update_message + post_updates_to_thread loses the first notification from history. Disabling update_message loses the second point.

An alternative: we previously had an SNS -> Slack lambda that behaved like update_message: false + post_updates_to_thread: true, and added a ✅️ reaction to the root message once the group resolved. If that approach makes more sense to you, I can add an option for it instead, though it needs the reactions:write scope.

Wdyt?

@SoloJacobs

Copy link
Copy Markdown
Contributor

Hi @ilyaluk ,

Thanks for the write-up. During the maintainer meetup we have discussed this feature, and we decided that it makes the most sense to go with the ✅️ reaction. The reason is that the other maintainers maintain similar functionality inside their forks, and also I just think the feature is more transparent. This should be behind a different feature flag and document the reactions:write permission.

Kind regards

@ilyaluk

ilyaluk commented Oct 7, 2026 •

Copy link
Copy Markdown
Author

Hey @SoloJacobs, thanks for your consideration!

Sounds good, will send a follow-up PR in the coming days. Do you think it would make sense to make reaction customizable (e.g. a react_on_resolution: ':white_check_mark:' flag which will enable this behavior), or plain react_on_resolution: true with hard-coded reaction? Do you have any preferences for flag naming?

@SoloJacobs

SoloJacobs commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Hi @ilyaluk ,

sorry I missed this message. Both are reasonable. I guess it would be good to have some validation for the emoji?

Kind regards, Solomon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send subsequent notifications to a slack thread instead of channel

2 participants