feat: add real-time alerting MVP (webhook + slack)#4
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: db1a2aa38a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| bucket, ok := a.buckets[key] | ||
| if !ok || bucket.windowStart.IsZero() { | ||
| a.buckets[key] = aggregateWindowBucket{windowStart: now, suppressed: 0} | ||
| return true, 1 |
There was a problem hiding this comment.
Evict stale alert aggregation buckets
alertWindowAggregator.Record adds a new entry for every unseen aggregation key but never removes old keys, so with alerting enabled a high-cardinality client_key/path stream (including spoofed X-Forwarded-For values) will make buckets grow without bound and steadily increase process memory over long runtimes. Adding TTL-based cleanup or bounded eviction before inserting new keys would prevent this leak-like behavior.
Useful? React with 👍 / 👎.
Summary
Implements Phase 3 Step 3 real-time alerting MVP with async fail-open delivery and two sinks:
This PR keeps existing inbound API behavior intact and adds outbound alerting for:
injection_blockedrate_limit_exceeded(window-based aggregate)scan_error(window-based aggregate)What Changed
alerting.*config surface +PIF_ALERTING_*env overrides.pif_alert_events_totalpif_alert_sink_deliveries_totalWebhook + Slack [x],PagerDuty [ ]Public Interface Notes
alerting.*,PIF_ALERTING_*.Validation Evidence
Local tests
go test ./...-> PASSgo test -race ./...-> PASSmalformed LC_DYSYMTAB), tests still pass.go test ./... -coverprofile=coverage.outgo tool cover -func=coverage.out | tail -n 1total: (statements) 81.4%Behavior verified by tests
Scope/Non-goals