| 1 | # Ducktape Tests |
| 2 | |
| 3 | Ducktape-based tests for the Confluent Kafka Python client with comprehensive performance metrics. |
| 4 | |
| 5 | ## Prerequisites |
| 6 | |
| 7 | - `pip install ducktape confluent-kafka psutil` |
| 8 | - Kafka running on `localhost:9092` (PLAINTEXT listener - ducktape tests use the simple port) |
| 9 | - Schema Registry running on `localhost:8081` (uses `host.docker.internal:29092` for Kafka connection) |
| 10 | |
| 11 | ## Running Tests |
| 12 | |
| 13 | ```bash |
| 14 | # Run all tests with integrated performance metrics |
| 15 | ./tests/ducktape/run_ducktape_test.py |
| 16 | |
| 17 | # Run all tests in a file |
| 18 | ./tests/ducktape/run_ducktape_test.py producer |
| 19 | |
| 20 | # Run a specific test with metrics |
| 21 | ./tests/ducktape/run_ducktape_test.py producer SimpleProducerTest.test_basic_produce |
| 22 | ``` |
| 23 | |
| 24 | ## Integrated Performance Metrics Features |
| 25 | |
| 26 | Every test automatically includes: |
| 27 | |
| 28 | - **Latency Tracking**: P50, P95, P99 percentiles with real-time calculation |
| 29 | - **Per-Topic/Partition Metrics**: Detailed breakdown by topic and partition |
| 30 | - **Memory Monitoring**: Peak memory usage and growth tracking with psutil |
| 31 | - **Batch Efficiency**: Messages per poll and buffer utilization analysis |
| 32 | - **Throughput Validation**: Messages/sec and MB/sec with configurable bounds checking |
| 33 | - **Comprehensive Reporting**: Detailed performance reports with pass/fail validation |
| 34 | - **Automatic Bounds Validation**: Performance assertions against configurable thresholds |
| 35 | |
| 36 | ## Configuration |
| 37 | |
| 38 | Performance bounds are loaded from an environment-based JSON config file. By default, it loads `producer_benchmark_bounds.json`, but you can override this with the `BENCHMARK_BOUNDS_CONFIG` environment variable. |
| 39 | |
| 40 | ### Environment-Based Configuration |
| 41 | |
| 42 | The bounds configuration supports different environments with different performance thresholds: |
| 43 | |
| 44 | ```json |
| 45 | { |
| 46 | "_comment": "Performance bounds for benchmark tests by environment", |
| 47 | "local": { |
| 48 | "_comment": "Default bounds for local development - more relaxed thresholds", |
| 49 | "min_throughput_msg_per_sec": 1000.0, |
| 50 | "max_p95_latency_ms": 2000.0, |
| 51 | "max_error_rate": 0.02, |
| 52 | "min_success_rate": 0.98, |
| 53 | "max_p99_latency_ms": 3000.0, |
| 54 | "max_memory_growth_mb": 800.0, |
| 55 | "max_buffer_full_rate": 0.05, |
| 56 | "min_messages_per_poll": 10.0 |
| 57 | }, |
| 58 | "ci": { |
| 59 | "_comment": "Stricter bounds for CI environment - production-like requirements", |
| 60 | "min_throughput_msg_per_sec": 1500.0, |
| 61 | "max_p95_latency_ms": 1500.0, |
| 62 | "max_error_rate": 0.01, |
| 63 | "min_success_rate": 0.99, |
| 64 | "max_p99_latency_ms": 2500.0, |
| 65 | "max_memory_growth_mb": 600.0, |
| 66 | "max_buffer_full_rate": 0.03, |
| 67 | "min_messages_per_poll": 15.0 |
| 68 | }, |
| 69 | "_default_environment": "local" |
| 70 | } |
| 71 | ``` |
| 72 | |
| 73 | ### Environment Selection |
| 74 | |
| 75 | - **BENCHMARK_ENVIRONMENT**: Selects which environment bounds to use (`local`, `ci`, etc.) |
| 76 | - **Default**: Uses "local" environment if not specified |
| 77 | - **CI**: Automatically uses "ci" environment in CI pipelines |
| 78 | |
| 79 | Usage: |
| 80 | ```bash |
| 81 | # Use default environment (local) |
| 82 | ./run_ducktape_test.py |
| 83 | |
| 84 | # Explicitly use local environment |
| 85 | BENCHMARK_ENVIRONMENT=local ./run_ducktape_test.py |
| 86 | |
| 87 | # Use CI environment with stricter bounds |
| 88 | BENCHMARK_ENVIRONMENT=ci ./run_ducktape_test.py |
| 89 | |
| 90 | # Use different config file entirely |
| 91 | BENCHMARK_BOUNDS_CONFIG=custom_bounds.json ./run_ducktape_test.py |
| 92 | ``` |
| 93 | |
| 94 | ```python |
| 95 | from producer_benchmark_metrics import MetricsBounds |
| 96 | |
| 97 | # Loads from BENCHMARK_BOUNDS_CONFIG env var, or producer_benchmark_bounds.json if not set |
| 98 | bounds = MetricsBounds() |
| 99 | |
| 100 | # Or load from a specific config file |
| 101 | bounds = MetricsBounds.from_config_file("my_bounds.json") |
| 102 | ``` |