Skip to content

Commit 0c062f4

Browse files
author
amuraru
committed
refactor
1 parent a589000 commit 0c062f4

File tree

8 files changed

+1046
-259
lines changed

8 files changed

+1046
-259
lines changed

.github/workflows/e2e-tests.yaml

Lines changed: 7 additions & 259 deletions
Original file line numberDiff line numberDiff line change
@@ -22,279 +22,27 @@ jobs:
2222
go-version-file: 'go.mod'
2323

2424
- name: Start Kafka 4 with KRaft
25-
run: |
26-
docker run -d \
27-
--name broker \
28-
--network host \
29-
-e KAFKA_NODE_ID=1 \
30-
-e KAFKA_PROCESS_ROLES=broker,controller \
31-
-e KAFKA_LISTENERS=PLAINTEXT://localhost:9092,CONTROLLER://localhost:9093 \
32-
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 \
33-
-e KAFKA_CONTROLLER_LISTENER_NAMES=CONTROLLER \
34-
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT \
35-
-e KAFKA_CONTROLLER_QUORUM_VOTERS=1@localhost:9093 \
36-
-e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 \
37-
-e KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR=1 \
38-
-e KAFKA_TRANSACTION_STATE_LOG_MIN_ISR=1 \
39-
-e KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS=0 \
40-
-e KAFKA_NUM_PARTITIONS=3 \
41-
apache/kafka:4.1.0
42-
43-
# Wait for Kafka to be ready
44-
echo "Waiting for Kafka to start..."
45-
for i in {1..60}; do
46-
# Check if Kafka is listening on port 9092
47-
if nc -z localhost 9092 2>/dev/null; then
48-
echo "Kafka port 9092 is open!"
49-
# Give it a couple more seconds to fully initialize
50-
sleep 3
51-
# Try to get broker API versions
52-
if docker exec broker /opt/kafka/bin/kafka-broker-api-versions.sh --bootstrap-server localhost:9092 > /dev/null 2>&1; then
53-
echo "Kafka is ready and responding to requests!"
54-
break
55-
fi
56-
fi
57-
if [ $i -eq 60 ]; then
58-
echo "Kafka failed to start within 60 seconds"
59-
echo "=== Kafka logs ==="
60-
docker logs broker
61-
exit 1
62-
fi
63-
echo "Attempt $i/60: Kafka not ready yet, waiting..."
64-
sleep 1
65-
done
66-
67-
# Verify Kafka is running
68-
echo "Verifying Kafka cluster..."
69-
docker exec broker /opt/kafka/bin/kafka-broker-api-versions.sh --bootstrap-server localhost:9092
70-
echo "Kafka cluster is up and running!"
71-
72-
- name: Create KMinion configuration
73-
run: |
74-
cat > kminion-config.yaml << 'EOF'
75-
kafka:
76-
brokers:
77-
- localhost:9092
78-
clientId: kminion-e2e-test
79-
80-
minion:
81-
endToEnd:
82-
enabled: true
83-
probeInterval: 500ms
84-
topicManagement:
85-
enabled: true
86-
name: kminion-end-to-end
87-
replicationFactor: 1
88-
partitionsPerBroker: 1
89-
reconciliationInterval: 10s
90-
producer:
91-
ackSla: 5s
92-
requiredAcks: all
93-
consumer:
94-
groupIdPrefix: kminion-end-to-end
95-
deleteStaleConsumerGroups: false
96-
roundtripSla: 10s
97-
commitSla: 5s
98-
99-
exporter:
100-
namespace: kminion
101-
port: 8080
102-
103-
logger:
104-
level: info
105-
EOF
25+
run: make e2e-setup
10626

10727
- name: Build KMinion
108-
run: |
109-
go build -o kminion .
28+
run: make build
11029

11130
- name: Start KMinion with E2E tests
112-
run: |
113-
export CONFIG_FILEPATH=kminion-config.yaml
114-
./kminion > kminion.log 2>&1 &
115-
KMINION_PID=$!
116-
echo "KMINION_PID=$KMINION_PID" >> $GITHUB_ENV
117-
118-
# Wait for KMinion to start
119-
echo "Waiting for KMinion to start..."
120-
for i in {1..30}; do
121-
if curl -s http://localhost:8080/metrics > /dev/null 2>&1; then
122-
echo "KMinion is ready!"
123-
break
124-
fi
125-
if [ $i -eq 30 ]; then
126-
echo "KMinion failed to start within 30 seconds"
127-
cat kminion.log
128-
exit 1
129-
fi
130-
echo "Attempt $i/30: KMinion not ready yet, waiting..."
131-
sleep 1
132-
done
133-
134-
- name: Wait for E2E tests to run
135-
run: |
136-
echo "Waiting for E2E tests to produce metrics..."
137-
sleep 30
138-
139-
- name: Validate E2E metrics
140-
run: |
141-
echo "Fetching metrics from KMinion..."
142-
METRICS=$(curl -s http://localhost:8080/metrics)
143-
144-
echo "=== KMinion Metrics Output ==="
145-
echo "$METRICS" | grep -E "kminion_end_to_end_" || true
146-
echo "=============================="
147-
148-
# Check for essential E2E metrics
149-
REQUIRED_METRICS=(
150-
"kminion_end_to_end_messages_produced_total"
151-
"kminion_end_to_end_messages_received_total"
152-
"kminion_end_to_end_produce_latency_seconds"
153-
"kminion_end_to_end_roundtrip_latency_seconds"
154-
"kminion_end_to_end_offset_commit_latency_seconds"
155-
)
156-
157-
MISSING_METRICS=()
158-
for metric in "${REQUIRED_METRICS[@]}"; do
159-
if ! echo "$METRICS" | grep -q "^${metric}"; then
160-
MISSING_METRICS+=("$metric")
161-
fi
162-
done
163-
164-
if [ ${#MISSING_METRICS[@]} -ne 0 ]; then
165-
echo "ERROR: Missing required E2E metrics:"
166-
printf '%s\n' "${MISSING_METRICS[@]}"
167-
echo ""
168-
echo "=== Full KMinion logs ==="
169-
cat kminion.log
170-
exit 1
171-
fi
172-
173-
# Verify messages were produced and received
174-
PRODUCED=$(echo "$METRICS" | grep "^kminion_end_to_end_messages_produced_total" | awk '{print $2}')
175-
RECEIVED=$(echo "$METRICS" | grep "^kminion_end_to_end_messages_received_total" | awk '{print $2}')
176-
177-
echo "Messages produced: $PRODUCED"
178-
echo "Messages received: $RECEIVED"
179-
180-
if [ -z "$PRODUCED" ] || [ "$PRODUCED" = "0" ]; then
181-
echo "ERROR: No messages were produced"
182-
cat kminion.log
183-
exit 1
184-
fi
185-
186-
if [ -z "$RECEIVED" ] || [ "$RECEIVED" = "0" ]; then
187-
echo "ERROR: No messages were received"
188-
cat kminion.log
189-
exit 1
190-
fi
191-
192-
echo "✅ E2E tests passed successfully!"
193-
echo " - Messages produced: $PRODUCED"
194-
echo " - Messages received: $RECEIVED"
195-
196-
- name: Validate built-in KMinion metrics
197-
run: |
198-
echo "Validating built-in KMinion metrics..."
199-
METRICS=$(curl -s http://localhost:8080/metrics)
200-
201-
# Core exporter metrics
202-
CORE_METRICS=(
203-
"kminion_exporter_up"
204-
"kminion_exporter_offset_consumer_records_consumed_total"
205-
)
31+
run: make e2e-start
20632

207-
# Kafka cluster metrics
208-
KAFKA_METRICS=(
209-
"kminion_kafka_cluster_info"
210-
"kminion_kafka_broker_info"
211-
)
212-
213-
# Topic metrics
214-
TOPIC_METRICS=(
215-
"kminion_kafka_topic_info"
216-
"kminion_kafka_topic_partition_count"
217-
"kminion_kafka_topic_partition_high_water_mark"
218-
"kminion_kafka_topic_high_water_mark_sum"
219-
)
220-
221-
MISSING_METRICS=()
222-
223-
# Check core metrics
224-
for metric in "${CORE_METRICS[@]}"; do
225-
if ! echo "$METRICS" | grep -q "^${metric}"; then
226-
MISSING_METRICS+=("$metric")
227-
fi
228-
done
229-
230-
# Check Kafka metrics
231-
for metric in "${KAFKA_METRICS[@]}"; do
232-
if ! echo "$METRICS" | grep -q "^${metric}"; then
233-
MISSING_METRICS+=("$metric")
234-
fi
235-
done
236-
237-
# Check topic metrics
238-
for metric in "${TOPIC_METRICS[@]}"; do
239-
if ! echo "$METRICS" | grep -q "^${metric}"; then
240-
MISSING_METRICS+=("$metric")
241-
fi
242-
done
243-
244-
if [ ${#MISSING_METRICS[@]} -ne 0 ]; then
245-
echo "ERROR: Missing required built-in metrics:"
246-
printf '%s\n' "${MISSING_METRICS[@]}"
247-
echo ""
248-
echo "=== Available metrics ==="
249-
echo "$METRICS" | grep "^kminion_" | head -20
250-
exit 1
251-
fi
252-
253-
# Validate specific metric values
254-
EXPORTER_UP=$(echo "$METRICS" | grep "^kminion_exporter_up" | awk '{print $2}')
255-
if [ "$EXPORTER_UP" != "1" ]; then
256-
echo "ERROR: kminion_exporter_up should be 1, got: $EXPORTER_UP"
257-
exit 1
258-
fi
259-
260-
# Check that cluster info has broker_count label
261-
if ! echo "$METRICS" | grep "kminion_kafka_cluster_info" | grep -q "broker_count"; then
262-
echo "ERROR: kminion_kafka_cluster_info missing broker_count label"
263-
exit 1
264-
fi
265-
266-
# Check that we have broker info for at least one broker
267-
BROKER_COUNT=$(echo "$METRICS" | grep "^kminion_kafka_broker_info" | wc -l)
268-
if [ "$BROKER_COUNT" -lt 1 ]; then
269-
echo "ERROR: No broker info metrics found"
270-
exit 1
271-
fi
272-
273-
echo "✅ Built-in KMinion metrics validation passed!"
274-
echo " - Exporter up: $EXPORTER_UP"
275-
echo " - Brokers detected: $BROKER_COUNT"
33+
- name: Run integration tests
34+
run: make e2e-test
27635

27736
- name: Show logs on failure
27837
if: failure()
27938
run: |
28039
echo "=== Kafka logs ==="
281-
docker logs broker || echo "No Kafka logs found"
40+
docker logs broker 2>&1 | tail -100 || echo "No Kafka logs found"
28241
echo ""
28342
echo "=== KMinion logs ==="
28443
cat kminion.log || echo "No KMinion logs found"
28544
28645
- name: Cleanup
28746
if: always()
288-
run: |
289-
# Stop KMinion
290-
if [ ! -z "$KMINION_PID" ]; then
291-
kill $KMINION_PID || true
292-
fi
293-
294-
# Stop and remove Kafka container
295-
docker stop broker || true
296-
docker rm broker || true
297-
298-
# Wait a bit for graceful shutdown
299-
sleep 2
47+
run: make e2e-cleanup
30048

Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.PHONY: help build test e2e-setup e2e-start e2e-stop e2e-test e2e-cleanup e2e-full
2+
3+
help: ## Show this help message
4+
@echo 'Usage: make [target]'
5+
@echo ''
6+
@echo 'Available targets:'
7+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
8+
9+
build: ## Build KMinion binary
10+
go build -o kminion .
11+
12+
test: ## Run unit tests
13+
go test -v ./...
14+
15+
e2e-setup: ## Start Kafka cluster for E2E testing
16+
@chmod +x e2e/bin/setup-kafka.sh
17+
./e2e/bin/setup-kafka.sh start
18+
19+
e2e-start: ## Start KMinion with E2E configuration
20+
@chmod +x e2e/bin/start-kminion.sh
21+
./e2e/bin/start-kminion.sh start
22+
23+
e2e-stop: ## Stop KMinion
24+
@chmod +x e2e/bin/start-kminion.sh
25+
./e2e/bin/start-kminion.sh stop
26+
27+
e2e-test: ## Run E2E integration tests (requires Kafka and KMinion to be running)
28+
@chmod +x e2e/bin/integration-test.sh
29+
./e2e/bin/integration-test.sh
30+
31+
e2e-cleanup: ## Stop and cleanup Kafka cluster and KMinion
32+
@chmod +x e2e/bin/start-kminion.sh e2e/bin/setup-kafka.sh
33+
./e2e/bin/start-kminion.sh stop || true
34+
./e2e/bin/setup-kafka.sh stop || true
35+
36+
e2e-full: e2e-setup ## Run full E2E test suite (setup, build, start, test, cleanup)
37+
@echo "Starting full E2E test suite..."
38+
@trap '$(MAKE) e2e-cleanup' EXIT; \
39+
$(MAKE) build && \
40+
$(MAKE) e2e-start && \
41+
$(MAKE) e2e-test
42+

e2e/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# E2E test artifacts
2+
*.log
3+
*.pid
4+

0 commit comments

Comments
 (0)