froggychips/sre-ai-copilot

GitHub: froggychips/sre-ai-copilot

基于 LLM 多阶段 agent 流水线的 Kubernetes 事件智能响应后端服务,自动接收告警、分析根因并生成修复建议。

Stars: 0 | Forks: 0

# SRE AI Copilot [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![Python](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/) [![FastAPI](https://img.shields.io/badge/FastAPI-0.104-009688)](https://fastapi.tiangolo.com/) [![Celery](https://img.shields.io/badge/Celery-5.3-37814A)](https://docs.celeryq.dev/) **SRE AI Copilot** — 用于自动化 Kubernetes 中 incident response 的后端服务:接收 Prometheus AlertManager webhook,通过基于 agent 的 LLM pipeline(analyzer → hypothesis → critic → fix → risk)进行异步事件分析,基于 k8s namespace 的 guardrails 以及在任何 write 操作前执行 human-approval flow。 ## 服务功能 - 通过 Prometheus AlertManager webhook (`/webhooks/alertmanager`) 接收事件告警,并使用 Celery 进行异步处理。 - 执行 agent pipeline(analyzer → hypothesis → critic → fix → risk → synthesis)。 - 将事件记录和分析结果存储在 PostgreSQL 中。 - 支持历史事件的 replay 模式(`/replay/{incident_id}`)。 - 导出 health/readiness 探针、Prometheus 指标和 OpenTelemetry 链路追踪。 ## 技术栈 - **API**: FastAPI - **队列**: Celery + Redis - **数据库**: PostgreSQL + SQLAlchemy - **可观测性**: Prometheus, OpenTelemetry, structlog - **集成**: Discord webhook, Kubernetes guardrails, Anthropic Claude API ## 快速入门 ### 1) 环境要求 - Docker + Docker Compose - Python 3.11+ ### 2) 配置环境 创建 `.env` 文件并至少设置以下内容: - `ANTHROPIC_API_KEY` - `DATABASE_URL` - `REDIS_URL` - `DISCORD_WEBHOOK_URL` - `JWT_PUBLIC_KEY`(如果启用了 JWT 认证) ### 3) 启动 ``` docker-compose up -d ``` 启动本地 API(不使用容器): ``` uvicorn app.main:app --reload --port 8000 ``` ## 主要 API 端点 - `POST /webhooks/alertmanager` — 接收 AlertManager 批量数据,为每个 alert 创建异步任务。 - `GET /webhooks/status/{task_id}` — 获取 webhook Celery 任务的状态。 - `POST /copilot` — 在后台启动响应/分析生成。 - `GET /jobs/{task_id}` — 获取 `generate_reply` 任务的状态。 - `POST /approvals/{approval_id}/approve|reject` — 批准/拒绝操作。 - `POST /replay/{incident_id}` — 重放历史事件分析。 - `POST /evaluation/{incident_id}/submit` 和 `GET /evaluation/stats` — 反馈闭环。 - `GET /healthz`,`GET /readyz` — 存活/就绪探针。 ## 安全与 guardrails - AI 不直接执行 kubectl:使用 `ExecutionIntent` DSL 和确定性转换器。 - `app/services/k8s_guard.py` 中的分层 namespace 策略:production(`prod`/`preprod`/`preupdate`)— 只读,dev(`squad-*`)— 通过 approval 可写,system/auth(`kube-*`,`mcp`)— 禁止访问。 - verb/resource 白名单;对 body 进行 deep-inspection,以检测 `privileged`/`hostNetwork`。 - 潜在的危险操作需经过 approval flow。 ## sre-ai-copilot vs froggy-sre froggy-sre 运行 5 阶段 pipeline。sre-ai-copilot 增加了第六个阶段:Synthesis agent 同时查看所有 5 个输出并生成最终报告(双层 reasoning)。根据上下文进行选择: | | sre-ai-copilot | [froggy-sre](https://github.com/froggychips/froggy-sre) | |---|---|---| | **触发器** | AlertManager webhook (headless) | 来自 Claude Code 的 MCP tool call | | **Runtime** | 任意服务器 / k8s pod | macOS 开发机 | | **LLM** | Anthropic API | Froggy local → Anthropic fallback | | **k8s 上下文** | In-cluster kubernetes SDK | 通过 kubeconfig 的 `kubectl` | | **存储** | SQLite + Celery queue | `~/.froggy-sre/incidents/` (local JSON) | | **通知** | Discord webhook | 在 Claude Code 中回复 | | **适用场景** | 生产环境需要持续的无头告警监控 | 通过 Claude Code 交互式地分析事件 | ## 文档 - [架构](docs/ARCHITECTURE.md) - [模块文档](docs/MODULE_DOCS.md) - [语义契约](docs/SEMANTIC_CONTRACT.md) - [灾备计划](docs/DR.md)
标签:AIOps, AI助手, AlertManager, Anthropic Claude, API集成, AV绕过, Celery, CISA项目, DevSecOps, DLL 劫持, FastAPI, GET参数, Human Approval, Incident Response, LLM, OpenTelemetry, PostgreSQL, Python, Redis, SQLAlchemy, SRE, Unmanaged PE, Webhook, 上游代理, 人工智能, 人机协同, 偏差过滤, 力导向图, 可观测性, 告警管理, 大语言模型, 子域名突变, 安全防护, 异步任务, 搜索引擎查询, 无后门, 测试用例, 用户代理, 用户模式Hook绕过, 站点可靠性工程, 自动化运维, 自定义请求头, 请求拦截, 逆向工具