Djones-qa/incident-response-hub
GitHub: Djones-qa/incident-response-hub
一个微服务架构的生产事件全生命周期管理平台,提供事件追踪、值班升级、运行手册自动化和复盘分析功能。
Stars: 0 | Forks: 0
# 事件响应中心
[](https://github.com/Djones-qa/incident-response-hub/actions/workflows/ci.yml)
[](https://www.typescriptlang.org/)
[](https://nodejs.org/)
[](https://redis.io/)
[](https://www.postgresql.org/)
[](https://kubernetes.io/)
[](https://www.docker.com/)
[](LICENSE)
事件响应与复盘管理平台。这是一个用于管理生产事件完整生命周期的分布式系统——从事件声明到调查、缓解、解决以及复盘分析。
## 架构
```
┌─────────────────────────────────────────────────────────────────┐
│ Kubernetes Cluster │
│ │
│ ┌──────────────────┐ ┌─────────────────────┐ ┌────────────┐ │
│ │ incident-engine │ │notification-service │ │ analytics │ │
│ │ (port 4000) │ │ (port 4001) │ │(port 4002) │ │
│ └────────┬─────────┘ └──────────┬──────────┘ └─────┬──────┘ │
│ │ │ │ │
│ └───────────┬────────────┴────────────────────┘ │
│ │ │
│ ┌────────▼────────┐ │
│ │ runbook-worker │ │
│ │ (consumer) │ │
│ └────────┬────────┘ │
│ │ │
│ ┌───────────┴───────────┐ │
│ │ │ │
│ ┌─────▼─────┐ ┌──────▼──────┐ │
│ │PostgreSQL │ │ Redis │ │
│ │ (15) │ │ (7) │ │
│ └───────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────────┘
```
### 服务
| 服务 | 端口 | 描述 |
|---------|------|-------------|
| **incident-engine** | 4000 | 核心领域逻辑——事件、时间线、严重程度、状态、响应者、复盘、运行手册、触发器匹配 |
| **notification-service** | 4001 | 通知发送、升级策略、自动升级计时器 |
| **analytics-service** | 4002 | MTTR、频率、趋势、 recurring 模式、团队绩效 |
| **runbook-worker** | — | 后台消费者——执行运行手册步骤、处理重试/回滚、报告进度 |
### 通信
服务通过 Redis Streams 进行通信,以实现事件驱动和松耦合的交互:
- `stream:runbook-executions` — 触发运行手册执行
- `stream:notifications` — 发送通知请求
- `stream:incident-events` — 用于自动升级的事件状态变更
- `stream:execution-progress` — 运行手册步骤进度报告
## 快速开始
```
# 启动基础设施 (PostgreSQL + Redis)
docker-compose up -d
# 等待服务变为健康状态
docker-compose ps
# 服务将可以通过以下地址访问:
# - incident-engine: http://localhost:4000
# - notification-service: http://localhost:4001
# - analytics-service: http://localhost:4002
```
## 开发环境设置
```
# 前提条件:Node.js 20+, Docker
# 安装依赖
npm install
# 构建所有 packages 和服务
npm run build
# 运行所有测试
npm test
# 运行特定的 test suites
npm run test:unit # Unit tests only
npm run test:property # Property-based tests only
npm run test:integration # Integration tests (requires Docker)
```
## API Endpoints
### incident-engine (端口 4000)
| 方法 | 路径 | 描述 |
|--------|------|-------------|
| POST | `/incidents` | 声明新事件 |
| GET | `/incidents` | 列出事件(带过滤器) |
| GET | `/incidents/:id` | 按 ID 获取事件 |
| PATCH | `/incidents/:id/status` | 转换状态 |
| PATCH | `/incidents/:id/severity` | 升级严重程度 |
| POST | `/incidents/:id/responders` | 分配响应者 |
| POST | `/incidents/:id/timeline` | 添加时间线条目 |
| GET | `/incidents/:id/timeline` | 获取事件时间线 |
| POST | `/incidents/:id/postmortem` | 生成复盘 |
| GET | `/incidents/:id/postmortem` | 获取复盘 |
| POST | `/runbooks` | 创建运行手册 |
| GET | `/runbooks` | 列出运行手册 |
| GET | `/runbooks/:id` | 获取运行手册 |
| POST | `/runbooks/:id/execute` | 触发执行 |
| GET | `/incidents/:id/suggested-runbooks` | 获取匹配的运行手册 |
| GET | `/health` | 存活探针 |
| GET | `/ready` | 就绪探针 |
### notification-service (端口 4001)
| 方法 | 路径 | 描述 |
|--------|------|-------------|
| POST | `/notifications` | 发送通知 |
| GET | `/incidents/:id/notifications` | 列出事件的相关通知 |
| POST | `/escalation-policies` | 创建升级策略 |
| GET | `/escalation-policies` | 列出策略 |
| GET | `/escalation-policies/:id` | 获取策略 |
| GET | `/health` | 存活探针 |
| GET | `/ready` | 就绪探针 |
### analytics-service (端口 4002)
| 方法 | 路径 | 描述 |
|--------|------|-------------|
| GET | `/metrics/mttr` | 按严重程度划分的 MTTR |
| GET | `/metrics/frequency` | 随时间变化的事件频率 |
| GET | `/metrics/trends` | 周环比趋势 |
| GET | `/metrics/severity-distribution` | 严重程度分布 |
| GET | `/metrics/recurring-patterns` | recurring 服务模式 |
| GET | `/metrics/team-performance` | 团队响应指标 |
| GET | `/health` | 存活探针 |
| GET | `/ready` | 就绪探针 |
## 技术栈
| 类别 | 技术 |
|----------|-----------|
| 语言 | TypeScript 5.3 |
| 运行时 | Node.js 20 |
| 框架 | Express.js |
| 数据库 | PostgreSQL 15 |
| 缓存/Streams | Redis 7 |
| 编排 | Kubernetes 1.28 |
| 容器化 | Docker |
| CI/CD | GitHub Actions |
| 测试 | Jest + fast-check (基于属性) |
| 代码检查 | ESLint + Prettier |
## 项目结构
```
incident-response-hub/
├── packages/
│ ├── shared-types/ # Shared TypeScript interfaces
│ ├── shared-utils/ # Common utilities (validation, dates, errors)
│ └── test-helpers/ # Shared test generators and helpers
├── services/
│ ├── incident-engine/ # Core incident management service
│ ├── notification-service/ # Notification & escalation service
│ ├── analytics-service/ # Metrics & analytics service
│ └── runbook-worker/ # Background runbook executor
├── k8s/ # Kubernetes manifests
├── scripts/ # Development & operational scripts
├── docker-compose.yml # Local development infrastructure
└── .github/workflows/ # CI/CD pipeline
```
## 事件生命周期
```
declared → investigating → mitigating → resolved → closed
```
- 状态转换严格呈线性(不能回退,不能跳过)
- 在活跃状态下,严重程度只能升级(low → medium → high → critical)
- 解决事件需要一个类型为 "resolution" 的时间线条目
- 复盘报告会根据事件数据按需自动生成
## 作者
**Darrius Jones** ([@Djones-qa](https://github.com/Djones-qa))
## 许可证
MIT © 2024 Darrius Jones
标签:GNU通用公共许可证, IT运维, MITM代理, Node.js, PostgreSQL, Redis, Socks5代理, TypeScript, 事件管理系统, 子域名突变, 安全插件, 搜索引擎查询, 测试用例, 自动化攻击, 请求拦截