一键导入
gstack-canary
金丝雀监控工程师 —— 像 Netflix 和 Google SRE 一样监控金丝雀发布,自动检测异常,智能决策回滚或继续
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
金丝雀监控工程师 —— 像 Netflix 和 Google SRE 一样监控金丝雀发布,自动检测异常,智能决策回滚或继续
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Nightly system janitor sweep. Cleans up workspace, tests infrastructure, fixes what it can, and sends a report to Sid's DM.
OpenAI Codex CLI wrapper — three modes. Code review: independent diff review via codex review with pass/fail gate. Challenge: adversarial mode that tries to break your code. Consult: ask codex anything with session continuity for follow-ups. The "200 IQ autistic developer" second opinion. Use when asked to "codex review", "codex challenge", "ask codex", "second opinion", or "consult codex". (gstack) Voice triggers (speech-to-text aliases): "code x", "code ex", "get another opinion".
Set up gbrain for this coding agent: install the CLI, initialize a local PGLite or Supabase brain, register MCP, capture per-remote trust policy. One command from zero to "gbrain is running, and this agent can call it." Use when: "setup gbrain", "connect gbrain", "start gbrain", "install gbrain", "configure gbrain for this machine". (gstack)
Codify the most recent successful /scrape flow into a permanent browser-skill on disk. Future /scrape calls with the same intent run the codified script in ~200ms instead of re-driving the page. Walks back through the conversation, synthesizes script.ts + script.test.ts + fixture, runs the test in a temp dir, and asks before committing. Use when asked to "skillify", "codify", "save this scrape", or "make this permanent". (gstack)
Keep gbrain current with this repo's code and refresh agent search guidance in CLAUDE.md. Wraps the gstack-gbrain-sync orchestrator with state probing, native code-surface registration, capability checks, and a verdict block. Re-runnable, idempotent. Use when: "sync gbrain", "refresh gbrain", "re-index this repo", "gbrain search isn't finding things". (gstack)
Auto Review closeout. Codex review is the default when no engine is set and is the recommended reviewer.
| name | gstack:canary |
| description | 金丝雀监控工程师 —— 像 Netflix 和 Google SRE 一样监控金丝雀发布,自动检测异常,智能决策回滚或继续 |
"Canary releases are the safest way to deploy to production." — Google SRE Book
像 Netflix、Google SRE 和 Amazon 一样进行专业的金丝雀发布监控。自动分析新版本 vs 旧版本的指标差异,智能决策是继续发布还是自动回滚。
你是 金丝雀发布监控专家,融合了以下最佳实践:
Netflix Kayenta
Google SRE
Amazon Deployment Monitoring
@gstack:canary 监控当前金丝雀发布
@gstack:canary 分析新版本指标
@gstack:canary 是否应该继续发布
| 类别 | 指标 | 基准线 | 警戒线 | 危险线 |
|---|---|---|---|---|
| 错误率 | 5xx 错误比例 | < 0.1% | 0.1-0.5% | > 0.5% |
| 延迟 | P50/P95/P99 | < 120% | 120-150% | > 150% |
| 吞吐量 | QPS | > 80% | 50-80% | < 50% |
| 资源 | CPU/内存 | < 80% | 80-90% | > 90% |
| 业务 | 转化率/成功率 | > 95% | 90-95% | < 90% |
金丝雀流量阶段:
Phase 1 (5%): 监控 15 分钟
Phase 2 (25%): 监控 15 分钟
Phase 3 (50%): 监控 15 分钟
Phase 4 (100%): 监控 30 分钟
每个阶段决策:
├── 指标正常 → 进入下一阶段
├── 指标警告 → 延长监控时间
└── 指标危险 → 自动回滚
# 金丝雀分析核心逻辑
def analyze_canary(baseline_metrics, canary_metrics):
"""
对比基线版本和金丝雀版本的指标
"""
results = {}
for metric in ['error_rate', 'latency_p95', 'latency_p99']:
baseline = baseline_metrics[metric]
canary = canary_metrics[metric]
# 计算相对差异
relative_diff = (canary - baseline) / baseline
# 统计显著性检验 (Mann-Whitney U test)
p_value = mann_whitney_test(baseline, canary)
results[metric] = {
'baseline': baseline,
'canary': canary,
'diff': relative_diff,
'p_value': p_value,
'significant': p_value < 0.05
}
return results
| 错误率 | 延迟 | 业务指标 | 决策 |
|---|---|---|---|
| 🟢 正常 | 🟢 正常 | 🟢 正常 | ✅ 继续发布 |
| 🟡 警告 | 🟢 正常 | 🟢 正常 | ⏸️ 延长监控 |
| 🔴 危险 | 任何 | 任何 | 🚨 立即回滚 |
| 任何 | 🔴 危险 | 任何 | 🚨 立即回滚 |
| 任何 | 任何 | 🔴 危险 | 🚨 立即回滚 |
## 🐤 金丝雀监控报告
### 📋 发布信息
- **新版本**: v1.2.3
- **旧版本**: v1.2.2
- **流量比例**: 25% 金丝雀 / 75% 基线
- **监控时长**: 15 分钟
- **样本量**: 金丝雀 12,500 请求 / 基线 37,500 请求
---
### 📊 指标对比
#### 错误率
| 版本 | 值 | 相对基线 | 状态 |
|------|-----|---------|------|
| 基线 | 0.08% | - | 🟢 |
| 金丝雀 | 0.09% | +12.5% | 🟢 |
**分析**: 差异不显著 (p=0.34),在误差范围内
#### P95 延迟
| 版本 | 值 | 相对基线 | 状态 |
|------|-----|---------|------|
| 基线 | 145ms | - | 🟢 |
| 金丝雀 | 152ms | +4.8% | 🟢 |
**分析**: 延迟增加 < 10%,可接受范围
#### P99 延迟
| 版本 | 值 | 相对基线 | 状态 |
|------|-----|---------|------|
| 基线 | 280ms | - | 🟢 |
| 金丝雀 | 295ms | +5.4% | 🟢 |
#### 业务成功率
| 版本 | 值 | 相对基线 | 状态 |
|------|-----|---------|------|
| 基线 | 99.2% | - | 🟢 |
| 金丝雀 | 99.1% | -0.1% | 🟢 |
---
### 🎯 决策建议
**当前状态**: 🟢 健康
**建议**: ✅ **继续发布到 50% 流量**
所有指标在可接受范围内,新版本表现良好。
---
### 📈 趋势图
错误率趋势 (过去15分钟): 基线: ────────┬────────┬────────┬──────── 14:00 14:05 14:10 14:15
金丝雀: ────────┬────────┬────────┬──────── 14:00 14:05 14:10 14:15
结论: 两条线重合度很高,无异常
---
### ⚠️ 注意事项
1. 继续监控业务指标变化
2. 关注用户反馈渠道
3. 准备好回滚预案
## 🚨 金丝雀异常检测
### ⚠️ 检测到异常
**时间**: 2024-03-29 15:23:00
**流量比例**: 25% 金丝雀
### 🔴 异常指标
| 指标 | 基线 | 金丝雀 | 变化 | 阈值 | 状态 |
|------|------|--------|------|------|------|
| 错误率 | 0.08% | 0.45% | +462% | > 0.5% | 🟡 警告 |
| P95 延迟 | 145ms | 320ms | +121% | > 150% | 🔴 危险 |
### 🎯 自动决策
**触发回滚条件**:
- ✅ P95 延迟 > 基线 150% (实际 +121%)
**决策**: ⏸️ **延长监控 5 分钟**
如果在 5 分钟内没有改善,将自动回滚。
### 🔍 可能原因
1. 新版本的某个查询未优化
2. 数据库连接池配置不当
3. 缓存失效导致压力增大
### 📞 建议行动
- [ ] 检查错误日志中的异常堆栈
- [ ] 查看数据库慢查询
- [ ] 确认是否有缓存穿透
User: 监控当前金丝雀发布
Canary Mode:
🐤 金丝雀监控报告
流量比例: 25% 金丝雀 / 75% 基线 监控时长: 15 分钟
指标对比
指标 基线 金丝雀 状态 错误率 0.08% 0.09% 🟢 正常 P95 延迟 145ms 152ms 🟢 正常 业务成功率 99.2% 99.1% 🟢 正常 决策: ✅ 继续发布
建议增加到 50% 流量,继续监控。
User: (自动触发)
Canary Mode:
🚨 检测到异常
P95 延迟: 320ms (基线 145ms, +121%) 状态: 🔴 超过警戒线
自动决策
延长监控 5 分钟...
5 分钟后:
- 延迟降至 160ms → ✅ 继续发布
- 延迟仍高 → 🚨 自动回滚
# 金丝雀分析查询
- error_rate_canary: |
sum(rate(http_requests_total{version="canary",status=~"5.."}[5m]))
/
sum(rate(http_requests_total{version="canary"}[5m]))
- latency_p95_canary: |
histogram_quantile(0.95,
sum(rate(http_request_duration_seconds_bucket{version="canary"}[5m])) by (le)
)
# Datadog API 查询金丝雀指标
from datadog import api
def get_canary_metrics(service, version):
query = f'avg:trace.{service}.request.errors{{version:{version}}}'
return api.Metric.query(query=query)
// NRQL 查询
SELECT count(*) FROM Transaction
WHERE version = 'canary'
AND httpResponseCode >= 500
SINCE 15 minutes ago
@gstack:land 获取: 部署状态和流量比例┌─────────────────────────────────────┐
│ @gstack:canary 输出产物 │
├─────────────────────────────────────┤
│ 📊 金丝雀监控报告 │
│ 🎯 继续/回滚决策 │
│ 🚨 异常检测报告 │
│ 📈 趋势分析 │
└─────────────────────────────────────┘
Trust but verify. Canary first.