|
| 1 | +# GitHub Copilot Instructions for oha |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +`oha` (おはよう) is an HTTP load testing tool written in Rust, inspired by `rakyll/hey`. It provides real-time TUI (Terminal User Interface) visualization of load testing results using `ratatui`. |
| 6 | + |
| 7 | +## Key Technologies & Dependencies |
| 8 | + |
| 9 | +- **Language**: Rust (edition 2024, MSRV 1.85) |
| 10 | +- **Async Runtime**: `tokio` with full features |
| 11 | +- **HTTP Client**: `hyper` (v1.4) with HTTP/1, HTTP/2 support |
| 12 | +- **TUI**: `ratatui` with `crossterm` backend |
| 13 | +- **CLI**: `clap` with derive features |
| 14 | +- **Memory Allocator**: `tikv-jemallocator` (non-MSVC targets) |
| 15 | +- **Error Handling**: `anyhow` and `thiserror` |
| 16 | +- **JSON**: `serde` and `serde_json` |
| 17 | +- **Database**: `rusqlite` with bundled SQLite |
| 18 | +- **Networking**: `hickory-resolver` for DNS resolution |
| 19 | + |
| 20 | +## Project Structure |
| 21 | + |
| 22 | +``` |
| 23 | +src/ |
| 24 | +├── lib.rs # Main library with CLI definitions and core logic |
| 25 | +├── main.rs # Binary entry point |
| 26 | +├── client.rs # HTTP client implementations (HTTP/1, HTTP/2) |
| 27 | +├── client_h3.rs # HTTP/3 client (feature-gated) |
| 28 | +├── aws_auth.rs # AWS signature authentication |
| 29 | +├── db.rs # Database operations for storing results |
| 30 | +├── histogram.rs # Statistical histogram implementation |
| 31 | +├── monitor.rs # Real-time monitoring and TUI |
| 32 | +├── printer.rs # Output formatting and display |
| 33 | +├── result_data.rs # Data structures for test results |
| 34 | +├── timescale.rs # Time-based scaling utilities |
| 35 | +├── tls_config.rs # TLS configuration |
| 36 | +├── url_generator.rs # URL generation with patterns |
| 37 | +└── pcg64si.rs # Random number generation |
| 38 | +``` |
| 39 | + |
| 40 | +## Features & Build Configurations |
| 41 | + |
| 42 | +### Default Features |
| 43 | +- `rustls` - Uses rustls for TLS (default) |
| 44 | + |
| 45 | +### Optional Features |
| 46 | +- `native-tls` - Use native TLS instead of rustls |
| 47 | +- `vsock` - Enable VSOCK support for VM communication |
| 48 | +- `http3` - Experimental HTTP/3 support via `h3` library |
| 49 | + |
| 50 | +### Build Examples |
| 51 | +```bash |
| 52 | +# Default build with rustls |
| 53 | +cargo build |
| 54 | + |
| 55 | +# With native TLS |
| 56 | +cargo build --no-default-features --features native-tls |
| 57 | + |
| 58 | +# With HTTP/3 support |
| 59 | +cargo build --features http3 |
| 60 | + |
| 61 | +# With VSOCK support |
| 62 | +cargo build --features vsock |
| 63 | +``` |
| 64 | + |
| 65 | +## Code Style & Conventions |
| 66 | + |
| 67 | +### Error Handling |
| 68 | +- Use `anyhow::Result<T>` for functions that can fail |
| 69 | +- Use `anyhow::bail!()` for early returns with error messages |
| 70 | +- Use `anyhow::ensure!()` for validation with custom error messages |
| 71 | +- Use `thiserror` for custom error types (when needed) |
| 72 | + |
| 73 | +### Async Code |
| 74 | +- All async code uses `tokio` |
| 75 | +- Use `tokio::spawn` for concurrent tasks |
| 76 | +- Prefer `async/await` over manual future polling |
| 77 | + |
| 78 | +### CLI Structure |
| 79 | +- Use `clap` derive macros for argument parsing |
| 80 | +- Main configuration struct is typically in `lib.rs` |
| 81 | +- Support both short and long argument forms |
| 82 | + |
| 83 | +### TUI Guidelines |
| 84 | +- Use `ratatui` for all terminal UI components |
| 85 | +- Handle terminal resize events |
| 86 | +- Implement proper cleanup on exit |
| 87 | +- Use `crossterm` for terminal control |
| 88 | + |
| 89 | +### HTTP Client Patterns |
| 90 | +- Support HTTP/1.1, HTTP/2, and optionally HTTP/3 |
| 91 | +- Handle connection pooling and reuse |
| 92 | +- Implement proper timeout handling |
| 93 | +- Support custom headers and authentication |
| 94 | + |
| 95 | +### Performance Considerations |
| 96 | +- Use `jemalloc` allocator for better memory performance |
| 97 | +- Leverage `tokio`'s async runtime efficiently |
| 98 | +- Minimize allocations in hot paths |
| 99 | +- Use streaming where appropriate for large responses |
| 100 | +- Use PCG64SI PRNG (`pcg64si.rs`) for high-performance random number generation |
| 101 | + |
| 102 | +## Testing |
| 103 | + |
| 104 | +### Test Structure |
| 105 | +- Integration tests in `tests/` directory |
| 106 | +- Use `assert_cmd` for CLI testing |
| 107 | +- Test server setup with `axum` and `axum-server` |
| 108 | +- SSL/TLS testing with provided certificates |
| 109 | + |
| 110 | +### Test Data |
| 111 | +- Test certificates: `tests/common/server.cert` and `tests/common/server.key` |
| 112 | +- Common test utilities in `tests/common/mod.rs` |
| 113 | + |
| 114 | +## Development Guidelines |
| 115 | + |
| 116 | +1. **Cross-platform**: Ensure code works on Linux, macOS, and Windows |
| 117 | +2. **Feature gates**: Use appropriate feature gates for optional dependencies |
| 118 | +3. **Documentation**: Document public APIs with rustdoc comments |
| 119 | +4. **Performance**: Profile and optimize hot paths |
| 120 | +5. **Error messages**: Provide helpful, actionable error messages |
| 121 | +6. **CLI UX**: Follow Unix conventions for command-line tools |
| 122 | + |
| 123 | +## Dependencies to Prefer |
| 124 | + |
| 125 | +- **HTTP**: `hyper` and `hyper-util` for HTTP client functionality |
| 126 | +- **TLS**: `rustls` by default, `native-tls` as fallback |
| 127 | +- **Async**: `tokio` ecosystem (`tokio-util`, `tokio-rustls`, etc.) |
| 128 | +- **CLI**: `clap` for argument parsing |
| 129 | +- **Serialization**: `serde` ecosystem |
| 130 | +- **Random**: `rand` and `rand_core` for randomization needs |
| 131 | +- **Time**: `chrono` for time handling |
| 132 | + |
| 133 | +## Platform-specific Code |
| 134 | + |
| 135 | +- Use `#[cfg(unix)]` for Unix-specific features (like `rlimit`) |
| 136 | +- Use `#[cfg(not(target_env = "msvc"))]` for non-MSVC Windows builds |
| 137 | +- Handle platform differences in TLS and networking code appropriately |
0 commit comments