技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
define-slo-sli-sla【数据与研究】Establish Service Level Objectives (SLO), Service Level Indicators (SLI), and Service Level Agreements (SLA) with error budget tracking, burn rate alerts, and automated reporting using Prometheus and tools like Sloth or Pyrra. Use when defining reliability targets for customer-facing services, balancing feature velocity against system reliability thr…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
以服務等級目標立可量之信度標的,以指標測之,以錯誤預算管之。
完整配置文件與模板,見 Extended Examples。
學此三概念之關係與別。
定義:
SLI (Service Level Indicator)
- **What**: A quantitative measure of service behavior
- **Example**: Request success rate, request latency, system throughput
- **Measurement**: `successful_requests / total_requests * 100`
SLO (Service Level Objective)
- **What**: Target value or range for an SLI over a time window
- **Example**: 99.9% of requests succeed in 30-day window
- **Purpose**: Internal reliability target to guide operations
SLA (Service Level Agreement)
- **What**: Contractual commitment with consequences for missing SLO
- **Example**: 99.9% uptime SLA with refunds if breached
- **Purpose**: External promise to customers with penalties
層次:
SLA (99.9% uptime, customer refunds)
├─ SLO (99.95% success rate, internal target)
│ └─ SLI (actual measured: 99.97% success rate)
└─ Error Budget (0.05% failures allowed per month)
要旨:SLO 宜嚴於 SLA,留餘地以避客戶受損。
例:
預期: 團隊明其別,同意何指標為 SLI,同意 SLO 標的。
失敗時:
擇反映用戶體驗與業務影響之 SLI。
四黃金信號(Google SRE):
延遲:應請求之時
# P95 latency
histogram_quantile(0.95,
sum(rate(http_request_duration_seconds_bucket[5m])) by (le)
)
流量:系統之需求
# Requests per second
sum(rate(http_requests_total[5m]))
錯誤:失敗請求之率
# Error rate percentage
sum(rate(http_requests_total{status=~"5.."}[5m]))
/ sum(rate(http_requests_total[5m])) * 100
飽和度:系統「滿」之程度
# CPU saturation
avg(rate(node_cpu_seconds_total{mode!="idle"}[5m]))
常見 SLI 模式:
# Availability SLI
availability:
description: "Percentage of successful requests"
query: |
sum(rate(http_requests_total{status!~"5.."}[5m]))
/ sum(rate(http_requests_total[5m]))
good_threshold: 0.999 # 99.9%
# Latency SLI
latency:
description: "P99 request latency under 500ms"
query: |
histogram_quantile(0.99,
sum(rate(http_request_duration_seconds_bucket[5m])) by (le)
) < 0.5
good_threshold: 0.95 # 95% of windows meet target
# Throughput SLI
throughput:
description: "Requests processed per second"
query: |
sum(rate(http_requests_total[5m]))
good_threshold: 1000 # Minimum 1000 req/s
# Data freshness SLI (for batch jobs)
freshness:
description: "Data updated within last hour"
query: |
(time() - max(data_last_updated_timestamp)) < 3600
good_threshold: 1 # Always fresh
SLI 擇選之準:
避之者:
預期: 每服務擇 2-4 SLI,至少涵蓋可用性與延遲,團隊同意測量查詢。
失敗時:
立實可達之信度標的。
SLO 規格格式:
service: user-api
slos:
- name: availability
objective: 99.9
description: |
99.9% of requests return non-5xx status codes
# ... (see EXAMPLES.md for complete configuration)
時窗之擇:
常見之窗:
例 30 日窗之錯誤預算:
SLO: 99.9% availability over 30 days
Allowed failures: 0.1%
Total requests per month: 100M
Error budget: 100,000 failed requests
Daily budget: ~3,333 failed requests
立實之標的:
當前性能之基線:
# Check actual availability over past 90 days
avg_over_time(
(sum(rate(http_requests_total{status!~"5.."}[5m]))
/ sum(rate(http_requests_total[5m])))[90d:5m]
)
# Result: 99.95% → Set SLO at 99.9% (safer than current)
計九之代價:
99% → 7.2 hours downtime/month (low reliability)
99.9% → 43 minutes downtime/month (good)
99.95% → 22 minutes downtime/month (very good)
99.99% → 4.3 minutes downtime/month (expensive)
99.999% → 26 seconds downtime/month (very expensive)
權衡用戶滿意與工程代價:
預期: SLO 標的得業務相關人支持,載明理由,算出錯誤預算。
失敗時:
用 Sloth 從 SLO 規格生 Prometheus 錄制規則與告警。
裝 Sloth:
# Binary installation
wget https://github.com/slok/sloth/releases/download/v0.11.0/sloth-linux-amd64
chmod +x sloth-linux-amd64
sudo mv sloth-linux-amd64 /usr/local/bin/sloth
# Or Docker
docker pull ghcr.io/slok/sloth:latest
建 Sloth SLO 規格(slos/user-api.yml):
version: "prometheus/v1"
service: "user-api"
labels:
team: "platform"
tier: "1"
slos:
# ... (see EXAMPLES.md for complete configuration)
生 Prometheus 規則:
# Generate recording and alerting rules
sloth generate -i slos/user-api.yml -o prometheus/rules/user-api-slo.yml
# Validate generated rules
promtool check rules prometheus/rules/user-api-slo.yml
所生之錄制規則(節選):
groups:
- name: sloth-slo-sli-recordings-user-api-requests-availability
interval: 30s
rules:
# SLI: Ratio of good events
- record: slo:sli_error:ratio_rate5m
# ... (see EXAMPLES.md for complete configuration)
所生之告警:
groups:
- name: sloth-slo-alerts-user-api-requests-availability
rules:
# Fast burn: 2% budget consumed in 1 hour
- alert: UserAPIHighErrorRate
expr: |
# ... (see EXAMPLES.md for complete configuration)
載規則入 Prometheus:
# prometheus.yml
rule_files:
- "rules/user-api-slo.yml"
重載 Prometheus:
curl -X POST http://localhost:9090/-/reload
預期: Sloth 生多窗多燃率告警,錄制規則評估成功,告警於事故時適時觸發。
失敗時:
yamllint slos/user-api.yml 驗 YAML 語法curl http://localhost:9090/api/v1/rules於 Grafana 視覺化 SLO 合規與錯誤預算消耗。
Grafana 儀表板 JSON(節選):
{
"dashboard": {
"title": "SLO Dashboard - User API",
"panels": [
{
"type": "stat",
# ... (see EXAMPLES.md for complete configuration)
宜視覺化之關鍵指標:
錯誤預算政策儀表板(markdown 面板):
## Error Budget Policy
**Current Status**: 78% budget remaining
### If Error Budget > 50%
- ✅ Full speed ahead on new features
# ... (see EXAMPLES.md for complete configuration)
預期: 儀表板示實時 SLO 合規,錯誤預算消耗可見,團隊可為特性速度作明智之決。
失敗時:
curl http://localhost:9090/api/v1/rules | jq '.data.groups[].rules[] | select(.name | contains("slo:"))'為管理錯誤預算立組織流程。
錯誤預算政策模板:
service: user-api
slo:
availability: 99.9%
latency_p99: 200ms
window: 30 days
# ... (see EXAMPLES.md for complete configuration)
政策自動執行:
# Example: Deployment gate script
import requests
import sys
def check_error_budget(service):
# Query Prometheus for error budget
# ... (see EXAMPLES.md for complete configuration)
整合入 CI/CD 管線:
# .github/workflows/deploy.yml
jobs:
check-error-budget:
runs-on: ubuntu-latest
steps:
- name: Check SLO Error Budget
run: |
python scripts/check_error_budget.py user-api
- name: Deploy
if: success()
run: |
kubectl apply -f deploy/
預期: 政策明載,自動閘阻止預算枯竭時之險部署,團隊於信度優先級對齊。
失敗時:
setup-prometheus-monitoring - 配 Prometheus 收指標以算 SLIconfigure-alerting-rules - 整合 SLO 燃率告警入 Alertmanager 以通知值班build-grafana-dashboards - 視覺化 SLO 合規與錯誤預算消耗write-incident-runbook - 於運行手冊中含 SLO 影響以優先處理事故