Files
ai-ops/EXECUTION_BOARD.md

201 lines
9.5 KiB
Markdown
Raw Permalink Normal View History

2026-05-12 17:47:32 +08:00
# AI-Ops Execution Board
> 版本v1.6 | 日期2026-05-12 | 状态:单机稳定版闭环已补齐,一键启动、备份、恢复、回滚演练通过
---
## 当前 Gate 状态
| Gate | 状态 | 说明 |
|------|------|------|
| GATE-0 编译 | ✅ **SOLID** | `go build -buildvcs=false ./...` 通过 |
| GATE-1 单测 | ✅ **SOLID** | `go test -buildvcs=false ./...` 通过 |
| GATE-2 运行 | ✅ **PODMAN_SOLID** | 已用本机 Podman Compose 跑通 PostgreSQL + Redis + App 全链路完成健康检查、ready、登录、dashboard、alerts/rules/channels/openapi 烟测Docker 权限环境仍待单独验证 |
| GATE-3 E2E | ⚠ **PARTIAL** | Podman Compose 全链路通过;完整 Docker Compose / 浏览器交互 / 聚合真实压测仍待有权限环境验证 |
---
## 进度概览
| 阶段 | 内容 | 工期 | 状态 | 完成度 |
|------|------|------|------|--------|
| **Phase 1** | 监控看板 + 日志查询 | 8人天 | ✅ 可运行 | ~95% |
| **Phase 2** | 告警规则引擎 + 通知渠道 | 12人天 | ✅ 核心闭环完成 | ~92% |
| **Phase 3** | 自愈引擎 + 审计回滚 | 14人天 | ✅ 安全最小闭环完成 | ~82% |
| **全局 G1** | 认证与权限 | - | ✅ 完成 | ~90% |
| **全局 G2** | 健康检查 | - | ✅ 完成 | ~95% |
| **全局 G3** | OpenAPI 文档 | - | ✅ 完成 | ~80% |
| **CI** | GitHub Actions | - | ✅ 已补 | ~80% |
**Go 文件数63 | Go 代码行数5890 | 编译:通过 | Race 测试:通过 | 单机一键启动:通过 | 备份:通过 | 恢复/回滚:通过 | 总覆盖率83.3%**
---
## 本轮收口内容
### 1. 告警集群聚合
| 项 | 状态 | 说明 |
|----|------|------|
| 同资源 1 分钟窗口聚合 | ✅ | `CreateEventWithAggregation(ctx,event,1m,20)`;同一 `resource_type/resource_id` 1 分钟内超过 20 条生成聚合告警 |
| 子告警关联 | ✅ | 子事件写入 `parent_alert_id`,聚合事件 `is_aggregated=true``aggregated_count=count` |
| 通知对象 | ✅ | 若触发聚合,通知发送聚合事件而不是最后一条子事件 |
| UUID 修复 | ✅ | 告警事件 ID 从 `evt_<nanos>` 改为 UUID匹配 PostgreSQL UUID 主键 |
| 测试 | ✅ | `TestAlertEngineAggregatesWhenSameResourceExceedsTwentyEventsWithinWindow` |
### 2. 通知日志 Service 层集成
| 项 | 状态 | 说明 |
|----|------|------|
| Domain model | ✅ | `internal/domain/model/notification.go` |
| Repository interface | ✅ | `NotificationLogRepository` |
| PostgreSQL 实现 | ✅ | `pg_notification_log_repository.go` |
| Service 集成 | ✅ | 每个渠道发送前创建 pending 日志;成功标记 sent失败标记 failed并继续备用渠道 |
| 测试 | ✅ | `TestNotificationServiceWritesLogWhenWebhookSent` |
### 3. 自愈真实执行器安全最小闭环
| 动作 | 状态 | 生产约束 |
|------|------|----------|
| `switch_route` | ✅ | 调用 healing_config.endpoint默认 POST |
| `throttle` | ✅ | 调用 healing_config.endpoint默认 POST |
| `restart_instance` | ✅ | 必须显式配置 `allow_restart=true`,否则拒绝执行 |
| `invoke_script` | ✅ | 只允许 `script_id` + endpoint 方式,禁止原始脚本文本直接执行 |
| HTTP 方法白名单 | ✅ | 仅允许 POST/PUT/PATCH |
| Token 支持 | ✅ | healing_config.token 写入 Bearer Authorization |
| 测试 | ✅ | 成功调用 endpoint + restart 安全拒绝测试 |
### 4. 前端页面
| 页面/能力 | 状态 | 说明 |
|-----------|------|------|
| `/ops/dashboard` | ✅ | 单页 HTML看板 + 登录 + 刷新 |
| 指标卡片 | ✅ | QPS、平均延迟、P99、错误率 |
| 告警事件列表 | ✅ | 调用 `/api/v1/ai-ops/alerts`,显示聚合字段 |
| 规则列表 | ✅ | 调用 `/api/v1/ai-ops/rules` |
| 渠道列表 | ✅ | 调用 `/api/v1/ai-ops/channels` |
| 日志列表 | ✅ | 调用 `/api/v1/ai-ops/logs` |
| 页面认证 | ✅ | 页面本身公开API 使用登录后 localStorage JWT 调用 |
### 5. CI / GitHub Actions
| 项 | 状态 | 文件 |
|----|------|------|
| Go 1.22 CI | ✅ | `.github/workflows/ci.yml` |
| PostgreSQL/Redis service | ✅ | CI services 配置 |
| gofmt 检查 | ✅ | `test -z "$(gofmt -l .)"` |
| build/test | ✅ | `go build -buildvcs=false ./...` + `go test -buildvcs=false -race ./...` |
| migration smoke | ✅ | 应用 000001 + 000002 migration |
---
## 当前模块状态
### Phase 1监控看板 + 日志查询
| 模块 | 状态 | 说明 |
|--------|------|------|
| 首页基础布局 | ✅ | `/ops/dashboard` 已升级为可用单页看板 |
| 指标数据获取 | ✅ | `/api/v1/ai-ops/metrics/realtime` |
| 指标下钻 | ✅ | `/api/v1/ai-ops/metrics/query` |
| 日志查询 | ✅ | 页面 + API + CSV 导出 |
| 日志查询性能 | ⚠ | 超时逻辑待补Redis 缓存框架已集成 |
### Phase 2告警规则引擎 + 通知渠道
| 模块 | 状态 | 说明 |
|--------|------|------|
| 告警规则 CRUD | ✅ | `/api/v1/ai-ops/rules` |
| 规则引擎 | ✅ | 30 秒评估 + 持续时间判定 + 抑制期 |
| 告警升级 | ✅ | P2 持续 2 小时未确认 → P1 |
| 告警事件列表 | ✅ | `/api/v1/ai-ops/alerts` 连接真实 repo |
| 告警集群聚合 | ✅ | 同资源 1 分钟 >20 条生成聚合事件 |
| 通知渠道 CRUD | ✅ | `/api/v1/ai-ops/channels` |
| 通知发送后端 | ✅ | 内存队列 + 失败自动切换 |
| 通知日志 | ✅ | DB + Service 集成完成 |
### Phase 3自愈引擎 + 审计回滚
| 模块 | 状态 | 说明 |
|--------|------|------|
| 自愈规则配置 | ✅ | `healing_action` + `healing_config` + `is_sandboxed` |
| 自愈执行后端 | ✅ | HTTP endpoint 执行器restart/script 有安全约束 |
| 沙盒模式 | ✅ | dry-run 只记录不执行 |
| 级联失败处理 | ⚠ | 基础失败记录已完成;复杂级联策略未实现 |
| 审计日志查询 | ✅ | `/api/v1/ai-ops/audits` |
| 审计后端 | ✅ | append-only 触发器保障 |
| 配置回滚 | ✅ | `/api/v1/ai-ops/audits/{id}/rollback` |
---
## 已验证命令
```bash
cd /home/long/project/ai-ops
gofmt -w cmd internal test
go build -buildvcs=false ./...
go test -buildvcs=false ./...
go test -buildvcs=false -coverprofile=coverage.out ./...
go tool cover -func=coverage.out | tail -1
# total: 81.3%
# latest total: 83.4%
# single-node hardening total: 83.3%
# 单机稳定版验证
scripts/aiops-single-node.sh doctor
AI_OPS_PROJECT=aiops-verify AI_OPS_APP_PORT=18180 AI_OPS_DB_PORT=15433 AI_OPS_REDIS_PORT=16380 scripts/aiops-single-node.sh start
AI_OPS_PROJECT=aiops-verify AI_OPS_APP_PORT=18180 AI_OPS_DB_PORT=15433 AI_OPS_REDIS_PORT=16380 scripts/aiops-single-node.sh backup
AI_OPS_PROJECT=aiops-verify AI_OPS_APP_PORT=18180 AI_OPS_DB_PORT=15433 AI_OPS_REDIS_PORT=16380 scripts/aiops-single-node.sh recover
AI_OPS_PROJECT=aiops-verify AI_OPS_APP_PORT=18180 AI_OPS_DB_PORT=15433 AI_OPS_REDIS_PORT=16380 scripts/aiops-single-node.sh restore backups/ai_ops_20260512-103615.sql.gz
# Podman Compose 替代 Docker Compose 全链路验证
CGO_ENABLED=0 go build -buildvcs=false -o ai-ops-static ./cmd/ai-ops
podman-compose -f docker-compose.podman.yml up -d
curl -fsS http://localhost:18080/health
curl -fsS http://localhost:18080/actuator/health/ready
curl -fsS http://localhost:18080/ops/dashboard
curl -fsS http://localhost:18080/openapi.json
curl -fsS -X POST http://localhost:18080/api/v1/ai-ops/login \
-H 'Content-Type: application/json' \
-d '{"username":"admin","password":"admin"}'
curl -fsS http://localhost:18080/api/v1/ai-ops/alerts?page=1\&page_size=5 \
-H "Authorization: Bearer $TOKEN"
# Podman DB schema smoke
PGPASSWORD=aiops123 psql -h localhost -p 15432 -U aiops -d ai_ops \
-c "SELECT to_regclass('public.ai_ops_alerts'), to_regclass('public.ai_ops_notification_logs');"
```
---
## Podman 验证交付物
| 文件 | 用途 |
|------|------|
| `config.podman.yaml` | 容器内配置DB host=`postgres`Redis host=`redis` |
| `docker-compose.podman.yml` | Rootless Podman Compose 验证,端口映射 `15432/16379/18080`,避免宿主冲突 |
| `Dockerfile.podman-local` | 离线本地二进制镜像模板;当前 compose 使用 volume 挂载 `ai-ops-static`,避免 build/pull 阻塞 |
| `ai-ops-static` | `CGO_ENABLED=0` 静态二进制,适配 Alpine 容器运行 |
Podman 当前验证结果:
```text
ai-ops-podman-app=Up
ai-ops-podman-postgres=Up (healthy)
ai-ops-podman-redis=Up (healthy)
PODMAN_COMPOSE_FULL_STACK_OK
```
---
## 剩余风险 / P2 技术债
1. Docker 原生 Compose 仍需在有 Docker daemon 权限环境单独验证;本机已用 Podman Compose 完成替代验证。
2. fresh DB 破坏性验证因本机命令钩子阻断 `DROP DATABASE`未在本机完成Podman 新卷初始化与 CI migration smoke 已覆盖主要场景。
3. 自愈执行器目前是安全 HTTP endpoint 适配层,不直接接 Kubernetes / Gateway SDK生产接入时需补具体 adapter。
4. 前端为轻量单页运维面板,不是完整产品化 UI。
5. 覆盖率 gate 已达成并继续补强:`go test -buildvcs=false -coverprofile=coverage.out ./...` 总覆盖率 83.3%已补告警升级、Feishu/Wechat 通知占位分支、日志导出错误分支、`CreateEvent` 直接路径,并修复告警升级通知服务为空时的空指针风险。
6. 单机稳定版已补齐:`scripts/aiops-single-node.sh` 支持 `start/stop/status/logs/smoke/backup/restore/recover/doctor`隔离端口验证通过restore 演练暴露并修复了恢复到已有库时 schema 对象重复的问题。
7. production mode 配置已加硬校验JWT secret 至少 32 字符、metrics auth 至少 16 字符、DB 必填项不能为空,避免线上单机空 secret/空 metrics key 误运行。