Add webhook and Slack alert channels (FEAT-6) - #34
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds two more alert channels alongside the existing Email and Null sinks.
src/spero/alerting/webhook.py): POSTs a JSON event{"event": "fire"|"resolve", "target": ..., "detail": ...}to a configured URL viahttpx.AsyncClientwith a bounded timeout.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 = ""andslack_webhook_url: str = ""(empty = channel disabled).make_alerter(settings)inalerting/__init__.py: returnsSlackAlerterifslack_webhook_urlis set, elseWebhookAlerterifalert_webhook_urlis set, elseNullAlerter.Tests
tests/test_alerters.pyuseshttpx.MockTransportto assert the exact payload and URL onfire()/resolve()for both alerters, that a network error is swallowed (no exception), and thatmake_alerterselects the right channel.Gates
ruff check .cleanruff format --check .cleanmypycleanpytestgreen (full suite, 8 new tests)Scope kept to
src/spero/alerting/,src/spero/config.py, andtests/only.