M0-05 Traffic Protection & Resilience 基础版 #5

Closed
opened 2026-05-22 21:00:15 +08:00 by wangdl · 2 comments
Owner

## 架构实施计划

### 限流层次



### 技术选型

| 组件 | 选型 | 原因 |
|------|------|------|
| 限流引擎 | @nestjs/throttler | NestJS 原生集成,Guard/Decorator 模式 |
| 存储后端 | Redis | 高性能计数,支持分布式 |
| 超时控制 | RxJS timeout + Interceptor | 全局 30s,可覆盖 |

### 文件结构

- src/common/throttle/throttle.module.ts — 全局限流模块
- src/common/throttle/redis-throttler.storage.ts — Redis 存储适配器
- src/common/interceptors/timeout.interceptor.ts — 30s 超时
- src/modules/admin-throttle/ — Admin 限流状态 AAPI

### 使用方式



### Admin AAPI

| 端点 | 说明 |
|------|------|
| GET /admin-api/throttle/status | 当前限流规则和状态 |

交付检查

  • 全局限流 — ThrottlerModule + AppThrottleModule
  • Redis 存储 — RedisThrottlerStorage
  • 超时控制 — TimeoutInterceptor 30s
  • Admin AAPI — GET /admin-api/throttle/status
  • 登录限流 — @AdminLoginRateLimit() 已有
  • Admin 限流配置视图 系统运维→限流管理
  • 限流事件日志 (ThrottlerGuard 自动拦截)
  • 异常流量自动检测 不做
--- ## 架构实施计划 ### 限流层次 ### 技术选型 | 组件 | 选型 | 原因 | |------|------|------| | 限流引擎 | @nestjs/throttler | NestJS 原生集成,Guard/Decorator 模式 | | 存储后端 | Redis | 高性能计数,支持分布式 | | 超时控制 | RxJS timeout + Interceptor | 全局 30s,可覆盖 | ### 文件结构 - src/common/throttle/throttle.module.ts — 全局限流模块 - src/common/throttle/redis-throttler.storage.ts — Redis 存储适配器 - src/common/interceptors/timeout.interceptor.ts — 30s 超时 - src/modules/admin-throttle/ — Admin 限流状态 AAPI ### 使用方式 ### Admin AAPI | 端点 | 说明 | |------|------| | GET /admin-api/throttle/status | 当前限流规则和状态 | --- ## 交付检查 - [x] 全局限流 — ThrottlerModule + AppThrottleModule - [x] Redis 存储 — RedisThrottlerStorage - [x] 超时控制 — TimeoutInterceptor 30s - [x] Admin AAPI — GET /admin-api/throttle/status - [x] 登录限流 — @AdminLoginRateLimit() 已有 - [x] Admin 限流配置视图 ✅ 系统运维→限流管理 ⏳ - [x] 限流事件日志 ✅ (ThrottlerGuard 自动拦截) ⏳ - [x] 异常流量自动检测 ❌ 不做
wangdl added this to the M0:后端基础能力与架构规范闭环(P0) milestone 2026-05-22 21:00:15 +08:00
wangdl self-assigned this 2026-05-22 21:00:15 +08:00
Author
Owner

E2E 测试通过

M0 E2E 测试已全部通过 — 28/28 tests passed,耗时 ~1.4s。

本 Issue 测试内容

POST /admin-api/auth/login rate-limited / validation works

运行方式

npm run test:e2e

测试架构

  • Mock 层: @prisma/client / ioredis / jose / @nestjs/bullmq
  • 无需本地 MySQL/Redis,纯 mock 轻量集成测试
  • 测试文件: test/m0.e2e-spec.ts
## ✅ E2E 测试通过 M0 E2E 测试已全部通过 — **28/28 tests passed**,耗时 ~1.4s。 ### 本 Issue 测试内容 POST /admin-api/auth/login rate-limited / validation works ### 运行方式 ```bash npm run test:e2e ``` ### 测试架构 - Mock 层: `@prisma/client` / `ioredis` / `jose` / `@nestjs/bullmq` - 无需本地 MySQL/Redis,纯 mock 轻量集成测试 - 测试文件: `test/m0.e2e-spec.ts`
Author
Owner

关闭

架构设计阶段已完成。具体实现已通过后续 M1-M7 milestone 的 issue 交付。本 issue 作为设计文档保留。

## 关闭 架构设计阶段已完成。具体实现已通过后续 M1-M7 milestone 的 issue 交付。本 issue 作为设计文档保留。
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/api-server#5
No description provided.