Skip to content

Commit a79b6a2

Browse files
author
amuraru
committed
(ci) Run e2e tests as part of PR/CI checks (#14)
1 parent cdf025f commit a79b6a2

File tree

8 files changed

+1098
-0
lines changed

8 files changed

+1098
-0
lines changed

.github/workflows/e2e-tests.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
branches: ["main", "master"]
6+
pull_request:
7+
branches: ["main", "master"]
8+
workflow_dispatch:
9+
10+
jobs:
11+
e2e-tests:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 15
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v5
18+
19+
- name: Set up Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version-file: 'go.mod'
23+
24+
- name: Start Kafka 4 with KRaft
25+
run: make e2e-setup
26+
27+
- name: Build KMinion
28+
run: make build
29+
30+
- name: Start KMinion with E2E tests
31+
run: make e2e-start
32+
33+
- name: Run integration tests
34+
run: make e2e-test
35+
36+
- name: Show logs on failure
37+
if: failure()
38+
run: |
39+
echo "=== Kafka logs ==="
40+
docker logs broker 2>&1 | tail -100 || echo "No Kafka logs found"
41+
echo ""
42+
echo "=== KMinion logs ==="
43+
cat kminion.log || echo "No KMinion logs found"
44+
45+
- name: Cleanup
46+
if: always()
47+
run: make e2e-cleanup
48+

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+

e2e/bin/README.md

Lines changed: 277 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
# KMinion E2E Integration Tests
2+
3+
This directory contains end-to-end integration tests for KMinion, including scripts to set up a test Kafka cluster and validate KMinion's metrics.
4+
5+
## Overview
6+
7+
The E2E test suite validates:
8+
- **End-to-End Monitoring**: KMinion's ability to produce, consume, and measure message latencies
9+
- **Built-in Metrics**: Core exporter metrics, Kafka cluster info, broker info, and topic metrics
10+
11+
## Scripts
12+
13+
All scripts are located in the `e2e/bin/` directory.
14+
15+
### `setup-kafka.sh`
16+
Manages a Kafka 4.0 cluster with KRaft mode in Docker for testing.
17+
18+
**Usage:**
19+
```bash
20+
# Start Kafka
21+
./e2e/bin/setup-kafka.sh start
22+
23+
# Stop Kafka
24+
./e2e/bin/setup-kafka.sh stop
25+
26+
# Restart Kafka
27+
./e2e/bin/setup-kafka.sh restart
28+
29+
# Check status
30+
./e2e/bin/setup-kafka.sh status
31+
32+
# View logs
33+
./e2e/bin/setup-kafka.sh logs
34+
```
35+
36+
**Environment Variables:**
37+
- `KAFKA_VERSION`: Kafka version (default: `4.1.0`)
38+
- `KAFKA_PORT`: Kafka port (default: `9092`)
39+
- `CONTAINER_NAME`: Docker container name (default: `broker`)
40+
- `WAIT_TIMEOUT`: Wait timeout in seconds (default: `60`)
41+
42+
**Example:**
43+
```bash
44+
# Start Kafka on a different port
45+
KAFKA_PORT=9093 ./e2e/bin/setup-kafka.sh start
46+
```
47+
48+
### `start-kminion.sh`
49+
Starts KMinion with E2E configuration and waits for it to be ready.
50+
51+
**Usage:**
52+
```bash
53+
# Start KMinion
54+
./e2e/bin/start-kminion.sh start
55+
56+
# Stop KMinion
57+
./e2e/bin/start-kminion.sh stop
58+
59+
# Restart KMinion
60+
./e2e/bin/start-kminion.sh restart
61+
62+
# Check status
63+
./e2e/bin/start-kminion.sh status
64+
65+
# View logs
66+
./e2e/bin/start-kminion.sh logs
67+
```
68+
69+
**Environment Variables:**
70+
- `CONFIG_FILE`: Path to config file (default: `e2e/bin/test-config.yaml`)
71+
- `KMINION_BIN`: Path to KMinion binary (default: `./kminion`)
72+
- `LOG_FILE`: Path to log file (default: `kminion.log`)
73+
- `METRICS_URL`: Metrics endpoint URL (default: `http://localhost:8080/metrics`)
74+
- `WAIT_TIMEOUT`: Wait timeout in seconds (default: `30`)
75+
76+
**Example:**
77+
```bash
78+
# Start with custom config
79+
CONFIG_FILE=my-config.yaml ./e2e/bin/start-kminion.sh start
80+
```
81+
82+
### `integration-test.sh`
83+
Validates KMinion's E2E and built-in metrics.
84+
85+
**Usage:**
86+
```bash
87+
# Run all integration tests
88+
./e2e/bin/integration-test.sh
89+
```
90+
91+
**Environment Variables:**
92+
- `METRICS_URL`: KMinion metrics endpoint (default: `http://localhost:8080/metrics`)
93+
- `WAIT_TIMEOUT`: Wait timeout in seconds (default: `30`)
94+
95+
**Example:**
96+
```bash
97+
# Test against a different KMinion instance
98+
METRICS_URL=http://localhost:8081/metrics ./e2e/bin/integration-test.sh
99+
```
100+
101+
## Running Tests Locally
102+
103+
### Prerequisites
104+
- Docker
105+
- `curl`
106+
- `nc` (netcat)
107+
- Go 1.21+ (for building KMinion)
108+
- GNU Make
109+
110+
### Quick Start with Makefile
111+
112+
The easiest way to run E2E tests is using the Makefile targets:
113+
114+
```bash
115+
# Run the complete E2E test suite (setup, build, test, cleanup)
116+
make e2e-full
117+
```
118+
119+
This single command will:
120+
1. Start Kafka cluster
121+
2. Build KMinion
122+
3. Start KMinion with E2E config
123+
4. Run integration tests
124+
5. Cleanup everything
125+
126+
### Step-by-Step with Makefile
127+
128+
If you prefer to run steps individually:
129+
130+
```bash
131+
# 1. Start Kafka cluster
132+
make e2e-setup
133+
134+
# 2. Build KMinion
135+
make build
136+
137+
# 3. Start KMinion with E2E config
138+
make e2e-start
139+
140+
# 4. Run integration tests
141+
make e2e-test
142+
143+
# 5. Cleanup
144+
make e2e-cleanup
145+
```
146+
147+
### Manual Test Flow (without Makefile)
148+
149+
1. **Start Kafka cluster:**
150+
```bash
151+
./e2e/bin/setup-kafka.sh start
152+
```
153+
154+
2. **Build KMinion:**
155+
```bash
156+
go build -o kminion .
157+
```
158+
159+
3. **Start KMinion:**
160+
```bash
161+
./e2e/bin/start-kminion.sh start
162+
```
163+
164+
4. **Run integration tests:**
165+
```bash
166+
./e2e/bin/integration-test.sh
167+
```
168+
169+
5. **Cleanup:**
170+
```bash
171+
./e2e/bin/start-kminion.sh stop
172+
./e2e/bin/setup-kafka.sh stop
173+
```
174+
175+
### Available Makefile Targets
176+
177+
```bash
178+
make help # Show all available targets
179+
make build # Build KMinion binary
180+
make test # Run unit tests
181+
make e2e-setup # Start Kafka cluster for E2E testing
182+
make e2e-start # Start KMinion with E2E configuration
183+
make e2e-stop # Stop KMinion
184+
make e2e-test # Run E2E integration tests (requires Kafka and KMinion)
185+
make e2e-cleanup # Stop and cleanup Kafka cluster and KMinion
186+
make e2e-full # Run full E2E test suite (setup, build, start, test, cleanup)
187+
```
188+
189+
## CI Integration
190+
191+
The GitHub Actions workflow (`.github/workflows/e2e-tests.yaml`) uses Makefile targets:
192+
193+
```yaml
194+
- name: Start Kafka 4 with KRaft
195+
run: make e2e-setup
196+
197+
- name: Build KMinion
198+
run: make build
199+
200+
- name: Start KMinion with E2E tests
201+
run: make e2e-start
202+
203+
- name: Run integration tests
204+
run: make e2e-test
205+
206+
- name: Cleanup
207+
run: make e2e-cleanup
208+
```
209+
210+
## Validated Metrics
211+
212+
### E2E Metrics
213+
- `kminion_end_to_end_messages_produced_total` - Total messages produced
214+
- `kminion_end_to_end_messages_received_total` - Total messages received
215+
- `kminion_end_to_end_produce_latency_seconds` - Producer ack latency
216+
- `kminion_end_to_end_roundtrip_latency_seconds` - End-to-end roundtrip latency
217+
- `kminion_end_to_end_offset_commit_latency_seconds` - Offset commit latency
218+
219+
### Built-in Metrics
220+
- `kminion_exporter_up` - Exporter health status
221+
- `kminion_exporter_offset_consumer_records_consumed_total` - Offset consumer records
222+
- `kminion_kafka_cluster_info` - Cluster metadata
223+
- `kminion_kafka_broker_info` - Broker information
224+
- `kminion_kafka_topic_info` - Topic metadata
225+
- `kminion_kafka_topic_partition_count` - Partition counts
226+
- `kminion_kafka_topic_partition_high_water_mark` - Partition offsets
227+
- `kminion_kafka_topic_high_water_mark_sum` - Aggregated topic offsets
228+
- `kminion_kafka_consumer_group_info` - Consumer group information
229+
- `kminion_kafka_broker_log_dir_size_total_bytes` - Broker log directory sizes
230+
231+
## Troubleshooting
232+
233+
### Kafka won't start
234+
```bash
235+
# Check logs
236+
./e2e/bin/setup-kafka.sh logs
237+
238+
# Restart
239+
./e2e/bin/setup-kafka.sh restart
240+
```
241+
242+
### KMinion not producing metrics
243+
```bash
244+
# Check if KMinion is running
245+
curl http://localhost:8080/metrics
246+
247+
# Check KMinion logs
248+
tail -f kminion.log
249+
```
250+
251+
### Port conflicts
252+
```bash
253+
# Use different port
254+
KAFKA_PORT=9093 ./e2e/bin/setup-kafka.sh start
255+
256+
# Update KMinion config to use localhost:9093
257+
```
258+
259+
## Development
260+
261+
To add new test validations, edit `integration-test.sh` and add new validation functions following the existing pattern:
262+
263+
```bash
264+
validate_my_new_metric() {
265+
log_info "Validating my new metric..."
266+
local metrics
267+
metrics=$(fetch_metrics "$METRICS_URL") || return 1
268+
269+
# Your validation logic here
270+
271+
log_info "✅ My new metric validation passed"
272+
return 0
273+
}
274+
```
275+
276+
Then call it from the `main()` function.
277+

0 commit comments

Comments
 (0)