esarabadani/automotive-ev-battery-sre-demo

GitHub: esarabadani/automotive-ev-battery-sre-demo

基于 Azure SRE Agent 的电动汽车电池工厂故障响应演示,展示从告警检测、AI 根因分析到自动修复与高管报告的完整 SRE 闭环。

Stars: 0 | Forks: 0

# 🔋 电动汽车电池工厂 — Azure SRE Agent 故障响应演示 一个 **15–20 分钟的现场演示**,展示 Azure 基础设施和 **Azure SRE Agent** 如何检测、诊断和解决电动汽车电池超级工厂的生产故障,并在警报自动解除后通过邮件自动生成并发送高管故障复盘报告。 ## 📐 架构 ``` ┌────────────────────────────┐ ┌─────────────────────────────────┐ │ MES app (Node.js, AKS) │─────▶│ Application Insights │ │ • cell pass/fail loop │ │ + Azure Monitor │ │ • per-chamber telemetry │ │ + alert-yield-drop (Sev1) │ │ • internal /profile :9090 │ └──────────────┬──────────────────┘ └────────────┬───────────────┘ │ │ ├─ poll ─▶ ⭐ Azure SRE Agent ┌────────────▼───────────────┐ │ (RCA + remediation) │ Dashboard (Node.js, AKS) │ │ │ • thin proxy + cockpit UI │ ▼ └────────────────────────────┘ ┌─────────────────────────────────┐ │ Action group webhook (Resolved)│ └──────────────┬──────────────────┘ │ ▼ ┌─────────────────────────────────┐ │ Incident-reporter Function App │ │ • Flex Consumption, Node 20 │ │ • UAMI + private VNet │ │ • Storage: PE-only, no keys │ └──────────────┬──────────────────┘ │ ▼ ┌─────────────────────────────────┐ │ Azure Communication Services │ │ • Email → executive report │ └─────────────────────────────────┘ ``` AKS 上的两个服务,一个在内存中生成所有数据的 Node 进程,外加一个**默认私有**的 serverless 报告器,它会在警报自动解除的瞬间发送高管摘要邮件。**没有 Event Hubs,没有 ADX,没有 Container Apps 环境,也没有单独的传感器模拟器。** 有关完整的拓扑结构以及为什么更简单的基础组件能胜出的原因,请参阅 [`docs/04-architecture.md`](docs/04-architecture.md)。 ## 🧰 使用的 Azure 服务 | 服务 | 用途 | |---|---| | **⭐ Azure SRE Agent** | AI 大脑 — 检测、信号关联、RCA、需审批的修复 | | **Azure Kubernetes Service (AKS)** | 托管 MES 应用 + 仪表板 | | **Azure Container Registry** | 用于 MES + 仪表板的容器镜像 | | **Application Insights / Azure Monitor** | 应用遥测、自定义 `YieldPercent` 指标、Sev1 警报规则 | | **Log Analytics** | 为 SRE Agent 提供数据的集中式日志 | | **Azure Functions (Flex Consumption)** | 故障报告器 — 在警报自动解除时渲染并发送高管邮件 | | **Azure Communication Services (Email)** | 通过 Azure 托管域名实现免 SMTP 的出站邮件 | | **VNet + Private Endpoints + Private DNS** | Function App 存储仅可通过 VNet 访问 — 无共享密钥,无公共访问 | | **Action Group** | 将来自指标警报的 `Resolved` webhook 路由到 Function App | | **Azure Key Vault** | 密钥(已预配,演示可选) | **区域:** `Sweden Central` 🇸🇪 ## 📂 仓库结构 ``` . ├── README.md ← you are here ├── docs/ │ ├── 01-prerequisites.md │ ├── 02-deployment-guide.md │ ├── 03-demo-script.md │ ├── 04-architecture.md │ └── 05-troubleshooting.md ├── infra/ │ └── terraform/ ← AKS, ACR, App Insights, KV, alert, action group, │ ACS, Function App + VNet/PE/DNS │ ├── main.tf (RG, AKS, ACR, AppI/LAW, KV, action group, metric alert) │ ├── acs.tf (Communication Services + email domain) │ ├── function.tf (Flex Consumption Function + UAMI + storage) │ ├── network.tf (VNet, delegated + PE subnets, private DNS zones) │ └── ... ├── apps/ │ ├── mes-app/ ← Node.js — generates yield + chamber telemetry in-memory; │ │ public /api/state + internal /profile /reset on :9090 │ ├── dashboard/ ← Node.js — thin proxy + polished static UI │ └── incident-reporter/ ← Azure Function (Node 20) — composes + emails the report └── scripts/ ├── build-and-push.ps1 ← builds MES + dashboard images into ACR ├── deploy-apps.ps1 ← deploys MES + dashboard to AKS ├── deploy-reporter.ps1 ← SCM zip publish for the Function App ├── trigger-incident.ps1 ← flips MES profile = degraded (kubectl exec → port 9090) ├── reset-demo.ps1 ← flips back to nominal + resets counters ├── send-report.ps1 ← manual fallback to call the Function directly └── close-alerts.ps1 ← bulk-closes any lingering alerts between iterations ``` ## 🚀 快速开始 ``` # 前置条件 — 参见 docs/01-prerequisites.md az login az account set --subscription "" # 部署基础设施(约 10 分钟 — AKS 是最耗时的部分) cd infra/terraform terraform init terraform apply -var="location=swedencentral" -var="report_recipient_email=" # 为 MES + dashboard 构建 & 推送容器镜像 cd ../../scripts ./build-and-push.ps1 # 将 MES + dashboard 部署到 AKS ./deploy-apps.ps1 # 部署 incident-reporter Function App 代码(zip 发布) ./deploy-reporter.ps1 # 更新 MES 公共 URL terraform 变量,使其指向实际的 MES LB IP, # 然后重新应用,以便 Function App 的 app-setting MES_BASE_URL 正确: kubectl -n mes get svc mes-app # copy EXTERNAL-IP cd ../infra/terraform terraform apply -var="mes_public_base_url=http://" -var="report_recipient_email=" # 将 Azure SRE Agent 加入到资源组 # Portal → Azure SRE Agent → attach 到 rg-evbat-demo- # 有关 response-plan + connector 设置,请参见 docs/02-deployment-guide.md 第 5 步 # 运行演示 — 参见 docs/03-demo-script.md ``` 完整的分步说明请见 [docs/02-deployment-guide.md](docs/02-deployment-guide.md)。 ## 🎬 演示流程(约 17 分钟) | 幕次 | 时间 | 发生内容 | |---|---|---| | 1. 设置与正常运行 | 3 分钟 | 展示架构;仪表板显示 98% 良率,profile = `nominal` | | 2. 故障发生 | 3 分钟 | 触发故障 → 良率下降,Azure Monitor Sev1 警报在 1–2 分钟内触发 | | 3. SRE Agent 诊断 ⭐ | 6 分钟 | SRE Agent 自动关联 AppI + AKS 信号,进行对话式 RCA,提出修复方案 | | 4. 批准的修复 | 3 分钟 | 一次批准 → 良率实时恢复,警报在 1–2 分钟内自动解除 | | 5. 高管报告 | 2 分钟 | 在 `Resolved` 时,action group 触发 Function;ACS 邮件在约 5 秒内送达,其中包含渲染好的故障报告(影响金额 $、各工位表格、时间线、RCA、建议操作) | 详细脚本:[docs/03-demo-script.md](docs/03-demo-script.md)。 ## 💰 预估成本 在 Sweden Central 运行此演示 **8 小时**:**约 $3–5 USD**。 | 组件 | 说明 | |---|---| | AKS (2× D2s_v5) | 8 小时约 $1.60 | | Function (Flex Consumption FC1) | 按执行付费;演示成本可忽略不计 | | Log Analytics + App Insights | 基于使用量,本次演示约 $1 | | ACR Basic, KV, 警报规则, action group | 当天约 $0.40 | | ACS email | 首次发送免费;远低于任何计费门槛 | | VNet / private endpoints (×3) | 8 小时约 $0.30 | 演示结束后请务必运行 `terraform destroy`。必须先在门户中**手动取消注册** SRE Agent。
标签:AKS, Azure, ECS, MITM代理, SRE, Terraform, 偏差过滤, 演示项目, 自动化应急响应, 自定义脚本, 运维监控