Kafka data generator and load testing tool - generate fake messages, simulate producers and consumers, test broker failures, and run chaos engineering scenarios
Contributing to khaos
Thanks for your interest in contributing!
Development setup
Requires Go 1.26 or newer (go.mod declares 1.26.5).
git clone https://github.com/aleksandarskrbic/khaos.git
cd khaos
go build -o khaos ./cmd/khaos
./khaos --help
The test suite needs no Docker. It runs against
kfake, an in-process broker that
speaks the real Kafka protocol, so the engine, the clients and the CLI are all exercised
without a container. Docker is only needed to drive the bundled cluster by hand --
khaos cluster-up, or khaos run against it -- while trying a change out end to end.
Before submitting a PR
./scripts/check.sh # gofmt, go vet, go test, static build + `khaos --version`
./scripts/check.sh -r # the same with -race, which is what CI runs
check.sh is the local equivalent of the test job in .github/workflows/ci.yml:
gofmt -l cmd internalmust print nothing.go vet ./...go test ./...---race -timeout 15munder-rand in CI,-timeout 10motherwise.CGO_ENABLED=0 go build ./cmd/khaos, then run the result. The static binary is the product, so it gets built the way it ships. CI goes one step further and smoke-tests it with--version,listandvalidate traffic/high-throughput.
CI runs two jobs check.sh does not:
- cross-compile builds linux/amd64, linux/arm64, darwin/amd64, darwin/arm64 and windows/amd64. Anything that drags in cgo fails here first.
- govulncheck is advisory. It reports vulnerabilities in required modules even when the calling code path is unreachable, so it never fails the build on its own.
Pull requests touching website/ get their own workflow, website-ci.yml: npm ci,
npm run lint, npm run build and an opennextjs-cloudflare build, all from website/ on
Node 22. Merging them to main runs deploy-website.yml, which deploys the site.
Code style
- Run
gofmtbefore committing;./scripts/check.shcatches anything unformatted. - Match the existing package structure (see the Architecture section in
README.md):internal/enginestays independent of any UI (internal/tui),internal/kafkais the only package that constructs Kafka (kgo/kadm) clients --internal/codecowns the Schema Registry client -- andinternal/scenariodepends on nothing else in the repo. - Comments say why, not what. The dash used throughout the codebase is
--, not an em dash. - Tests are required for new features.
- Commit subjects follow conventional commits.
scripts/release.shdrafts the CHANGELOG entry fromfeat:,fix:,perf:,refactor:anddocs:subjects since the last tag and skips everything else, so a user-visible change described aschore:silently misses the release notes.
Adding a scenario
Scenario YAML lives in scenarios/<category>/<name>.yaml, and the binary embeds a copy
under internal/scenario/bundled/. Add the file in both places, byte for byte:
TestBundledCopyMatchesRepo fails the moment the two drift, and TestShippedScenariosValidate
and TestBundledScenariosAreGeneratable check that everything shipped both validates and
actually generates data.
khaos list and khaos validate pick the new file up with no code change. A new category
directory also wants an entry in categoryOrder and categoryInfo in
cmd/khaos/scenarios.go, or it sorts last in khaos list under a title-cased directory
name with no description.
Pull request process
- Fork the repo and branch from
main. - Run
./scripts/check.sh -rand make sure it passes. - Update the docs if behaviour changed. User-facing documentation is
website/content/docs/, and the flag tables live inwebsite/content/docs/reference/cli.mdx. - Open the PR with a clear description of what changed and why.
One other file is worth knowing about: RUNBOOK.md covers building, releasing and driving a
cluster by hand.
The deliberate behavioural choices -- which partitioner, which rebalance protocol, whether
topics are recreated, what a producer does when its buffer fills -- are documented at the
symbol that sets each one, so the explanation cannot drift from the value. Most are in
internal/kafka/policy.go (Partitioner, Balancers, RecreateTopicsByDefault,
BlockOnBufferFull); the other two are scenario.ClusterAssumptions in
internal/scenario/validate.go and engine.DefaultFlowConcurrency in
internal/engine/flow.go. Each doc comment gives the current value, why it was chosen, and
what changes if you flip it.