Skip to content

Latest commit

 

History

History
201 lines (144 loc) · 8.67 KB

CONTRIBUTING.md

File metadata and controls

201 lines (144 loc) · 8.67 KB

Welcome

Contributions are very welcome on Karapace. When contributing please keep this in mind:

  • Open an issue to discuss new bigger features.
  • Write code consistent with the project style and make sure the tests are passing.
  • Stay in touch with us if we have follow up questions or requests for further changes.

Development

Local Environment

There is very little you need to get started coding for Karapace:

python -m venv <path_to_venv>
source <path_to_venv>/bin/activate
pip install .
pip install -e .[dev,typing]

Local Environment with Docker & Compose

For isolated testing and development using Docker, we provide convenient make commands that handle all setup automatically. This ensures consistency across development environments.

Quick Setup

Set .env:

cp .env.example .env

Edit .env to customize:

  • PYTHON_VERSION - Python version for Docker builds (default: 3.13)
  • KARAPACE_VERSION - Karapace version (default: 5.0.3)
  • DOCKER_COMPOSE - Docker compose command (default: docker-compose)
  • RUNNER_UID / RUNNER_GID - Container user IDs (check .env.example on how to get)
  • PYTEST_ARGS - Pytest arguments for test runs

Available Commands

Run any make command - make populates the environment with .env:

Some commands run start-karapace-docker-resources, so resources are available.

  • make cli - Open interactive shell inside Karapace container
  • make start-karapace-docker-resources - Start all Docker containers (Kafka, Schema Registry, etc.)
  • make stop-karapace-docker-resources - Stop all Docker containers
  • make type-check-mypy-in-docker - Run type checking in Docker
  • make unit-tests-in-docker - Run unit tests in Docker
  • make integration-tests-in-docker - Run integration tests in Docker
  • make e2e-tests-in-docker - Run end-to-end tests in Docker
  • make smoke-test-schema-registry - Run schema registry smoke tests
  • make smoke-test-rest-proxy - Run REST proxy smoke tests

Website

Karapace documentation is part of this GitHub repository. You can find it in website folder. Its README file contains instructions explaining how you can run documentation website locally.

Tests

Tests are written with the pytest framework, and All PRs are tested for each supported Python version using GitHub Flow.

There are two flavors of tests, unit tests and integration tests:

  • Unit: These are faster and very useful for quick iterations. They are usually testing pure functions.
  • Integration: Are slower but more complete. These tests run Karapace, ZooKeeper, and Kafka servers, pytest's fixtures are used to start/stop these for you.

Both flavors run in parallel using pytest-xdist. New tests should be engineered with this in mind:

  • Don't reuse schema/subject/topic names
  • Expect other clients to be interacting with the servers at the same time.

Before running the tests make sure you have protoc installed. protoc is part of the protobuf-compiler package. In Fedora® distributions you can install it using:

dnf install protobuf-compiler

Running Tests with Docker (Recommended)

Use the make commands for consistent, isolated test environments:

make unit-tests-in-docker
make integration-tests-in-docker
make e2e-tests-in-docker

Running Tests Locally

To run the tests locally in your virtual environment use the binary pytest available in the virtualenv. It will download Kafka to be used in the tests for you:

pytest tests/unit
pytest tests/integration

The integration tests can be configured with the use of a few parameters:

  • --kafka-version: allows to change the version of the Kafka server used by the tests. Example versions: 2.7.2, 2.8.1, 3.0.0.
  • --kafka-bootstrap-servers: A comma separated list of servers. This option allows to use an external server (the tests won't start a server for you)

Other options can be seen with pytest test/integration --help

Static checking and Linting

The code is statically checked and formatted using a few tools. To run these automatically on each commit please enable the pre-commit hooks.

Manual testing

To use your development code, you need to set up a Kafka server and run Karapace from you virtual environment:

docker compose -f ./container/compose.yml up -d kafka
karapace karapace.config.json

Configuration

To see descriptions of configuration keys see our README.

Each configuration key can be overridden with an environment variable prefixed with KARAPACE_, exception being configuration keys that actually start with the karapace string. For example, to override the bootstrap_uri config value, one would use the environment variable KARAPACE_BOOTSTRAP_URI.

Opening a PR

  • Commit messages should describe the changes, not the filenames. Win our admiration by following the excellent advice from Chris Beams when composing commit messages.
  • Choose a meaningful title for your pull request.
  • The pull request description should focus on what changed and why.
  • Check that the tests pass (and add test coverage for your changes if appropriate).
  • Tick the change type in the PR template. Reviewers add the matching label before merging (see below).

Versioning & releases

Karapace follows semantic versioning. Each release takes the highest level among the PRs merged since the previous tag.

Level When Label
Level Example When
--- --- ---
Major (<major>.0.0) 7.0.0 Breaking changes: a config key removed or renamed, a changed default, an incompatible API change, a storage or backup format change, a dropped Python version
Minor (<major>.<minor>.0) 6.3.0 New features, endpoints or config options; major-version dependency upgrades
Patch (<major>.<minor>.<patch>) 6.2.5 Bug fixes, docs, tests, CI, minor dependency bumps

"Generate release notes" groups PRs by these labels (.github/release.yml). An unlabelled PR lands under "Other changes", so an unlabelled feature makes a release look like a patch. Check the labels before every release (step 4 below).

How to cut a release

  1. Open Releases → Draft a new release.
  2. Choose a tag: type the new version, e.g. 6.3.0. GitHub creates the tag on publish.
  3. Target: the commit to release. Pick main, or a recent commit from the list. For an older commit, use gh release create <version> --target <sha> --generate-notes instead.
  4. Previous tag: the last release of the same line. Click "Generate release notes". If the notes have an "Other changes" section, those PRs have no label. Label them (labels can be added after merge) and generate the notes again. To list unlabelled PRs in advance: gh pr list --repo Aiven-Open/karapace --state merged --search "no:label merged:>=<date of the previous tag>"
  5. Pick the version: anything under Breaking changes means a major, otherwise anything under Features means a minor, otherwise a patch.
  6. Publish. The tag push builds the container image.

A release contains the full history up to its target commit. To leave a merged PR out, revert it on main first.

Fixes for an older release line

  1. Merge the fix on main first.
  2. Create the maintenance branch <major>.<minor>.x (a literal x, e.g. 6.2.x) from the line's latest tag if it doesn't exist: git switch -c 6.2.x 6.2.4. Never name a branch like a tag (6.2.5).
  3. If the branch was cut from a tag older than .github/release.yml, cherry-pick that file onto it once.
  4. Cherry-pick the fix with git cherry-pick -x <sha> into a PR against the maintenance branch (e.g. 6.2.x), label it and merge it.
  5. Release the next patch of that line (e.g. 6.2.5) with the maintenance branch as target, and untick "Set as the latest release".

Trademarks:

Fedora and the Infinity design logo are trademarks of Red Hat, Inc.