Skip to content

Add webhook and Slack alert channels (FEAT-6) - #34

Merged
joy-software merged 1 commit into
mainfrom
feature/alerters
Jun 7, 2026
Merged

Add webhook and Slack alert channels (FEAT-6)#34
joy-software merged 1 commit into
mainfrom
feature/alerters

Conversation

@joy-software

Copy link
Copy Markdown
Contributor

What

Adds two more alert channels alongside the existing Email and Null sinks.

  • WebhookAlerter (src/spero/alerting/webhook.py): POSTs a JSON event {"event": "fire"|"resolve", "target": ..., "detail": ...} to a configured URL via httpx.AsyncClient with a bounded timeout.
  • SlackAlerter (src/spero/alerting/slack.py): POSTs a Slack incoming-webhook {"text": "..."} message for fire/resolve.

Both follow the alerting layer's best-effort contract: network errors (httpx.HTTPError, timeouts, connect failures) are caught and swallowed, so a flaky endpoint never stalls or crashes a supervision cycle.

Config

  • alert_webhook_url: str = "" and slack_webhook_url: str = "" (empty = channel disabled).
  • make_alerter(settings) in alerting/__init__.py: returns SlackAlerter if slack_webhook_url is set, else WebhookAlerter if alert_webhook_url is set, else NullAlerter.

Tests

tests/test_alerters.py uses httpx.MockTransport to assert the exact payload and URL on fire()/resolve() for both alerters, that a network error is swallowed (no exception), and that make_alerter selects the right channel.

Gates

  • ruff check . clean
  • ruff format --check . clean
  • mypy clean
  • pytest green (full suite, 8 new tests)

Scope kept to src/spero/alerting/, src/spero/config.py, and tests/ only.

Two HTTP alerters that POST over httpx with a bounded timeout and the
same best-effort contract as the rest of the alerting layer: network
errors are caught and swallowed so a flaky endpoint never stalls or
crashes a supervision cycle.

- WebhookAlerter: generic JSON event POST ({event, target, detail}).
- SlackAlerter: Slack incoming-webhook {"text": ...} message.
- config: alert_webhook_url and slack_webhook_url (empty = disabled).
- make_alerter(settings): Slack wins over webhook, else NullAlerter.
- tests: httpx.MockTransport asserts payload + URL on fire/resolve,
  swallowed network error, and make_alerter selection.
@joy-software
joy-software merged commit 2542e4c into main Jun 7, 2026
8 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.

1 participant