RizwanSid7/azure-sre-agent-app-incident-response-lab

GitHub: RizwanSid7/azure-sre-agent-app-incident-response-lab

该项目是一个 Azure SRE 实践实验室,通过模拟应用程序故障场景演示如何结合 Grafana、Application Insights 和 Azure SRE Agent 进行事件调查与根因分析。

Stars: 0 | Forks: 0

\# Azure SRE Agent 应用程序事件响应实验室 本项目将之前的 Azure SRE Agent 虚拟机事件实验室扩展到了应用程序级别的事件响应场景。 本实验室的目标是了解 Azure SRE Agent、Azure Managed Grafana、Azure Monitor、Application Insights 和 Azure Functions 如何在应用程序故障排除和根因分析过程中协同工作。 \--- \## 项目摘要 在本项目中,我部署了一个包含 Azure Managed Grafana 的 Azure SRE Agent 沙盒环境,并创建了一个基于 Python 且具有多个测试 endpoint 的 Azure Function App。 该 Function App 用于模拟: \- 正常的应用程序流量 \- HTTP 错误响应 \- 响应缓慢行为 \- 临时 CPU 负载 生成的遥测数据通过 Grafana 和 Azure Monitor 进行了验证。随后,利用 Azure SRE Agent 对该 Function App 进行了调查,并总结了可能的根因、影响、修复措施及预防措施。 \--- \## 简单说明 在真实的生产环境中,应用程序可能会变慢、返回错误或出现意外行为。 通常,工程师需要手动检查多个位置: \- Azure Portal \- 应用程序指标 \- 日志 \- Grafana dashboard \- 活动日志 \- 近期变更 本项目展示了 Azure SRE Agent 如何帮助整合这些上下文信息,并协助加快事件调查速度。 \--- \## 技术架构 ``` User / Traffic Generator | v Azure Function App /health -> normal request /slow -> slow response simulation /error -> HTTP error simulation /cpu -> CPU load simulation | v Application Insights + Azure Monitor | v Azure Managed Grafana | v Azure SRE Agent | v Incident investigation + probable RCA + remediation summary ``` \--- \## 使用的 Azure 资源 | 资源 | 用途 | |---|---| | Azure SRE Agent | AI 辅助的事件调查与根因分析 (RCA) | | Azure Managed Grafana | 应用程序指标可视化 | | Azure Function App | 演示应用程序工作负载 | | Application Insights | 应用程序性能与错误遥测 | | Log Analytics Workspace | 存储监控与日志数据 | | Storage Account | Azure Functions 必需 | | Managed Identity | Azure 资源的安全身份 | | Azure RBAC | Grafana 和 SRE Agent 的访问控制 | | Azure Monitor | 指标与可观测性平台 | \--- \## 演示应用程序 Endpoint | Endpoint | 用途 | |---|---| | `/` | 主页 | | `/health` | 正常响应 | | `/slow` | 模拟响应缓慢 | | `/error` | 模拟 HTTP 错误 | | `/cpu` | 模拟临时 CPU 负载 | \--- \## 模拟的事件场景 \### 1. HTTP 错误场景 多次调用 `/error` endpoint 以生成失败的请求。 \### 2. 响应缓慢场景 使用 `/slow` endpoint 通过延迟响应来模拟延迟。 \### 3. CPU 负载场景 `/cpu` endpoint 为应用程序性能测试生成了临时 CPU 负载。 \--- \## Grafana 捕获的指标 Grafana 用于通过 Azure Monitor 和 Application Insights 指标验证应用程序行为。 捕获的指标: \- Function 请求 \- HTTP 错误行为 \- Function 执行计数 \- 应用程序随时间的活动情况 \--- \## 使用的 SRE Agent 调查 Prompt \### Function App 发现 ``` Can you identify the Function App deployed in rg-appinc-sbx-sre and summarize its current status? ``` \### 错误调查 ``` Investigate the Function App in rg-appinc-sbx-sre. Check whether there are recent HTTP 5xx errors, slow responses, or performance anomalies. ``` \### 根因总结 ``` Check recent Azure Monitor metrics and activity logs for this Function App. Correlate request count, HTTP 5xx errors, response behavior, and recent operational activity. Summarize the probable root cause. ``` \### 修复总结 ``` The test traffic generation has been stopped. Can you summarize the incident, impact, probable root cause, remediation, and preventive actions? ``` \--- \## 截图 | 步骤 | 截图 | |---|---| | AZD 部署成功 | !\[AZD 部署成功](screenshots-public/00-powershell-azd-up-success.png) | | Function App 概览 | !\[Function App 概览](screenshots-public/01-function-app-overview.png) | | Application Insights 概览 | !\[Application Insights 概览](screenshots-public/02-application-insights-overview.png) | | 演示 Function 主页 | !\[演示 Function 主页](screenshots-public/03-demo-app-homepage.png) | | Grafana Function 请求 | !\[Grafana Function 请求](screenshots-public/04-grafana-function-requests.png) | | Grafana HTTP 错误 | !\[Grafana HTTP 错误](screenshots-public/05-grafana-http-errors.png) | | Grafana Function 执行计数 | !\[Grafana Function 执行计数](screenshots-public/06-grafana-function-execution-count.png) | | SRE Agent Function 发现 | !\[SRE Agent Function 发现](screenshots-public/07-sre-agent-function-app-discovery.png) | | SRE Agent 错误调查 | !\[SRE Agent 错误调查](screenshots-public/08-sre-agent-error-investigation.png) | | SRE Agent 根因总结 | !\[SRE Agent 根因总结](screenshots-public/09-sre-agent-root-cause-summary.png) | | SRE Agent 修复总结 | !\[SRE Agent 修复总结](screenshots-public/10-sre-agent-remediation-summary.png) | | PowerShell 流量生成 | !\[PowerShell 流量生成](screenshots-public/11-powershell-traffic-generation.png) | | 来自 CLI 的 Function 指标 | !\[来自 CLI 的 Function 指标](screenshots-public/12-powershell-function-metrics.png) | \--- \## 本项目展示的内容 \- 应用程序级别的事件模拟 \- Azure Function App 监控 \- Application Insights 遥测 \- Azure Monitor 指标 \- Grafana 可视化 \- Azure SRE Agent 调查 \- RBAC 和 Managed Identity 配置 \- 根因分析工作流 \- 事件修复文档记录 \--- \## 此设置的适用场景 此设置适用于以下情况: \- 应用程序返回错误 \- 响应时间突然增加 \- 工程师需要关联指标与近期活动 \- 使用 Grafana 进行可视化验证 \- 使用 SRE Agent 提供调查上下文 \- 事件总结需要包含 RCA、影响、修复措施和预防措施 \--- \## 主要学习成果 \- 应用程序事件需要不同于仅针对虚拟机事件的监控信号。 \- Application Insights 对于请求和失败遥测至关重要。 \- Grafana 有助于可视化发生的情况。 \- SRE Agent 有助于总结调查上下文。 \- 必须正确配置 RBAC 和 Managed Identity。 \- 测试后的成本清理非常重要。 \--- \## 局限性 \- 这是一个实验室环境,而非生产环境。 \- 应用程序错误是故意生成的。 \- 指标可能需要几分钟才能显示。 \- SRE Agent 的调查质量取决于可用的遥测数据和权限。 \- 截图在发布前已作脱敏处理。 \- 该实验室在创建 App Service Plan 达到配额限制后,使用了 Azure Functions Consumption。 \--- \## 成本意识 本实验室使用以下可计费的 Azure 资源: \- Azure SRE Agent \- Azure Managed Grafana \- Azure Function App \- Application Insights \- Log Analytics Workspace \- Storage Account 测试后应删除资源,以避免产生不必要的成本。 \--- \## 清理 ``` azd down --purge --force ``` 验证删除: ``` az group exists --name rg-appinc-sbx-sre ``` 预期输出: ``` false ``` \--- \## 最终成果 本项目展示了如何超越基础设施级别的事件,将 Azure SRE Agent 的使用扩展到结合 Azure Functions、Application Insights、Azure Monitor 和 Managed Grafana 进行应用程序级别的事件调查。
标签:Azure, Grafana, Serverless, SRE, 偏差过滤, 故障排查, 自动化根因分析, 运维监控, 逆向工具