executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
define-slo-sli-slaエラーバジェット追跡、バーンレートアラート、PrometheusおよびSlothやPyrraなどのツールを使用した 自動レポートを含む、サービスレベル目標(SLO)、サービスレベル指標(SLI)、 サービスレベルアグリーメント(SLA)を確立する。カスタマー向けサービスの信頼性目標を 定義する場合、エラーバジェットを通じた機能開発速度とシステム信頼性のバランスを取る場合、 任意のアップタイム目標からデータ駆動型のメトリクスへ移行する場合、またはSRE実践を 実装する場合に使用する。
Independent GitHub snapshot · Automated classification · Original documentation governs
サービスレベル目標で測定可能な信頼性ターゲットを確立し、指標で追跡し、エラーバジェットを管理する。
完全な設定ファイルとテンプレートは拡張例を参照。
これら3つの概念の関係と違いを習得する。
定義:
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を選ぶ。
Four Golden Signals(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)
「9」のコストを計算:
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/rulesGrafanaでSLOコンプライアンスとエラーバジェット消費を可視化する。
GrafanaダッシュボードのJSON(抜粋):
{
"dashboard": {
"title": "SLO Dashboard - User API",
"panels": [
{
"type": "stat",
# ... (see EXAMPLES.md for complete configuration)
可視化すべき主要メトリクス:
エラーバジェットポリシーダッシュボード(マークダウンパネル):
## Error Budget Policy
**Current Status**: 78% budget remaining
### If Error Budget > 50%
- ✅ Full speed ahead on new features
# ... (完全な設定はEXAMPLES.mdを参照)
期待結果: ダッシュボードがリアルタイムの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 - SLI計算のためにメトリクスを収集するPrometheusを設定するconfigure-alerting-rules - オンコール通知のためにAlertmanagerとSLOバーンレートアラートを統合するbuild-grafana-dashboards - SLOコンプライアンスとエラーバジェット消費を可視化するwrite-incident-runbook - インシデント対応の優先順位付けのためにランブックにSLOへの影響を含める