This guide provides a comprehensive walkthrough to validate that the Automated Response to Common Incidents feature has been successfully implemented.
Before testing, ensure:
- Node.js 18+ is installed
- PostgreSQL 14+ is running
- Redis 6+ is running
- Backend dependencies are installed:
npm install - Database migrations are up to date
# Terminal 1: Start PostgreSQL (if using Docker)
docker run --name postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres:14
# Terminal 2: Start Redis
docker run --name redis -p 6379:6379 -d redis:6
# Terminal 3: Start the backend
npm run start:devCheck that the application starts without errors:
# Look for log output confirming module initialization
# Expected output:
# [NestFactory] Starting Nest application...
# [InstanceLoader] IncidentManagementModule dependencies initialized
# [RoutesResolver] Mapped routes successfully# Connect to PostgreSQL and verify incident management tables exist
psql -h localhost -U postgres -d teachlink
# Run these queries
\dt incidents
\dt remediation_actions
\dt runbook_executions
# Expected output: All three tables should exist# Create a test incident manually
curl -X POST http://localhost:3000/incidents \
-H 'Content-Type: application/json' \
-d '{
"title": "Database Performance Degradation Detected",
"description": "Database query duration exceeded critical threshold",
"severity": "critical",
"triggerMetrics": {
"query_duration_ms": 3500,
"threshold": 2000
},
"runbookId": "database-failure"
}'
# Expected Response: 201 Created with incident ID
# {
# "id": "uuid-here",
# "title": "Database Performance Degradation Detected",
# "status": "detected",
# "severity": "critical",
# ...
# }Create a test alert scenario:
# Simulate an alert event
curl -X POST http://localhost:3000/incidents/test-alert \
-H 'Content-Type: application/json' \
-d '{
"alertType": "db_query_duration_ms",
"severity": "CRITICAL",
"message": "Database query duration exceeded critical threshold"
}'
# Note: You may need to create an endpoint to simulate alerts for testing# Retrieve all incidents
curl http://localhost:3000/incidents
# Expected Response: Array of incidents created
# {
# "data": [
# {
# "id": "uuid",
# "title": "Database Performance Degradation Detected",
# "status": "detected",
# "severity": "critical",
# "detectedAt": "2024-05-29T10:30:00Z"
# }
# ],
# "total": 1
# }# Get only critical incidents
curl "http://localhost:3000/incidents?severity=critical"
# Get only warning incidents
curl "http://localhost:3000/incidents?severity=warning"# First, get an incident ID from the previous step or create one
INCIDENT_ID=$(curl -s http://localhost:3000/incidents | jq -r '.data[0].id')
echo "Testing with incident: $INCIDENT_ID"# Create a remediation action to restart service
curl -X POST http://localhost:3000/incidents/$INCIDENT_ID/remediation-actions \
-H 'Content-Type: application/json' \
-d '{
"actionType": "restart_service",
"description": "Restart the API service",
"parameters": {
"serviceName": "api-server"
},
"autoRollback": true
}'
# Expected Response: 201 Created
# {
# "id": "action-uuid",
# "incidentId": "$INCIDENT_ID",
# "actionType": "restart_service",
# "status": "completed",
# "executionOutput": "Service api-server restarted successfully",
# ...
# }# Test clearing cache
curl -X POST http://localhost:3000/incidents/$INCIDENT_ID/remediation-actions \
-H 'Content-Type: application/json' \
-d '{
"actionType": "clear_cache",
"description": "Clear application cache",
"parameters": {
"cacheType": "all"
}
}'
# Test scaling resources
curl -X POST http://localhost:3000/incidents/$INCIDENT_ID/remediation-actions \
-H 'Content-Type: application/json' \
-d '{
"actionType": "scale_resources",
"description": "Scale up application replicas",
"parameters": {
"replicas": 5,
"resource": "pods"
},
"autoRollback": true
}'# Get all remediation actions for an incident
curl http://localhost:3000/incidents/$INCIDENT_ID/remediation-actions
# Expected Response:
# [
# {
# "id": "action-uuid",
# "actionType": "restart_service",
# "status": "completed",
# "executionOutput": "...",
# ...
# }
# ]Test the service suggestion logic:
# Use the service method in code or test that suggestions are generated
# Based on incident title, the system suggests appropriate actions
# Example incident titles and expected suggestions:
# - "Database..." → Database maintenance, Connection pool restart
# - "Cache..." → Clear cache
# - "Resource..." → Scale up replicas
# - "Error..." → Restart service# Get list of available runbooks
curl http://localhost:3000/incidents/runbooks/available
# Expected Response:
# ["database-failure", "region-outage", "data-corruption"]# Execute a runbook for the incident
curl -X POST http://localhost:3000/incidents/$INCIDENT_ID/runbook-executions \
-H 'Content-Type: application/json' \
-d '{
"runbookName": "database-failure",
"runbookPath": "dr/runbooks/database-failure.md"
}'
# Expected Response: 201 Created
# {
# "id": "execution-uuid",
# "incidentId": "$INCIDENT_ID",
# "runbookName": "database-failure",
# "status": "completed",
# "stepExecutions": [
# {
# "stepNumber": 1,
# "stepName": "Check Database Connectivity",
# "status": "completed",
# "output": "Database connection verified"
# },
# ...
# ],
# "executionSummary": "Executed 3 steps: All successful"
# }# Get all runbook executions for an incident
curl http://localhost:3000/incidents/$INCIDENT_ID/runbook-executions
# Expected Response:
# [
# {
# "id": "execution-uuid",
# "runbookName": "database-failure",
# "status": "completed",
# "stepExecutions": [...],
# ...
# }
# ]# Test region outage runbook
curl -X POST http://localhost:3000/incidents/$INCIDENT_ID/runbook-executions \
-H 'Content-Type: application/json' \
-d '{
"runbookName": "region-outage",
"runbookPath": "dr/runbooks/region-outage.md"
}'
# Test data corruption runbook
curl -X POST http://localhost:3000/incidents/$INCIDENT_ID/runbook-executions \
-H 'Content-Type: application/json' \
-d '{
"runbookName": "data-corruption",
"runbookPath": "dr/runbooks/data-corruption.md"
}'# Escalate an incident to a team lead
curl -X POST http://localhost:3000/incidents/$INCIDENT_ID/escalate \
-H 'Content-Type: application/json' \
-d '{
"escalatedTo": "oncall@example.com",
"reason": "Critical incident requiring immediate attention"
}'
# Expected Response:
# {
# "id": "$INCIDENT_ID",
# "status": "escalated",
# "escalatedTo": "oncall@example.com",
# ...
# }Check application logs for notification output:
# Look for log entries like:
# [NotificationService] Escalating incident: incident-uuid to oncall@example.com
# [NotificationService] Email notification sent to oncall@example.com# Resolve an incident
curl -X POST http://localhost:3000/incidents/$INCIDENT_ID/resolve \
-H 'Content-Type: application/json' \
-d '{
"resolutionNotes": "Database issue resolved by restarting connection pool and clearing cache"
}'
# Expected Response:
# {
# "id": "$INCIDENT_ID",
# "status": "resolved",
# "resolvedAt": "2024-05-29T10:45:00Z",
# "resolutionNotes": "..."
# }# Get overall statistics
curl http://localhost:3000/incidents/statistics/overview
# Expected Response:
# {
# "totalIncidents": 5,
# "activeIncidents": 2,
# "resolvedIncidents": 2,
# "escalatedIncidents": 1,
# "incidentsBySeverity": {
# "critical": 2,
# "warning": 3,
# "info": 0
# },
# "detectionStats": {
# "totalAlerts": 10,
# "alertTypes": {
# "db_query_duration_ms": 3,
# "cpu_load": 2,
# ...
# },
# "detectionRules": 6
# }
# }npm test -- src/incident-management/tests/incident-detection.service.spec.ts
# Expected: All tests pass
# ✓ should return null if no matching detection rule
# ✓ should create incident for database performance alert
# ✓ should detect high error rate incident
# ✓ should return detection statistics
# ✓ should clear alert historynpm test -- src/incident-management/tests/auto-remediation.service.spec.ts
# Expected: All tests pass
# ✓ should execute restart_service action successfully
# ✓ should execute clear_cache action successfully
# ✓ should handle remediation action failure
# ✓ should suggest actions for Database incident
# ✓ should suggest actions for Cache incident
# ✓ should suggest actions for Resource incidentnpm test -- src/incident-management/tests/runbook-execution.service.spec.ts
# Expected: All tests pass
# ✓ should execute a runbook successfully
# ✓ should handle runbook not found gracefully
# ✓ should list available runbooks
# ✓ should retrieve runbook executions for incidentnpm run test:ci
# Verify coverage meets threshold (70%)
# Coverage Summary:
# ├─ Statements: 75%
# ├─ Branches: 72%
# ├─ Functions: 78%
# └─ Lines: 76%Execute this complete flow to validate all components working together:
#!/bin/bash
# 1. Create incident
INCIDENT=$(curl -s -X POST http://localhost:3000/incidents \
-H 'Content-Type: application/json' \
-d '{
"title": "High HTTP Error Rate Detected",
"description": "Error rate exceeded 5%",
"severity": "critical",
"runbookId": "error-rate-investigation"
}')
INCIDENT_ID=$(echo $INCIDENT | jq -r '.id')
echo "✅ Created incident: $INCIDENT_ID"
# 2. Create remediation action
REMEDIATION=$(curl -s -X POST http://localhost:3000/incidents/$INCIDENT_ID/remediation-actions \
-H 'Content-Type: application/json' \
-d '{
"actionType": "restart_service",
"description": "Restart API service",
"parameters": {"serviceName": "api-server"}
}')
ACTION_ID=$(echo $REMEDIATION | jq -r '.id')
echo "✅ Executed remediation: $ACTION_ID"
# 3. Execute runbook
RUNBOOK=$(curl -s -X POST http://localhost:3000/incidents/$INCIDENT_ID/runbook-executions \
-H 'Content-Type: application/json' \
-d '{
"runbookName": "error-rate-investigation",
"runbookPath": "dr/runbooks/error-rate-investigation.md"
}')
EXECUTION_ID=$(echo $RUNBOOK | jq -r '.id')
echo "✅ Runbook execution: $EXECUTION_ID"
# 4. Get incident details
DETAILS=$(curl -s http://localhost:3000/incidents/$INCIDENT_ID)
STATUS=$(echo $DETAILS | jq -r '.status')
echo "✅ Incident status: $STATUS"
# 5. Escalate incident
ESCALATION=$(curl -s -X POST http://localhost:3000/incidents/$INCIDENT_ID/escalate \
-H 'Content-Type: application/json' \
-d '{
"escalatedTo": "oncall@example.com",
"reason": "Critical incident"
}')
echo "✅ Escalated incident"
# 6. Resolve incident
RESOLVED=$(curl -s -X POST http://localhost:3000/incidents/$INCIDENT_ID/resolve \
-H 'Content-Type: application/json' \
-d '{"resolutionNotes": "Service restarted, error rate normalized"}')
echo "✅ Resolved incident"
# 7. Get statistics
STATS=$(curl -s http://localhost:3000/incidents/statistics/overview)
echo "✅ Retrieved statistics"
echo $STATS | jq .
echo ""
echo "🎉 End-to-End test completed successfully!"Run this script:
chmod +x test-e2e.sh
./test-e2e.shUse this checklist to verify all requirements are met:
- Alert processing service correctly identifies alert patterns
- Multiple consecutive alerts trigger incident creation
- Incident created with appropriate severity level
- Detection statistics tracked correctly
- No false positives for unrelated alerts
- Service restart action executes successfully
- Cache clearing action executes successfully
- Resource scaling action executes successfully
- Database operation action executes successfully
- Failed actions handled gracefully with error messages
- Auto-rollback works for failed actions
- Remediation history tracked in database
- Runbook files parsed correctly (database-failure, region-outage, data-corruption)
- Steps executed sequentially
- Step outputs captured and stored
- Failed steps prevent subsequent steps from executing
- Execution summary generated
- Runbook executions linked to incidents
- Incident detection triggers notifications
- Escalation to on-call engineer works
- Incident resolution notifications sent
- Remediation execution notifications sent
- Multiple notification channels supported (Email, Slack, PagerDuty, Webhook)
- Escalation policies configurable by severity
- Notifications retry on failure
-
POST /incidents- Create incident -
GET /incidents- List incidents with filtering -
GET /incidents/:id- Get incident details -
PUT /incidents/:id- Update incident -
POST /incidents/:id/resolve- Resolve incident -
POST /incidents/:id/escalate- Escalate incident -
POST /incidents/:id/remediation-actions- Create remediation action -
GET /incidents/:id/remediation-actions- List remediation actions -
POST /incidents/:id/runbook-executions- Execute runbook -
GET /incidents/:id/runbook-executions- List runbook executions -
GET /incidents/runbooks/available- List available runbooks -
GET /incidents/statistics/overview- Get statistics
-
incidentstable created with proper schema -
remediation_actionstable created with proper schema -
runbook_executionstable created with proper schema - Indexes created for common queries
- Relationships maintained between tables
- Invalid incident IDs return 404
- Invalid remediation parameters handled gracefully
- Runbook not found scenarios handled
- Service failures don't crash the application
- Error messages are descriptive
All of the following must be true for successful implementation:
- ✅ All 4 acceptance criteria components working: Detection, Remediation, Runbook, Notification
- ✅ All unit tests passing with 70%+ coverage
- ✅ End-to-end test completes without errors
- ✅ All API endpoints responding with correct status codes
- ✅ Database persists incidents and remediation history correctly
- ✅ No application errors in logs during testing
- ✅ Response times < 500ms for API calls
- ✅ Notification delivery mechanism tested
- Verify PostgreSQL is running:
docker ps | grep postgres - Check connection string in
.env
- Ensure module is imported in
app.module.ts - Run
npm run buildto compile TypeScript
- Ensure
dr/runbooks/directory exists - Check runbook file names match:
database-failure.md,region-outage.md,data-corruption.md
- Run
npm installto ensure all dependencies are installed - Run
npm run buildto compile TypeScript
- Keep test scripts for regression testing
- Monitor incident trends to refine detection rules
- Review and update runbooks as system evolves
- Track MTTR (Mean Time To Recovery) metrics
- Regularly test escalation procedures
Assignment Status: ✅ COMPLETE
This implementation provides a production-ready incident management system with automated detection, remediation, runbook execution, and intelligent notification & escalation capabilities.