MCP HubMCP Hub
스킬 목록으로 돌아가기

run-chaos-experiment

pjt222
업데이트됨 5 days ago
9 조회
17
2
17
GitHub에서 보기
테스팅aitestingdesign

정보

이 스킬은 Litmus나 Chaos Mesh와 같은 도구를 사용해 카오스 엔지니어링 실험을 설계하고 실행할 수 있게 해줍니다. 제어된 결함 주입을 수행하여 시스템 복원력을 테스트하고, 가설을 검증하며, 장애 복구 능력을 개선합니다. 주요 출시 전, 아키텍처 변경 후 또는 복원력 훈련 중에 장애 가정을 검증하는 데 사용하세요.

빠른 설치

Claude Code

추천
기본
npx skills add pjt222/agent-almanac -a claude-code
플러그인 명령대체
/plugin add https://github.com/pjt222/agent-almanac
Git 클론대체
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/run-chaos-experiment

Claude Code에서 이 명령을 복사하여 붙여넣어 스킬을 설치하세요

문서

執行混沌實驗

注入受控之故障以測試並改善系統韌性。

適用時機

  • 重大產品發佈前(負載測試)
  • 架構變更後(驗證韌性)
  • GameDay 或災難恢復演練期間
  • 為驗證對故障模式之假設
  • 作為 SRE 成熟度計劃之一部分

輸入

  • 必要:Kubernetes 集群(用於 Litmus 或 Chaos Mesh)
  • 必要:穩態定義(「正常」之樣貌)
  • 必要:欲測之假設(如「一個 pod 崩潰時 API 仍可用」)
  • 選擇性:可觀察性堆疊(Prometheus、Grafana)以量測影響
  • 選擇性:回滾計劃

步驟

步驟一:定義穩態與假設

記錄系統正常行為:

## Steady State Definition

### Service: API Gateway
- **Availability**: 99.9% (< 0.1% error rate)
- **Latency**: p95 < 200ms
- **Throughput**: 1000 req/s
- **Dependencies**: Database (Postgres), Cache (Redis), Auth Service

### Metrics
- `rate(http_requests_total{job="api"}[5m])`
- `histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))`
- `rate(http_requests_total{status=~"5.."}[5m])`

## Hypothesis
**"If one API pod is killed, the remaining pods will handle the load with <5s
disruption and no increase in error rate."**

### Validation Criteria
- Error rate remains <1%
- p95 latency stays <300ms (50ms grace)
- Service recovers within 5 seconds
- No cascading failures to downstream services

預期: 對正常行為與成功標準有清晰、可量測之定義。

失敗時: 若無法定義穩態,可觀察性不足。應先增加指標。

步驟二:設定爆炸半徑限制

縮小實驗範圍以最小化風險:

# chaos-config.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: chaos-testing

---
# Label pods participating in chaos experiments
apiVersion: v1
kind: Pod
metadata:
  labels:
    chaos-enabled: "true"
    environment: staging  # NEVER production for first run

設定保護措施:

## Blast Radius Controls

### Environment
- **Scope**: Staging only (first 5 runs)
- **Production**: Only after 5 successful staging runs
- **Timing**: Business hours (09:00-17:00 local), never weekends/holidays

### Target Selection
- **Limit**: Max 1 pod per service
- **Percentage**: Max 25% of replicas
- **Exclusions**: Database, payment service, auth service (critical path)

### Auto-Abort Conditions
- Error rate >10% for >30 seconds
- Customer-facing alerts fire
- Manual abort signal from on-call engineer

### Rollback Plan
- Kubernetes will auto-restart killed pods
- Manual rollback: `kubectl rollout undo deployment/api`
- Incident declared if recovery takes >5 minutes

預期: 實驗有清晰邊界,不致打垮整個系統。

失敗時: 若爆炸半徑過大,縮小範圍。從一個非關鍵服務開始。

步驟三:安裝 Chaos Mesh

部署 Chaos Mesh(Kubernetes 原生):

# Add Chaos Mesh Helm repo
helm repo add chaos-mesh https://charts.chaos-mesh.org
helm repo update

# Install Chaos Mesh in isolated namespace
helm install chaos-mesh chaos-mesh/chaos-mesh \
  --namespace chaos-mesh \
  --create-namespace \
  --set dashboard.create=true \
  --set controllerManager.replicaCount=1

# Verify installation
kubectl get pods -n chaos-mesh

# Access dashboard
kubectl port-forward -n chaos-mesh svc/chaos-dashboard 2333:2333
# Open http://localhost:2333

替代:Litmus(中立於供應商):

# Install Litmus
kubectl apply -f https://litmuschaos.github.io/litmus/litmus-operator-v2.14.0.yaml

# Wait for Litmus pods
kubectl get pods -n litmus

# Install Litmus CRDs
kubectl apply -f https://hub.litmuschaos.io/api/chaos/master?file=charts/generic/experiments.yaml

預期: Chaos Mesh 或 Litmus 已運行,儀表板可存取。

失敗時: 檢查 RBAC 權限。混沌工具需集群範圍存取。

步驟四:建立並執行實驗

範例:Pod Kill 實驗(Chaos Mesh):

# pod-kill-experiment.yaml
apiVersion: chaos-mesh.org/v1alpha1
kind: PodChaos
metadata:
  name: api-pod-kill-test
  namespace: chaos-testing
spec:
  action: pod-kill
  mode: one  # Kill one pod only
  selector:
    namespaces:
      - production
    labelSelectors:
      app: api-gateway
      chaos-enabled: "true"
  duration: "30s"
  scheduler:
    cron: "@every 5m"  # Repeat every 5 minutes (for sustained testing)

施行實驗:

# Apply experiment
kubectl apply -f pod-kill-experiment.yaml

# Watch experiment status
kubectl get podchaos -n chaos-testing -w

# View detailed status
kubectl describe podchaos api-pod-kill-test -n chaos-testing

# Check which pods were affected
kubectl get events -n production --sort-by=.metadata.creationTimestamp | grep api-gateway

於 Grafana 監控影響:

# Error rate during experiment
rate(http_requests_total{status=~"5..", job="api"}[1m])

# Latency spike
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket{job="api"}[1m]))

# Pod restarts
rate(kube_pod_container_status_restarts_total{pod=~"api-.*"}[5m])

預期: Pod 被殺,Kubernetes 重啟之,服務以小波動繼續。

失敗時: 若錯誤率激增或服務顯著降級,中止實驗並調查。

步驟五:分析結果並反覆

建立實驗報告:

# Chaos Experiment Report: API Pod Kill

**Date**: 2025-02-09
**Hypothesis**: API stays available if one pod crashes
**Tool**: Chaos Mesh
**Environment**: Staging
**Duration**: 30 seconds (pod kill + recovery)

## Results

### Metrics During Experiment
- **Error Rate**: Increased from 0.1% to 2.3% (spike lasted 8 seconds)
- **p95 Latency**: Increased from 180ms to 450ms (spike lasted 12 seconds)
- **Recovery Time**: 8 seconds (pod restart + load balancer update)

### Hypothesis Outcome
**FAILED**: Error rate exceeded 1% threshold, latency spike >300ms

## Root Cause Analysis
- Load balancer continued routing to killed pod for 8 seconds (stale endpoint)
- Readiness probe set to 10s interval (too slow)
- No pre-stop hook to drain connections gracefully

## Improvements Made
1. **Reduced readiness probe interval**: 10s → 2s
2. **Added pre-stop hook**: 5-second sleep for connection draining
3. **Tuned load balancer**: Enabled faster endpoint updates

## Follow-Up Experiment
- Re-run with same parameters in 1 week
- Expected: Error rate <1%, recovery <5s

於日誌追蹤實驗:

# chaos-experiment-log.csv
date,experiment,environment,status,error_rate_peak,recovery_time_s,outcome
2025-02-09,pod-kill-api,staging,complete,2.3%,8,failed
2025-02-16,pod-kill-api,staging,complete,0.8%,4,passed
2025-02-23,network-delay-db,staging,aborted,15%,N/A,failed

預期: 學習已捕捉、修正已實施、後續已排程。

失敗時: 若實驗後無行動,混沌工程淪為表演。應將修正列為優先。

步驟六:謹慎晉升至生產

當預備環境實驗持續通過:

# Production pod-kill experiment (more conservative)
apiVersion: chaos-mesh.org/v1alpha1
kind: PodChaos
metadata:
  name: api-pod-kill-prod
  namespace: chaos-testing
spec:
  action: pod-kill
  mode: one
  selector:
    namespaces:
      - production
    labelSelectors:
      app: api-gateway
      chaos-enabled: "true"
  duration: "10s"  # Shorter than staging
  scheduler:
    cron: "0 10 * * 2"  # Tuesdays at 10 AM only (predictable, low-risk time)

生產之保護措施:

# Create a kill switch for production chaos
kubectl create configmap chaos-killswitch \
  -n chaos-testing \
  --from-literal=enabled=true

# Update experiments to check kill switch
# (implementation depends on chaos tool)

預期: 生產實驗於低風險時段執行,並備有緊急開關。

失敗時: 若生產實驗引發事件,立即停用並進行事後檢討。

驗證

  • 穩態與假設已清楚定義
  • 爆炸半徑已限制(環境、範圍、時機)
  • 混沌工具(Chaos Mesh 或 Litmus)已安裝並測試
  • 實驗於預備環境成功執行
  • 結果已附指標與分析記錄
  • 已依發現實施改進
  • 後續實驗驗證了修正
  • 生產實驗僅於 5 次以上預備環境成功後執行

常見陷阱

  • 無假設:「看看會發生什麼」之混沌實驗浪費時間。應始終有假設。
  • 範圍過廣:一次殺死所有 pod 是測試災難恢復而非韌性。從小開始。
  • 生產優先:絕不於生產執行首次實驗。永遠先預備環境。
  • 忽視結果:無行動之混沌即表演。應修正所學。
  • 警報疲勞:混沌實驗會觸發警報。應於 Grafana 註記或靜音預期警報。
  • 無中止計劃:若實驗出錯,需有緊急開關。應預先備妥。

相關技能

  • setup-prometheus-monitoring - 用以量測實驗影響之指標
  • configure-alerting-rules - 混沌期間觸發之警報(預期內)
  • define-slo-sli-sla - 與 SLO 連動之穩態

GitHub 저장소

pjt222/agent-almanac
경로: i18n/wenyan-lite/skills/run-chaos-experiment
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

연관 스킬

evaluating-llms-harness

테스팅

이 Claude Skill은 MMLU, GSM8K를 포함한 60개 이상의 표준화된 학술 과제에서 LLM 성능을 벤치마크하기 위해 lm-evaluation-harness를 실행합니다. 개발자들이 모델 품질을 비교하고, 학습 진행 상황을 추적하거나 학술 결과를 보고할 수 있도록 설계되었습니다. 이 도구는 HuggingFace와 vLLM 모델을 포함한 다양한 백엔드를 지원합니다.

스킬 보기

cloudflare-cron-triggers

테스팅

이 스킬은 cron 표현식을 사용하여 Worker를 스케줄링하기 위한 Cloudflare Cron Triggers 구현에 관한 포괄적인 지식을 제공합니다. 주기적 작업, 유지보수 작업, 자동화된 워크플로우 설정 방법을 다루며, 잘못된 cron 표현식이나 시간대 문제 같은 일반적인 이슈들을 해결하는 방법을 포함합니다. 개발자들은 이를 통해 스케줄된 핸들러 구성, cron 트리거 테스트, Workflows 및 Green Compute와의 연동 작업을 수행할 수 있습니다.

스킬 보기

webapp-testing

테스팅

이 Claude Skill은 Python 스크립트를 통해 로컬 웹 애플리케이션을 테스트하기 위한 Playwright 기반 툴킷을 제공합니다. 프론트엔드 검증, UI 디버깅, 스크린샷 캡처, 로그 확인 기능을 지원하며 서버 라이프사이클을 관리합니다. 브라우저 자동화 작업에 사용하되 컨텍스트 오염을 방지하기 위해 소스 코드를 읽지 않고 스크립트를 직접 실행하세요.

스킬 보기

finishing-a-development-branch

테스팅

이 스킬은 테스트 통과를 확인한 후 체계적인 통합 옵션을 제시하여 개발자가 완성된 작업을 마무리하도록 돕습니다. 구현이 완료된 후 머지, PR 생성, 브랜치 정리와 같은 워크플로우를 안내합니다. 코드가 준비되고 테스트가 완료되었을 때 개발 프로세스를 체계적으로 마무리하기 위해 사용하세요.

스킬 보기