Tiêu chí | Chaos Toolkit | Chaos Monkey |
---|---|---|
Mục đích | Tạo các thí nghiệm chaos đa dạng, linh hoạt | Chủ yếu tập trung vào injection lỗi nhanh cho ứng dụng Java |
Nền tảng hỗ trợ | Kubernetes, đa đám mây, đa ngôn ngữ | Tối ưu cho Spring Boot (Java) |
Mức độ tùy chỉnh | Rất cao, dễ mở rộng kịch bản | Đơn giản, chủ yếu tấn công tầng ứng dụng |
Cách triển khai | CLI, script, declaration | Thư viện tích hợp trực tiếp vào Spring Boot |
Thao tác mạng & hạ tầng | Có (pod kill, độ trễ, mạng) | Không có |
application.yml
:spring: profiles: active: chaos-monkeychaos: monkey: enabled: true assaults: level: 3 latency-active: true latency-range-start: 2000 latency-range-end: 5000 exceptions-active: true watcher: controller: true service: true repository: true
mvn spring-boot:run -Dspring.profiles.active=chaos-monkey
curl -X POST http://localhost:8080/actuator/chaosmonkey/enable
curl -X POST http://localhost:8080/actuator/chaosmonkey/assaults \ -H "Content-Type: application/json" \ -d '{ "latencyActive": true, "exceptionsActive": true, "level": 5 }'
npm install chaos-monkey --save
const express = require("express");const chaosMonkey = require("chaos-monkey");const app = express();
app.use(chaosMonkey()); // Bơm lỗi ngẫu nhiên
app.get("/", (req, res) => { res.send("Hello, Chaos Monkey!");});
app.listen(3000, () => { console.log("App running on port 3000");});
chaosMonkey.config.js
ví dụ:module.exports = { latency: { enabled: true, minMs: 500, maxMs: 3000, }, exceptions: { enabled: true, probability: 0.2, }, killProcess: { enabled: false, },};
const config = require("./chaosMonkey.config");app.use(chaosMonkey(config));
pip install chaostoolkitpip install chaostoolkit-kubernetespip install -U chaostoolkit-istiopip install -U chaostoolkit-prometheus
{ "version": "1.0.0", "title": "System Resilience to Pod Failures", "description": "Can the system survive a pod failure?", "configuration": { "app_name": { "type": "env", "key": "APP_NAME" }, "namespace": { "type": "env", "key": "NAMESPACE" } }, "steady-state-hypothesis": { "title": "Application must be up and healthy", "probes": [{ "name": "check-application-health", "type": "probe", "provider": { "type": "http", "url": "http://myapp.com/health", "method": "GET" } }] }, "method": [{ "type": "action", "name": "terminate-pod", "provider": { "type": "python", "module": "chaosk8s.pod.actions", "func": "terminate_pods", "arguments": { "label_selector": "app=${app_name}", "ns": "${namespace}", "rand": true, "mode": "fixed", "qty": 1 } } }]}
chaos run pod-kill-experiment.json --journal-path=pod-kill-experiment-journal.json
chaos report --export-format=html pod-kill-experiment-journal.json > pod-kill-experiment-report.html
version: "1.0.0"title: "Region Delay Experiment"description: "Simulating high latency in a specific region"method: - type: action name: "inject-fault" provider: type: python module: chaosistio.fault.actions func: add_delay_fault arguments: virtual_service_name: "my-service-vs" fixed_delay: "5s" percentage: 100 ns: "default"pauses: before: 5 after: 20rollbacks: - type: action name: "remove-fault" provider: type: python module: chaosistio.fault.actions func: remove_delay_fault arguments: virtual_service_name: "my-service-vs" ns: "default"
chaos run region-delay-experiment.yaml --journal-path=region-delay-journal.json
chaos report --export-format=html region-delay-journal.json > region-delay-report.html
name: Chaos Testing Pipelineon: push: branches: - mainjobs: chaos-test: runs-on: ubuntu-latest steps: - name: Checkout Code uses: actions/checkout@v2 - name: Install Chaos Toolkit run: pip install chaostoolkit - name: Run Chaos Experiment run: chaos run pod-kill-experiment.json - name: Validate Recovery run: curl -f http://myapp.com/health || exit 1