Skip to content

Commit a16d04c

Browse files
Incorporate kafka tests into github work flow (#6)
1. Incorporate kafka tests into github workflow 2. Updated tests to assert that worker exits without error 3. Updated busy loop pause to respect context cancellation 4. Updated virtual partition write to respect context cancellation 5. Added debug logs for reader/processor exit 6. Removed dependency on github.com/errors package (no need for stack trace info) 7. Added go report card 8. Corrected spelling mistakes 9. Updated coverage.sh script to echo each line 10. Updated compose.yml (renamed from docker-compose) to use kafka+zookeeper instead of KRAFT implementation (in local usage) 11. Updated dependencies (confluent-kafka-go/otel)
1 parent 68f29be commit a16d04c

19 files changed

+452
-316
lines changed

Diff for: .github/workflows/go.yml

+8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ jobs:
3232
run: |
3333
go mod download
3434
35+
- name: Run Kafka KRaft Broker
36+
uses: spicyparrot/[email protected]
37+
with:
38+
kafka-version: "3.7.0"
39+
kafka-topics: "example,1"
40+
3541
- name: Test
42+
env:
43+
KAFKA_BOOTSTRAP_SERVER: ${{ env.kafka_runner_address }}:9092
3644
run: make cover
3745

3846
- name: Upload coverage reports to Codecov

Diff for: Makefile

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
# Directories containing independent Go modules.
22
MODULE_DIRS = .
33

4-
.PHONY: test-no-setup
5-
test-no-setup:
6-
./coverage.sh
74

85
.PHONY: setup-test
96
setup-test:
10-
docker compose -p $$RANDOM -f ./example/docker-compose.yaml up -d
7+
docker compose -p $$RANDOM -f ./example/compose.yaml up -d
118

129
.PHONY: test-local
13-
test-local: setup-test test-no-setup
10+
test-local: setup-test cover
1411

1512
.PHONY: cover
1613
cover:
17-
./coverage.sh
14+
export GO_TAGS=--tags=integration; ./coverage.sh --tags=integration
1815

1916
.PHONY: example-producer
2017
example-producer:

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![License](https://img.shields.io/github/license/zillow/zkafka)](https://github.com/zillow/zkafka/blob/main/LICENSE)
44
[![GitHub Actions](https://github.com/zillow/zkafka/actions/workflows/go.yml/badge.svg)](https://github.com/zillow/zkafka/actions/workflows/go.yml)
55
[![Codecov](https://codecov.io/gh/zillow/zkafka/branch/main/graph/badge.svg?token=STRT8T67YP)](https://codecov.io/gh/zillow/zkafka)
6-
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/zillow/zkafka)](https://goreportcard.com/report/github.com/zillow/zkafka)
77

88
## Install
99

@@ -93,7 +93,7 @@ client because that value is explicitly set to true after reading of the Additio
9393
"KafkaTopicConfig": {
9494
"Topic": "KafkaTopicName",
9595
"BootstrapServers": [
96-
"localhost:9093"
96+
"localhost:9092"
9797
],
9898
// translates to librdkafka value "bootstrap.servers"
9999
// specify ad hoc configuration values which don't have a strongly typed version in the TopicConfig struct.

Diff for: commitmgr_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ func Test_commitMgr_PerPartitionDataStructuresBuiltUpConcurrentlyCorrectly(t *te
197197
require.Equal(t, int64(0), mgr.inWorkCount, "expected inWorkCount to be empty")
198198
}
199199

200-
// Test_commitMgr_mutex_ShouldReturnReferenceToSameMutexForSamePartition tests for a race condition (based on bugfound)
201-
// where two goroutines calling this method received distinct mutexes (which isn't correct for syncronization purposes).
200+
// Test_commitMgr_mutex_ShouldReturnReferenceToSameMutexForSamePartition tests for a race condition (based on bug found)
201+
// where two goroutines calling this method received distinct mutexes (which isn't correct for synchronization purposes).
202202
// Try a large amount of times to access the mutex for a particular partition. Always should return same pointer
203203
func Test_commitMgr_mutex_ShouldReturnReferenceToSameMutexForSamePartition(t *testing.T) {
204204
defer recoverThenFail(t)

Diff for: coverage.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
#!/usr/bin/env bash
2+
set -x
3+
4+
go_tags=$GO_TAGS
5+
go_tags="${go_tags:---tags=unit}"
26

37
# golang packages that will be used for either testing or will be assessed for coverage
48
pck1=github.com/zillow/zkafka
@@ -22,11 +26,11 @@ function quit() {
2226
}
2327
# change to example directory for execution (because it uses hardcoded filepaths, and the testable
2428
# examples don't work when executed outside of that directory
25-
go test -c -coverpkg=$pck1 -covermode=atomic -o "$root_res" $pck1
29+
go test $go_tags -c -coverpkg=$pck1 -covermode=atomic -o "$root_res" $pck1
2630
# convert binary to go formatted
2731
go tool test2json -t "$root_res" -test.v -test.coverprofile "$root_out"
2832

29-
go test -c -coverpkg=$pck1 -covermode=atomic -o "$source_res" $pck2
33+
go test $go_tags -c -coverpkg=$pck1 -covermode=atomic -o "$source_res" $pck2
3034
go tool test2json -t "$source_res" -test.v -test.coverprofile "$source_out"
3135

3236
# delete aggregate file

Diff for: example/compose.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
zookeeper:
3+
image: confluentinc/cp-zookeeper:latest
4+
container_name: zkafka-zookeeper
5+
environment:
6+
ZOOKEEPER_CLIENT_PORT: 2181
7+
ZOOKEEPER_TICK_TIME: 2000
8+
ports:
9+
- "22181:2181"
10+
kafka:
11+
image: confluentinc/cp-kafka:latest
12+
container_name: zkafka-broker
13+
depends_on:
14+
- zookeeper
15+
ports:
16+
- "29092:29092"
17+
- "9092:9092"
18+
environment:
19+
KAFKA_BROKER_ID: 1
20+
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
21+
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
22+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
23+
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
24+
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

Diff for: example/consumer/consumer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func main() {
1313
// configure broker connectivity options with zkafka.Config
1414
cfg := zkafka.Config{
15-
BootstrapServers: []string{"localhost:9093"},
15+
BootstrapServers: []string{"localhost:9092"},
1616
}
1717

1818
// configure consumer options with zkafka.ConsumerTopicConfig. See zkafka for full option values

Diff for: example/docker-compose.yaml

-10
This file was deleted.

Diff for: example/producer/producer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
func main() {
1515
ctx := context.Background()
1616
writer, err := zkafka.NewClient(zkafka.Config{
17-
BootstrapServers: []string{"localhost:9093"},
17+
BootstrapServers: []string{"localhost:9092"},
1818
}).Writer(ctx, zkafka.ProducerTopicConfig{
1919
ClientID: "example",
2020
Topic: "two-multi-partition",

Diff for: example/worker/worker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func main() {
1818
ctx := context.Background()
1919
client := zkafka.NewClient(zkafka.Config{
20-
BootstrapServers: []string{"localhost:9093"},
20+
BootstrapServers: []string{"localhost:9092"},
2121
},
2222
zkafka.LoggerOption(stdLogger{}),
2323
)

Diff for: go.mod

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ module github.com/zillow/zkafka
33
go 1.22
44

55
require (
6-
github.com/confluentinc/confluent-kafka-go/v2 v2.4.0
6+
github.com/confluentinc/confluent-kafka-go/v2 v2.5.0
77
github.com/golang/mock v1.6.0
88
github.com/google/go-cmp v0.6.0
99
github.com/google/uuid v1.6.0
10-
github.com/pkg/errors v0.9.1
1110
github.com/sony/gobreaker v1.0.0
1211
github.com/stretchr/testify v1.9.0
1312
github.com/zillow/zfmt v1.0.1
14-
go.opentelemetry.io/otel v1.27.0
15-
go.opentelemetry.io/otel/trace v1.27.0
13+
go.opentelemetry.io/otel v1.28.0
14+
go.opentelemetry.io/otel/trace v1.28.0
1615
golang.org/x/sync v0.7.0
1716
)
1817

@@ -24,7 +23,7 @@ require (
2423
github.com/golang/protobuf v1.5.4 // indirect
2524
github.com/heetch/avro v0.4.5 // indirect
2625
github.com/pmezard/go-difflib v1.0.0 // indirect
27-
go.opentelemetry.io/otel/metric v1.27.0 // indirect
26+
go.opentelemetry.io/otel/metric v1.28.0 // indirect
2827
google.golang.org/protobuf v1.34.2 // indirect
2928
gopkg.in/yaml.v3 v3.0.1 // indirect
3029
)

0 commit comments

Comments
 (0)