Skip to content

Commit 826d60b

Browse files
committed
chore(docker): add kraft-based demo
Changes: - Add a gradle task to move binaries to a docker directory - Build docker image from OSS kafka image, adding cache directory, and use binaries generated by Gradle. - Refactor make tasks to use a temporal container to run topic create/fill topic.
1 parent 9bd467c commit 826d60b

File tree

4 files changed

+139
-18
lines changed

4 files changed

+139
-18
lines changed

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ tasks.distTar {
254254
duplicatesStrategy DuplicatesStrategy.EXCLUDE
255255
}
256256

257+
tasks.register('copyDistFiles', Copy) {
258+
from tarTree(tasks.distTar.outputs.files.singleFile)
259+
into layout.buildDirectory.dir('docker')
260+
doFirst {
261+
delete layout.buildDirectory.dir('docker')
262+
}
263+
dependsOn tasks.distTar
264+
}
265+
257266
tasks.register('validateDependencies') {
258267
doLast {
259268
def dependencyVersions = [:]

demo/Makefile

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
##
1616

1717
kafka_container=kafka-ts
18-
bootstrap_server=kafka:29092
1918
bootstrap_server_host=localhost:9092
2019

2120
# Topic defaults
@@ -28,11 +27,13 @@ local_retention_bytes=1
2827
retention_ms=360000000 # 100 hours
2928
local_retention_ms=1000 # 1 second
3029

30+
kafka_image=apache/kafka:3.9.0
31+
3132
.PHONY: create_topic_by_size_ts
3233
create_topic_by_size_ts:
33-
docker exec -e KAFKA_OPTS= $(kafka_container) \
34-
kafka-topics \
35-
--bootstrap-server $(bootstrap_server) \
34+
docker run --network host $(kafka_image) \
35+
/opt/kafka/bin/kafka-topics.sh \
36+
--bootstrap-server $(bootstrap_server_host) \
3637
--create \
3738
--config remote.storage.enable=true \
3839
--config retention.ms=-1 \
@@ -45,9 +46,9 @@ create_topic_by_size_ts:
4546

4647
.PHONY: create_topic_by_time_ts
4748
create_topic_by_time_ts:
48-
docker exec -e KAFKA_OPTS= $(kafka_container) \
49-
kafka-topics \
50-
--bootstrap-server $(bootstrap_server) \
49+
docker run --network host $(kafka_image) \
50+
/opt/kafka/bin/kafka-topics.sh \
51+
--bootstrap-server $(bootstrap_server_host) \
5152
--create \
5253
--config remote.storage.enable=true \
5354
--config segment.bytes=$(segment) \
@@ -59,9 +60,9 @@ create_topic_by_time_ts:
5960

6061
.PHONY: create_topic_by_size_no_ts
6162
create_topic_by_size_no_ts:
62-
docker exec -e KAFKA_OPTS= $(kafka_container) \
63-
kafka-topics \
64-
--bootstrap-server $(bootstrap_server) \
63+
docker run --network host $(kafka_image) \
64+
/opt/kafka/bin/kafka-topics.sh \
65+
--bootstrap-server $(bootstrap_server_host) \
6566
--create \
6667
--config retention.ms=-1 \
6768
--config segment.bytes=$(segment) \
@@ -72,9 +73,9 @@ create_topic_by_size_no_ts:
7273

7374
.PHONY: create_topic_by_time_no_ts
7475
create_topic_by_time_no_ts:
75-
docker exec -e KAFKA_OPTS= $(kafka_container) \
76-
kafka-topics \
77-
--bootstrap-server $(bootstrap_server) \
76+
docker run --network host $(kafka_image) \
77+
/opt/kafka/bin/kafka-topics.sh \
78+
--bootstrap-server $(bootstrap_server_host) \
7879
--create \
7980
--config segment.bytes=$(segment) \
8081
--config retention.ms=$(retention_ms) \
@@ -88,8 +89,9 @@ throughput = 1000
8889

8990
.PHONY: fill_topic
9091
fill_topic:
91-
docker exec -e KAFKA_OPTS= $(kafka_container) \
92-
kafka-producer-perf-test --producer-props bootstrap.servers=$(bootstrap_server) \
92+
docker run --network host $(kafka_image) \
93+
/opt/kafka/bin/kafka-producer-perf-test.sh \
94+
--producer-props bootstrap.servers=$(bootstrap_server_host) \
9395
--topic $(topic) \
9496
--num-records $(num_records) \
9597
--record-size $(record_size) \
@@ -115,13 +117,21 @@ run_gcs_fake_gcs_server:
115117
run_azure_blob_azurite:
116118
docker compose -f compose-azure-blob-azurite.yml up
117119

120+
docker_volume:
121+
cd .. && ./gradlew copyDistFiles
122+
123+
.PHONY: run_kraft_s3_minio
124+
run_kraft_s3_minio: docker_volume
125+
docker compose -f compose-kraft-s3-minio.yml up
126+
118127
.PHONY: clean
119128
clean:
120129
docker compose -f compose-local-fs.yml down
121130
docker compose -f compose-s3-aws.yml down
122131
docker compose -f compose-s3-minio.yml down
123132
docker compose -f compose-gcs-fake-gcs-server.yml down
124133
docker compose -f compose-azure-blob-azurite.yml down
134+
docker compose -f compose-kraft-s3-minio.yml down
125135

126136
.PHONY: show_local_data
127137
show_local_data:
@@ -139,7 +149,7 @@ show_remote_data_s3_aws:
139149

140150
.PHONY: show_remote_data_s3_minio
141151
show_remote_data_s3_minio:
142-
docker run --rm --network=host --entrypoint /usr/bin/bash quay.io/minio/mc \
152+
docker run --rm --network host --entrypoint /usr/bin/bash quay.io/minio/mc \
143153
-c "mc alias set mycloud http://localhost:9000 minioadmin minioadmin && mc ls --recursive mycloud/test-bucket | grep $(topic)"
144154

145155
.PHONY: show_remote_data_gcs_fake_gcs_server
@@ -148,7 +158,7 @@ show_remote_data_gcs_fake_gcs_server:
148158

149159
.PHONY: show_remote_data_azurite
150160
show_remote_data_azurite:
151-
docker run --rm --network=host mcr.microsoft.com/azure-cli \
161+
docker run --rm --network host mcr.microsoft.com/azure-cli \
152162
az storage blob list --container-name test-container \
153163
--account-name devstoreaccount1 \
154164
--account-key Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw== \
@@ -160,7 +170,7 @@ kcat_opts =
160170
# kcat_opts = "-X fetch.wait.max.ms=100"
161171
.PHONY: consume
162172
consume:
163-
docker run --rm --network=host edenhill/kcat:1.7.1 \
173+
docker run --rm --network host edenhill/kcat:1.7.1 \
164174
-b $(bootstrap_server_host) -C -t $(topic) -c $(consume) -o $(offset) -e -f '%t-%p-%o\n' $(kcat_opts)
165175

166176
.env:

demo/compose-kraft-s3-minio.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
##
2+
# Copyright 2023 Aiven Oy
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
##
16+
services:
17+
kafka:
18+
build: ./kraft-s3-minio/
19+
container_name: "kafka-ts"
20+
depends_on:
21+
- minio
22+
ports:
23+
- "9092:9092"
24+
environment:
25+
CLUSTER_ID: "4L6g3nShT-eMCtK--X86sw"
26+
KAFKA_PROCESS_ROLES: "broker,controller"
27+
KAFKA_NODE_ID: 1
28+
KAFKA_CONTROLLER_QUORUM_VOTERS: "1@kafka:29093"
29+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT"
30+
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT_HOST://localhost:9092,PLAINTEXT://kafka:29092"
31+
KAFKA_LISTENERS: "CONTROLLER://:29093,PLAINTEXT_HOST://:9092,PLAINTEXT://:29092"
32+
KAFKA_INTER_BROKER_LISTENER_NAME: "PLAINTEXT"
33+
KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
34+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
35+
KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS: 1
36+
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
37+
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
38+
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
39+
KAFKA_AUTO_CREATE_TOPICS_ENABLE: false
40+
# Increase Tiered Storage log level
41+
KAFKA_LOG4J_LOGGERS: "io.aiven.kafka.tieredstorage=DEBUG"
42+
# Tweak retention checking
43+
KAFKA_LOG_RETENTION_CHECK_INTERVAL_MS: 10000
44+
# Enable Tiered Storage
45+
KAFKA_REMOTE_LOG_STORAGE_SYSTEM_ENABLE: true
46+
KAFKA_REMOTE_LOG_MANAGER_TASK_INTERVAL_MS: 5000
47+
# Remote metadata manager
48+
KAFKA_REMOTE_LOG_METADATA_MANAGER_CLASS_NAME: "org.apache.kafka.server.log.remote.metadata.storage.TopicBasedRemoteLogMetadataManager"
49+
KAFKA_REMOTE_LOG_METADATA_MANAGER_LISTENER_NAME: "PLAINTEXT"
50+
KAFKA_RLMM_CONFIG_REMOTE_LOG_METADATA_TOPIC_REPLICATION_FACTOR: 1
51+
# Remote storage manager
52+
KAFKA_REMOTE_LOG_STORAGE_MANAGER_CLASS_PATH: "/tiered-storage-for-apache-kafka/core/*:/tiered-storage-for-apache-kafka/s3/*"
53+
KAFKA_REMOTE_LOG_STORAGE_MANAGER_CLASS_NAME: "io.aiven.kafka.tieredstorage.RemoteStorageManager"
54+
KAFKA_RSM_CONFIG_CHUNK_SIZE: 4194304 # 4 MiB
55+
KAFKA_RSM_CONFIG_FETCH_CHUNK_CACHE_CLASS: "io.aiven.kafka.tieredstorage.fetch.cache.DiskChunkCache"
56+
KAFKA_RSM_CONFIG_FETCH_CHUNK_CACHE_PATH: /var/lib/kafka/tiered-storage-cache
57+
KAFKA_RSM_CONFIG_FETCH_CHUNK_CACHE_SIZE: 1073741824 # 1 GiB
58+
KAFKA_RSM_CONFIG_FETCH_CHUNK_CACHE_PREFETCH_MAX_SIZE: 16777216 # 16 MiB
59+
KAFKA_RSM_CONFIG_FETCH_CHUNK_CACHE_RETENTION_MS: 600000 # 600000 ms
60+
KAFKA_RSM_CONFIG_CUSTOM_METADATA_FIELDS_INCLUDE: "REMOTE_SIZE"
61+
# Storage backend
62+
KAFKA_RSM_CONFIG_KEY_PREFIX: "tiered-storage-demo/"
63+
KAFKA_RSM_CONFIG_STORAGE_BACKEND_CLASS: "io.aiven.kafka.tieredstorage.storage.s3.S3Storage"
64+
KAFKA_RSM_CONFIG_STORAGE_S3_ENDPOINT_URL: "http://minio:9000"
65+
KAFKA_RSM_CONFIG_STORAGE_S3_BUCKET_NAME: "test-bucket"
66+
KAFKA_RSM_CONFIG_STORAGE_S3_REGION: "us-east-1"
67+
KAFKA_RSM_CONFIG_STORAGE_S3_PATH_STYLE_ACCESS_ENABLED: true
68+
KAFKA_RSM_CONFIG_STORAGE_AWS_ACCESS_KEY_ID: "minioadmin"
69+
KAFKA_RSM_CONFIG_STORAGE_AWS_SECRET_ACCESS_KEY: "minioadmin"
70+
volumes:
71+
# These paths depend on gradle copyDistFiles task run on root directory
72+
- ./../build/docker/tiered-storage-for-apache-kafka-0.0.1-SNAPSHOT:/tiered-storage-for-apache-kafka/core
73+
- ./../storage/s3/build/docker/s3-0.0.1-SNAPSHOT:/tiered-storage-for-apache-kafka/s3
74+
- ./../storage/s3/build/docker/gcs-0.0.1-SNAPSHOT:/tiered-storage-for-apache-kafka/gcs
75+
- ./../storage/s3/build/docker/azure-0.0.1-SNAPSHOT:/tiered-storage-for-apache-kafka/azure
76+
77+
minio:
78+
image: quay.io/minio/minio
79+
ports:
80+
- "9000:9000"
81+
- "9090:9090"
82+
command: server /data --console-address ":9090"
83+
84+
minio-createbucket:
85+
image: quay.io/minio/mc
86+
restart: "no"
87+
depends_on:
88+
- minio
89+
entrypoint: >
90+
/bin/sh -c "
91+
/usr/bin/mc config host add local http://minio:9000 minioadmin minioadmin;
92+
/usr/bin/mc mb local/test-bucket;
93+
exit 0;
94+
"

demo/kraft-s3-minio/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM apache/kafka:3.9.0
2+
3+
ARG _VERSION
4+
5+
USER appuser
6+
7+
RUN mkdir /var/lib/kafka/tiered-storage-cache
8+

0 commit comments

Comments
 (0)