thearrowoftime/notears

GitHub: thearrowoftime/notears

NoTears 为 homelab k3s/Prometheus 环境提供带安全防护的混沌工程实验,并自动验证监控告警是否按预期触发。

Stars: 0 | Forks: 0

# NoTears 为 homelab k3s / Prometheus 技术栈提供安全的混沌工程与检测验证。 受 Netflix Chaos Monkey 启发——带有防护机制,让你(理想情况下)**不留眼泪**。 | 模式 | 任务 | |------|-----| | **Chaos** | 在测试窗口内随机或故意停止容器、重启服务、禁用网络接口、破坏 DNS 或隔离主机/CIDR —— 并且**始终恢复**。 | | **Detect** | 运行这些场景,并检查 **Prometheus** 是否捕获了信号,以及 **Alertmanager** 是否触发了预期的告警。 | 默认状态:**dry-run**。变更操作需要 `--live` 以及确认口令。 ## 安全机制(默认) - 无 `--live` / 无 `--confirm` → **零变更** - `protect_control_plane: true` + 黑名单:对 `homelab-master` / `master` 不予干预 - `k3s`、`ssh`、`sshd` 被禁止作为重启目标 - 故障时长受限(`min` / `max_duration_seconds`) - 在 `finally` 中执行恢复(包括 Ctrl+C)+ 重试 + 主机端 watchdog - `notears recover` 用于紧急修复(同样受 `--live` 限制) ## 安装 ``` git clone https://github.com/thearrowoftime/notears.git cd notears python -m venv .venv # Windows: .\.venv\Scripts\Activate.ps1 # Unix: source .venv/bin/activate pip install -e ".[dev]" cp config.example.yaml config.yaml ``` 编辑 `config.yaml`(SSH 密钥、Prometheus / Alertmanager URL、黑名单)。 ## 快速开始 ``` notears -c config.yaml doctor notears -c config.yaml detect list notears -c config.yaml chaos once notears -c config.yaml chaos once -a kill_container -t homelab-worker2 notears -c config.yaml detect run # LIVE — 实际更改实验环境 notears -c config.yaml --live --confirm "I UNDERSTAND THIS WILL BREAK THINGS" \ chaos once -a restart_service -t worker1:k3s-agent ``` ## Chaos 操作 | 操作 | 效果 | 恢复方式 | |--------|--------|---------| | `kill_container` | `docker stop` | `docker start`(+ watchdog) | | `restart_service` | 通过 SSH 执行 `systemctl restart` | 确保处于 active 状态 | | `disable_interface` | `ip link set … down` | `up`(+ nohup 故障保护) | | `break_dns` | 覆盖 `/etc/resolv.conf` | 恢复备份 | | `isolate_host` | iptables DROP 至主机/CIDR | 清空链 | ## Detection 场景 `scenarios/` 目录下的 YAML 文件。每个文件都声明了一个 chaos 操作以及 Prometheus / Alertmanager 预期。请根据你实际的 kube-prometheus-stack 规则调整 `promql` / `alertname` —— 如果监控系统未能检测到你所声明的情况,场景应当**失败**。 ## 目录结构 ``` notears/ ├── notears/ # Python package │ ├── cli.py │ ├── chaos/ # chaos engine + actions │ └── detection/ # validation + probes ├── scenarios/ ├── tests/ ├── config.example.yaml └── reports/ ``` ## 许可证 MIT
标签:K3s, 内存分配, 可靠性测试, 混沌工程, 自定义请求头, 请求拦截, 运维工具, 逆向工具