-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
The current main.rs file is 794 lines and contains all application logic in a single file. This issue tracks refactoring the codebase into a modular structure for better maintainability, testability, and code organization.
Current State
All code resides in src/main.rs:
LoadModelenum and implementation (~100 lines)- Utility functions:
parse_duration_string(),parse_headers_with_escapes()(~60 lines) - Main function with TLS config, load test logic, metrics server (~450 lines)
metrics_handler()function (~20 lines)- Unit tests (~70 lines)
Proposed Structure
src/
├── main.rs # Entry point only (~50 lines)
├── lib.rs # Module exports
├── config.rs # Config struct, env var parsing, validation
├── load_models.rs # LoadModel enum + calculate_current_rps()
├── client.rs # HTTP client builder, TLS configuration
├── metrics.rs # Prometheus metrics setup, handler, registry
├── worker.rs # Async worker task logic
└── utils.rs # parse_duration_string(), parse_headers_with_escapes()
Acceptance Criteria
- Each module has a single, clear responsibility
-
main.rscontains only entry point logic and orchestration - All existing functionality preserved (no behavioral changes)
- All existing tests pass
- Each module has appropriate visibility (
pub,pub(crate)) - Modules use explicit imports (no
use super::*) - Code compiles with no new warnings
Implementation Notes
Module Responsibilities
| Module | Contents |
|---|---|
config.rs |
Config struct, load_from_env(), validation logic |
load_models.rs |
LoadModel enum, calculate_current_rps(), phase calculations |
client.rs |
build_client(), TLS connector setup, mTLS handling |
metrics.rs |
REGISTRY, metric definitions, metrics_handler() |
worker.rs |
run_worker() async function, request loop logic |
utils.rs |
parse_duration_string(), parse_headers_with_escapes() |
Migration Steps
- Create module files with
// TODOplaceholders - Move
LoadModeland tests toload_models.rs - Move utility functions and tests to
utils.rs - Extract metrics to
metrics.rs - Extract client builder to
client.rs - Create
Configstruct inconfig.rs - Extract worker logic to
worker.rs - Update
main.rsto orchestrate modules - Run
cargo testandcargo clippy
Benefits
- Easier to navigate codebase
- Tests co-located with implementation
- Better separation of concerns
- Enables parallel development on different modules
- Improves compile times for incremental builds
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request