Skip to content

Fix Slack notification grouping with label-based channel override#2030

Merged
arikalon1 merged 2 commits intomasterfrom
claude/fix-slack-channel-override-uLCCt
Mar 19, 2026
Merged

Fix Slack notification grouping with label-based channel override#2030
arikalon1 merged 2 commits intomasterfrom
claude/fix-slack-channel-override-uLCCt

Conversation

@arikalon1
Copy link
Contributor

Summary

This PR fixes notification grouping in Slack when using channel_override with label/annotation-based templating. Previously, findings routed to different channels via label-based overrides were incorrectly grouped together. Now they are properly separated into distinct groups, summaries, and threads per channel.

Key Changes

  • slack_sink.py:

    • Added import for ChannelTransformer to resolve channels with label/annotation context
    • Resolve the target channel early in handle_notification_grouping() using the finding's labels and annotations
    • Include the resolved channel in the grouping key to ensure findings destined for different channels are grouped separately
    • Pass the pre-resolved channel to send_or_update_summary_message() to avoid re-resolving without label context
  • sender.py:

    • Updated send_or_update_summary_message() signature to accept an optional pre-resolved channel parameter
    • Modified channel resolution logic to use the passed channel when available, falling back to cluster-only resolution only when needed

Implementation Details

The fix ensures that when channel_override uses label or annotation templating, the channel resolution happens in the sink layer where full finding context (labels/annotations) is available. This resolved channel is then:

  1. Included in the grouping key to separate findings by destination channel
  2. Passed to the sender to avoid losing the label context during summary message creation

This maintains backward compatibility while properly supporting dynamic channel routing based on finding metadata.

https://claude.ai/code/session_01L3rB5LufiC9W9hGDgYMTXP

When channel_override uses labels/annotations (e.g. robusta-clusterrel-labels.severity),
grouped messages were broken in two ways:

1. The group key only used group_by attributes (e.g. cluster), so findings
   destined for different channels (sev1, sev2, sev3) were incorrectly merged
   into a single group.

2. The summary message resolved the channel with empty labels/annotations,
   falling back to the default channel instead of the override channel. Thread
   replies then went to a different channel than the summary, breaking threading.

Fix: resolve the channel per-finding and include it in the group key when
channel_override is configured, and pass the pre-resolved channel to the
summary message sender.

https://claude.ai/code/session_01L3rB5LufiC9W9hGDgYMTXP
@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

Walkthrough

This change implements channel-aware message grouping in the Slack sink. A resolved channel is determined via ChannelTransformer based on various sources (channel_override, slack_channel, cluster, and finding labels/annotations), then used to separate message groups and passed to the message sender, which conditionally accepts a channel parameter for backward compatibility.

Changes

Cohort / File(s) Summary
Slack Sink Channel Resolution
src/robusta/core/sinks/slack/slack_sink.py
Imported ChannelTransformer and integrated channel resolution logic. Introduced resolved_channel computation based on channel_override, slack_channel, cluster, and finding attributes. Extended grouping key to include resolved_channel when channel_override is set, ensuring separate message groups per channel. Pass resolved_channel to send_or_update_summary_message method.
Sender Channel Parameter
src/robusta/integrations/slack/sender.py
Added optional channel parameter to send_or_update_summary_message method. Implemented conditional channel resolution: uses provided channel directly if supplied, otherwise falls back to existing resolution logic from channel_override/slack_channel/cluster_name, maintaining backward compatibility.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly reflects the main change: fixing Slack notification grouping when using label-based channel override, which is exactly what the PR accomplishes.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the problem, key changes in both files, and implementation details.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/fix-slack-channel-override-uLCCt
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Tip

Migrating from UI to YAML configuration.

Use the @coderabbitai configuration command in a PR comment to get a dump of all your UI settings in YAML format. You can then edit this YAML file and upload it to the root of your repository to configure CodeRabbit programmatically.

@github-actions
Copy link

github-actions bot commented Mar 18, 2026

Docker image ready for 74a4338 (built in 41s)

⚠️ Warning: does not support ARM (ARM images are built on release only - not on every PR)

Use this tag to pull the image for testing.

📋 Copy commands

⚠️ Temporary images are deleted after 30 days. Copy to a permanent registry before using them:

gcloud auth configure-docker us-central1-docker.pkg.dev
docker pull us-central1-docker.pkg.dev/robusta-development/temporary-builds/robusta-runner:74a4338
docker tag us-central1-docker.pkg.dev/robusta-development/temporary-builds/robusta-runner:74a4338 me-west1-docker.pkg.dev/robusta-development/development/robusta-runner-dev:74a4338
docker push me-west1-docker.pkg.dev/robusta-development/development/robusta-runner-dev:74a4338

Patch Helm values in one line:

helm upgrade --install robusta robusta/robusta \
  --reuse-values \
  --set runner.image=me-west1-docker.pkg.dev/robusta-development/development/robusta-runner-dev:74a4338

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/robusta/core/sinks/slack/slack_sink.py`:
- Around line 54-60: Guard against missing finding.subject when resolving the
Slack channel: in the call to ChannelTransformer.template (using
self.params.channel_override, self.params.slack_channel, self.cluster_name,
finding.subject.labels, finding.subject.annotations) ensure you first check if
finding.subject is truthy and, if not, pass safe defaults (e.g., empty dicts for
labels and annotations or a default subject) so AttributeError is avoided during
channel resolution; update the code path that computes resolved_channel to
handle a missing subject before dereferencing finding.subject.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 056296d3-36d9-4093-b93c-cadb50b6b0ae

📥 Commits

Reviewing files that changed from the base of the PR and between bf02470 and edbe500.

📒 Files selected for processing (2)
  • src/robusta/core/sinks/slack/slack_sink.py
  • src/robusta/integrations/slack/sender.py

@arikalon1 arikalon1 merged commit 05324b8 into master Mar 19, 2026
5 checks passed
@arikalon1 arikalon1 deleted the claude/fix-slack-channel-override-uLCCt branch March 19, 2026 07:41
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.

3 participants