|
| 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