Skip to content

Add label-based Slack channel routing - #7

Merged
smolaon merged 2 commits into
mainfrom
slack-label-routing
Jul 15, 2026
Merged

Add label-based Slack channel routing#7
smolaon merged 2 commits into
mainfrom
slack-label-routing

Conversation

@smolaon

@smolaon smolaon commented Jul 13, 2026

Copy link
Copy Markdown

Summary

  • Route alerts to different Slack channels based on pod label rules (token mode only)
  • Each route lists label regexes (all must match, unanchored — use ^...$ to anchor) and one or more target channels; all matching routes apply, channels deduplicated in first-seen order
  • Events matching no route, and label-less messages (PVC alerts, startup ping), fall back to the default channel; webhook mode is unchanged and ignores routes with a warning
  • Invalid routes config (bad regex, missing labels/channels) fails provider init loudly; per-channel post failures are aggregated with errors.Join and don't block remaining channels
  • Composes with the SLACK_TOKEN/SLACK_CHANNEL env fallback (feat(slack): Add environment variable fallback for config #6): credentials come from the Secret-backed env vars, while the non-secret routes stay in the ConfigMap-mounted config file

Config example

alert:
  slack:
    # token/channel may come from SLACK_TOKEN/SLACK_CHANNEL env instead
    channel: "#alerts-default"
    routes:
      - labels:
          app: "^payments-.*"
          tier: "backend"
        channels:
          - "#payments-alerts"
          - "#backend-oncall"

Test plan

  • 9 new unit tests: route parsing, init validation failures, webhook-mode ignore, AND-matching/dedup/fallback semantics, multi-channel SendEvent routing, SendMessage default channel, error aggregation
  • go build ./..., go vet, package tests green after rebase onto main (includes added support for slack token #3 token support and feat(slack): Add environment variable fallback for config #6 env fallback)
  • End-to-end config round-trip verified through the real LoadConfigNewSlack path
  • Manual: run against a dev cluster with a real bot token (token must be invited to each routed channel)

🤖 Generated with Claude Code

Route alerts to different Slack channels based on pod label rules.
Each route lists label regexes (all must match) and one or more target
channels; all matching routes apply with channels deduplicated. Events
matching no route, and label-less messages (PVC alerts, startup ping),
fall back to the default channel. Token mode only; webhook mode ignores
routes with a warning.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@smolaon
smolaon force-pushed the slack-label-routing branch from 6a714d3 to 05561a6 Compare July 13, 2026 14:49
@smolaon
smolaon changed the base branch from slack-token to main July 13, 2026 14:49
A route with includeDefault: true also sends matching events to the
default channel (dual-send), without hardcoding its name in the route.
Needed because the default channel may come from the SLACK_CHANNEL
environment variable and vary per deployment.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@smolaon

smolaon commented Jul 14, 2026

Copy link
Copy Markdown
Author

Added includeDefault per-route option (commit 1fe926c): a matching route can also notify the default channel without hardcoding its name — needed for dual-send when the default channel comes from the SLACK_CHANNEL env var. Branch image published as kwatch:exaforce-1fe926c75c2576175b158ff1c76505baf8cbbb06.

@smolaon
smolaon merged commit 83a084c into main Jul 15, 2026
2 checks passed
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.

2 participants