Skip to content

Feature/dlq external alerts#169

Merged
robertocarlous merged 7 commits into
Neurowealth:mainfrom
strngecloud:feature/dlq-external-alerts
Jun 16, 2026
Merged

Feature/dlq external alerts#169
robertocarlous merged 7 commits into
Neurowealth:mainfrom
strngecloud:feature/dlq-external-alerts

Conversation

@strngecloud

Copy link
Copy Markdown
Contributor

DLQ External Alerting Implementation

Summary

Wires DLQ size alerts to Slack/PagerDuty with configurable thresholds and deduplication. Replaces hardcoded logging with a pluggable AlertingService supporting multiple notification channels.

Changes

Core Implementation

  • AlertingService (src/services/alerting.ts): New singleton service with support for LOG, SLACK, and PAGERDUTY channels
    • Automatic alert deduplication using configurable cooldown (default 15 min)
    • Rich DLQ alert payloads including size, status breakdown, oldest event age
    • Admin dashboard links for quick inspection
  • DLQ Integration (src/stellar/dlq.ts): Replaced hardcoded threshold with config-driven alerting
    • Uses config.dlq.alertThreshold from environment
    • Emits structured alerts with actionable metadata
    • Tracks and formats event age in human-readable format
    • Clears alert state when queue normalizes below threshold

Configuration

  • Environment Variables (.env.example):
    • DLQ_ALERT_THRESHOLD: Queue size alert threshold (default: 50)
    • DLQ_ALERT_COOLDOWN_MS: Deduplication window (default: 15 min)
    • SLACK_WEBHOOK_URL: Optional Slack integration
    • PAGERDUTY_ROUTING_KEY: Optional PagerDuty integration
    • ADMIN_DASHBOARD_URL: Admin console URL for inspection links

Observability

  • Prometheus Metric (src/utils/metrics.ts): New dlq_alert_active gauge
    • Tracks whether alert is currently active (1 = active, 0 = inactive)
    • Useful for monitoring alert state in Prometheus/Grafana

Testing & Documentation

  • Unit Tests (tests/unit/stellar/dlq-alerts.test.ts): Comprehensive test coverage

    • Singleton pattern verification
    • Cooldown/deduplication behavior
    • Severity level handling
    • Alert state management
  • Runbook (docs/DLQ_ALERTING_RUNBOOK.md): Operator guide

    • Step-by-step alert response procedures
    • Common root causes and recovery strategies
    • Integration setup instructions
    • Prometheus monitoring examples
    • Escalation procedures

Acceptance Criteria Met

DLQ_ALERT_THRESHOLD from env is the single source of truth
✅ Crossing threshold triggers external notification (Slack/PagerDuty) when configured
✅ Alert includes actionable metadata (size, status breakdown, oldest pending age, admin link)
✅ Cooldown prevents duplicate alerts within configured window
✅ Unit tests for threshold logic and cooldown behavior
✅ Runbook section: "What to do when DLQ alert fires" with inspect → dry-run retry → resolve workflow

Backward Compatibility

✅ Fully backward compatible

  • LOG channel always enabled (existing behavior preserved)
  • All new external channels are optional
  • Graceful fallback if external services are unavailable

Closes #163

- Create new AlertingService with singleton pattern
- Support LOG, SLACK, and PAGERDUTY channels
- Implement alert deduplication/cooldown (15 min default)
- Support rich DLQ alert payloads with metadata
- Export types for DLQAlertPayload
- New gauge tracks whether DLQ alert is currently active
- Set to 1 when threshold exceeded, 0 when normalized
- Useful for monitoring alert state in Prometheus/Grafana
- DLQ_ALERT_COOLDOWN_MS: Control alert deduplication window (default 15min)
- Support SLACK_WEBHOOK_URL for Slack integration
- Support PAGERDUTY_ROUTING_KEY for PagerDuty integration
- Add ADMIN_DASHBOARD_URL for inspection links
Replace hardcoded SIZE_ALERT_THRESHOLD with configurable config.dlq.alertThreshold
- Emit rich DLQ alerts with metadata (size, status breakdown, oldest event age)
- Include actionable admin dashboard links
- Support alert deduplication to prevent fatigue
- Calculate status breakdown (pending, retried, resolved counts)
- Track oldest pending event and human-readable age
- Clear alert state when queue normalizes

Closes Neurowealth#163
Add documentation for:
- DLQ_ALERT_COOLDOWN_MS
- SLACK_WEBHOOK_URL
- PAGERDUTY_ROUTING_KEY
- ADMIN_DASHBOARD_URL
- Test AlertingService singleton pattern
- Test cooldown/deduplication behavior
- Test alert suppression within cooldown window
- Test alert re-emission after cooldown expires
- Test DLQ alert payload formatting
- Test all alert severity levels (critical, warning, info)
- Test LOG channel always enabled
- Test alert state clearing
Complete guide for handling DLQ alerts:
- Inspection and diagnosis steps
- Common root causes and recovery procedures
- Manual retry procedures
- Integration setup (Slack, PagerDuty)
- Prometheus monitoring examples
- Prevention best practices
- Escalation procedures
@robertocarlous robertocarlous merged commit 8683676 into Neurowealth:main Jun 16, 2026
0 of 3 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.

[Critical] Wire DLQ size alerts to Slack/PagerDuty and use configurable threshold

2 participants