How swarmourr/cj works
Purpose and Entry Points
chaos-jungle is a Python chaos-engineering framework for Linux and distributed targets. It injects infrastructure, storage, process, GPU, and LLM/agent faults while measuring and recording experiment outcomes. Primary interfaces are the Python API in chaos_jungle/__init__.py, CLI in chaos_jungle/cli.py, remote daemon in chaos_jungle/daemon.py, and decorator/session conveniences in chaos_jungle/decorators.py.
Experiment Orchestration
ChaosRunner owns the experiment lifecycle: preflight, baseline collection, guarded fault injection, workload execution, chaos collection, cleanup, and persistence. Scenarios group named fault instances; decorators and context managers adapt application code to this runner. Key paths: chaos_jungle/runner.py, chaos_jungle/scenario.py, chaos_jungle/decorators.py.
Fault Model and Execution Boundary
Fault implementations share a base abstraction and execute through a target command boundary. Families cover Linux traffic control/BPF, filesystem/storage scripts, process/resource/state changes, gateway behavior, GPU pressure, and LLM/MCP proxy failures. Faults must support reversal, enabling runner cleanup in exceptional paths. Key paths: chaos_jungle/faults/base.py, chaos_jungle/faults/network.py, chaos_jungle/faults/llm.py.
Targets and Remote Control
Targets abstract where commands and fault actions run: local host, SSH-connected Linux machines, HTTP daemon endpoints, and logging wrappers. SSH uses Paramiko; HTTP targets delegate control to the installed daemon with bearer-token authentication. This separates controller-side orchestration from privileged target-side execution. Key paths: chaos_jungle/targets/base.py, chaos_jungle/targets/ssh.py, chaos_jungle/targets/http.py.
Safety, Validation, and Scheduling
Construction-time validation and preflight checks prevent malformed fault parameters and incompatible or pre-existing system state. Guardrails mediate conflicts with raise/warn/force policies. Separate-mode sessions, timed execution, and multi-experiment scheduling are handled outside core fault definitions. Key paths: chaos_jungle/guardrails.py, chaos_jungle/preflight.py, chaos_jungle/scheduler.py.
Measurement, Judgement, and Persistence
Metrics are collected both before and during chaos via built-ins, custom decorated metrics, scripts, and strategies. Results may be evaluated through oracles, hypotheses, and judging components. Session metadata, fault parameters, command events, and results are persisted locally in SQLite, forming the source for exports and UI views. Key paths: chaos_jungle/metrics/base.py, chaos_jungle/db/session_db.py, chaos_jungle/oracles.py.
Operations, Reporting, and External Dependencies
The dashboard exposes persisted session status, events, metrics, logs, and system-tool availability through FastAPI/uvicorn. Exporters send results to Datadog, Prometheus, or webhooks. Runtime fault dependencies include Linux tc/netem, optional BPF/XDP, and bundled Python/C helper scripts; LLM faults run a local HTTP proxy and redirect client base-URL environment variables. Key paths: chaos_jungle/dashboard.py, chaos_jungle/exporters/base.py, chaos_jungle/scripts/llm_proxy/llm_proxy.py.
Parallel Suites
ExperimentSuite loads Python- or YAML-defined experiments and coordinates sequential or parallel runs across independently targeted scenarios. It is the higher-level fan-out layer above a single ChaosRunner session. Key paths: chaos_jungle/suite.py, chaos_jungle/config.py, chaos_jungle/runner.py.
Main entry points: runner.py ChaosRunner · faults/base.py Fault abstraction · suite.py Experiment suite · targets/base.py Target abstraction
Components 22
Interfaces
- Python API
chaos_jungle/__init__.py - CLI
chaos_jungle/cli.py - Decorators & sessions
chaos_jungle/decorators.py - Remote daemon
chaos_jungle/daemon.py
Experiment control
- Experiment suite · Loads Python or YAML experiments for sequential or parallel execution.
chaos_jungle/suite.py - Experiment config
chaos_jungle/config.py - ChaosRunner · Runs preflight, baseline, injection, workload, collection, cleanup, and persistence.
chaos_jungle/runner.py - Scenario
chaos_jungle/scenario.py - Guardrails & preflight · Validates parameters, target state, and conflict policy.
chaos_jungle/preflight.py - Scheduler · Handles separate-mode sessions and multi-experiment timing.
chaos_jungle/scheduler.py
Target execution
- Fault abstraction
chaos_jungle/faults/base.py - Fault families · Includes traffic control/BPF, storage, process, resource, and proxy failures.
chaos_jungle/faults/network.py - LLM/MCP faults
chaos_jungle/faults/llm.py - Target abstraction
chaos_jungle/targets/base.py - SSH target
chaos_jungle/targets/ssh.py - HTTP target
chaos_jungle/targets/http.py - LLM proxy · Redirects client base-URL environment variables for injected failures.
chaos_jungle/scripts/llm_proxy/llm_proxy.py
Results and operations
- Metrics collection · Supports built-in, custom, script, and strategy metrics.
chaos_jungle/metrics/base.py - Oracles & judgement
chaos_jungle/oracles.py - Session database · Stores metadata, fault parameters, command events, and results.
chaos_jungle/db/session_db.py - Dashboard · Shows persisted session status, events, metrics, logs, and tool availability.
chaos_jungle/dashboard.py - Exporters · Publishes to Datadog, Prometheus, or webhooks.
chaos_jungle/exporters/base.py
Connections 21
- Python API → ChaosRunner: starts experiments
- CLI → Experiment suite: runs suites
- Decorators & sessions → ChaosRunner: adapts application code
- Experiment suite → Experiment config: loads definitions
- Experiment suite → ChaosRunner: fans out runs
- Scheduler → ChaosRunner: times sessions
- ChaosRunner → Scenario: executes
- ChaosRunner → Guardrails & preflight: preflight checks
- ChaosRunner → Metrics collection: collects baseline and chaos
- ChaosRunner → Oracles & judgement: evaluates outcomes
- ChaosRunner → Session database: persists lifecycle
- Scenario → Fault abstraction: contains faults
- Fault families → Fault abstraction: implements
- LLM/MCP faults → Fault abstraction: implements
- Fault abstraction → Target abstraction: executes through
- Target abstraction → SSH target: remote implementation
- Target abstraction → HTTP target: daemon implementation
- HTTP target → Remote daemon: bearer-auth control
- LLM/MCP faults → LLM proxy: uses
- Dashboard → Session database: reads sessions and events
- Exporters → Session database: publishes results