Skip to content

Commit

Permalink
jepsen: add basic kafka test (#21)
Browse files Browse the repository at this point in the history
* project: add new test template for hstream kafka

* project: reorganize & add basic kafka test
  • Loading branch information
Commelina authored Mar 14, 2024
1 parent 160721c commit 8d2687a
Show file tree
Hide file tree
Showing 46 changed files with 5,376 additions and 121 deletions.
81 changes: 61 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:
branches: [main, master]

jobs:
jepsen-test:
legacy-test:
runs-on: ubuntu-latest
name: The simplest jepsen test for HStreamDB
timeout-minutes: 60
name: Jepsen test for hstream legacy mode
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -24,38 +24,79 @@ jobs:
- name: Build base image
run: |
docker build -t jepsen-hstream:base ./docker/base/
./scripts/build_base.sh
- name: Build test images
- name: Build test images (legacy)
run: |
docker-compose --file ./docker/docker-compose.yml \
--compatibility \
-p jepsen \
build
- name: Clean dangling images
./scripts/build_legacy.sh
- name: Check disk space
run: |
df -h
- name: Start test cluster and run jepsen test (legacy)
run: |
docker image prune -f
./scripts/up_legacy.sh
- name: Cleanup resources (legacy)
run: |
./scripts/clean_legacy.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
if: ${{ success() }} || ${{ failure() }}
with:
name: legacy-result
path: |
store/legacy-husky
store/legacy-list-append
/tmp/*.log
!store/latest
!store/current
retention-days: 7

kafka-test:
runs-on: ubuntu-latest
name: Jepsen test for hstream kafka mode
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"

- name: Prepare environment for test
run: |
cd ./docker
./init-secret.sh
- name: Build base image
run: |
./scripts/build_base.sh
- name: Build test images (kafka)
run: |
./scripts/build_kafka.sh
- name: Check disk space
run: |
df -h
- name: Start test cluster and run jepsen test
- name: Start test cluster and run jepsen test (kafka)
run: |
./scripts/up_kafka.sh
- name: Cleanup resources (kafka)
run: |
docker-compose --file ./docker/docker-compose.yml \
--compatibility \
-p jepsen \
up \
--renew-anon-volumes \
--exit-code-from control
./scripts/clean_kafka.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
if: ${{ success() }} || ${{ failure() }}
with:
name: jepsen-test-result
path: |
store/HStream
store/kafka
/tmp/*.log
!store/HStream/latest
!store/latest
!store/current
retention-days: 7
100 changes: 78 additions & 22 deletions .github/workflows/ci_repo_dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
types: image_updated

jobs:
jepsen-test:
legacy-test:
runs-on: ubuntu-latest
name: The simplest jepsen test for HStreamDB
timeout-minutes: 60
name: Jepsen test for hstream legacy mode
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -21,41 +21,97 @@ jobs:
- name: Build base image
run: |
docker build -t jepsen-hstream:base ./docker/base/
./scripts/build_base.sh
- name: Build test images
- name: Build test images (legacy)
run: |
docker-compose --file ./docker/docker-compose.yml \
--compatibility \
-p jepsen \
build
./scripts/build_legacy.sh
- name: Clean dangling images
- name: Check disk space
run: |
df -h
- name: Start test cluster and run jepsen test (legacy)
run: |
./scripts/up_legacy.sh
- name: Cleanup resources (legacy)
run: |
./scripts/clean_legacy.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
if: ${{ success() }} || ${{ failure() }}
with:
name: legacy-result
path: |
store/legacy-husky
store/legacy-list-append
/tmp/*.log
!store/latest
!store/current
retention-days: 7

- name: Post to Slack channel
if: ${{ success() }} || ${{ failure() }}
run: |
if [ "${{ job.status }}" = 'success' ]
then JOB_STATUS_EMOJI=':white_check_mark:'
else JOB_STATUS_EMOJI=':x:'
fi
curl \
-X POST \
-H 'Content-Type: application/json' \
${{ secrets.SLACK_WEBHOOK_URL }} \
--data '{"GitHub Action build result": "${{ job.status }} '"$JOB_STATUS_EMOJI"'",
"Commit info": "https://github.com/hstreamdb/hstream/commit/${{ github.event.client_payload.commit_sha }}",
"Action summary": "https://github.com/'"$GITHUB_REPOSITORY"'/actions/runs/'"$GITHUB_RUN_ID"'"}'
kafka-test:
runs-on: ubuntu-latest
name: Jepsen test for hstream kafka mode
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"

- name: Prepare environment for test
run: |
cd ./docker
./init-secret.sh
- name: Build base image
run: |
docker image prune -f
./scripts/build_base.sh
- name: Build test images (kafka)
run: |
./scripts/build_kafka.sh
- name: Check disk space
run: |
df -h
- name: Start test cluster and run jepsen test
- name: Start test cluster and run jepsen test (kafka)
run: |
docker-compose --file ./docker/docker-compose.yml \
--compatibility \
-p jepsen \
up \
--renew-anon-volumes \
--exit-code-from control
- name: 'Upload Artifact'
./scripts/up_kafka.sh
- name: Cleanup resources (kafka)
run: |
./scripts/clean_kafka.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
if: ${{ success() }} || ${{ failure() }}
with:
name: jepsen-test-result
path: |
store/HStream
store/kafka
/tmp/*.log
!store/HStream/latest
!store/latest
!store/current
retention-days: 7

- name: Post to Slack channel
if: ${{ success() }} || ${{ failure() }}
Expand Down
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Jepsen test instances for [HStreamDB](https://github.com/hstreamdb/hstream).

**Note:**

The following files are forked & modified from [https://github.com/jepsen-io/redpanda](Jepsen's official repository), with the same license.

- `src/jepsen/hstream/kafka_test.clj`
- `src/jepsen/hstream/kafka/*`

## Overview

The project is at its early stage and is under active development.
Expand All @@ -13,27 +20,32 @@ It currently contains the following tests:
## Usage

```
docker-compose --file ./docker/docker-compose.yml --compatibility -p jepsen build
docker-compose --file ./docker/docker-compose.yml --compatibility -p jepsen up --renew-anon-volumes --exit-code-from control
./scripts/build_base.sh
./scripts/build_legacy.sh
./scripts/up_legacy.sh
./scripts/clean_legacy.sh
```

For kafka version test, run `*_kafka.sh`.

## Check Test Results

The test results will be stored at `./store` directory. Check it manually or by a simple server:

- If you have [`leiningen`](https://leiningen.org/) installed:
```
lein with-profile husky run serve
lein with-profile legacy-husky run serve
```
- If you do not have `leiningen`:
```
docker run -t --rm --network host -v $(pwd):/working clojure:temurin-21-lein /bin/bash -c "cd /working && lein with-profile husky run serve"
docker run -t --rm --network host -v $(pwd):/working clojure:temurin-21-lein /bin/bash -c "cd /working && lein with-profile legacy-husky run serve"
```

Then browse the results at `localhost:8080`.

## Customization

- Add `HSTREAM_IMAGE` arg on building step to use your own hstream image.
- Adjust test parameters in `docker/control/Dockerfile`.
- Add `BASE_IMAGE` and `HSTREAM_IMAGE` arg on building step to use your own hstream image.
- Add `USE_CHINA_MIRROR` arg to speed up downloading.
- Add `env_http_proxy` and `env_https_proxy` arg to use proxy from your host (it should allow LAN requests).
- Adjust test parameters in `docker/control/Dockerfile` or `docker/control-kafka/Dockerfile`, then **rebuild images** (no need to rebuild base image).
37 changes: 37 additions & 0 deletions docker/admin-kafka/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ARG BASE_IMAGE="jepsen-hstream:base"
FROM ${BASE_IMAGE}

# Waiting for Zookeeper
COPY ./wait-zk.sh /usr/local/bin/wait-zk
RUN chmod +x /usr/local/bin/wait-zk

# Waiting for logdeviced
COPY ./wait-hstore.sh /usr/local/bin/wait-hstore
RUN chmod +x /usr/local/bin/wait-hstore

# Waiting for hservers
COPY ./wait-hservers.sh /usr/local/bin/wait-hservers
RUN chmod +x /usr/local/bin/wait-hservers

# Config for LogDevice
COPY ./logdevice.json /etc/logdevice.json

EXPOSE 22 6440

CMD /usr/local/bin/init-ssh && \
ZK_IP=$(dig +short zookeeper) && \
sed -i "s/172.16.0.10:2181/$ZK_IP:2181/g" /etc/logdevice.json && \
/usr/local/bin/wait-zk && \
/usr/share/zookeeper/bin/zkCli.sh -server zookeeper:2181 create /logdevice.conf "`cat /etc/logdevice.json`" && \
ld-admin-server \
--config-path zk:zookeeper:2181/logdevice.conf \
--enable-maintenance-manager \
--maintenance-log-snapshotting \
--enable-safety-check-periodic-metadata-update \
>> /tmp/$HOSTNAME.log 2>&1 & \
/usr/local/bin/wait-hstore && \
hadmin store nodes-config bootstrap --metadata-replicate-across node:3 && \
/usr/local/bin/wait-hservers && \
hstream-kafka --host hserver-1 node init >> /tmp/$HOSTNAME.log 2>&1 && \
echo "Bootstraped" > /var/jepsen/shared/hserver-cluster-started && \
tail -f /dev/null
52 changes: 52 additions & 0 deletions docker/admin-kafka/logdevice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"cluster": "logdevice-dev",
"server_settings": {
"enable-node-self-registration": "true",
"enable-nodes-configuration-manager": "true",
"use-nodes-configuration-manager-nodes-configuration": "true",
"enable-cluster-maintenance-state-machine": "true",
"rocksdb-memtable-size-per-node": "1024M",
"free-disk-space-threshold": 0.1
},
"client_settings": {
"enable-nodes-configuration-manager": "true",
"use-nodes-configuration-manager-nodes-configuration": "true",
"admin-client-capabilities": "true"
},
"internal_logs": {
"config_log_deltas": {
"replicate_across": {
"node": 3
}
},
"config_log_snapshots": {
"replicate_across": {
"node": 3
}
},
"event_log_deltas": {
"replicate_across": {
"node": 3
}
},
"event_log_snapshots": {
"replicate_across": {
"node": 3
}
},
"maintenance_log_deltas": {
"replicate_across": {
"node": 3
}
},
"maintenance_log_snapshots": {
"replicate_across": {
"node": 3
}
}
},
"zookeeper": {
"zookeeper_uri": "ip://172.16.0.10:2181",
"timeout": "30s"
}
}
11 changes: 11 additions & 0 deletions docker/admin-kafka/wait-hservers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/bash

until ( \
/usr/local/bin/hstream-kafka --host hserver-1 --port 9092 node status && \
/usr/local/bin/hstream-kafka --host hserver-2 --port 9092 node status && \
/usr/local/bin/hstream-kafka --host hserver-3 --port 9092 node status && \
/usr/local/bin/hstream-kafka --host hserver-4 --port 9092 node status && \
/usr/local/bin/hstream-kafka --host hserver-5 --port 9092 node status \
) >/dev/null 2>&1; do
sleep 1
done;
Loading

0 comments on commit 8d2687a

Please sign in to comment.