-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance vts_zone directive with proper implementation and documentation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add foundational VTS (Virtual Host Traffic Status) node implementation similar to the original nginx-module-vts: ## New Features: - **VtsNodeStats**: Comprehensive traffic statistics structure - Request counts and timing metrics - Status code distribution (1xx-5xx) - Bytes in/out tracking - First/last request timestamps - **VtsStatsManager**: Statistics management system - Per-server zone tracking - In-memory storage (prepared for shared memory upgrade) - Thread-safe operations ready - **VTS Configuration**: Module directives - `vts_status` - Enable status endpoint - `vts_zone` - Configure shared memory zone (placeholder) ## Architecture Design: - Modular structure ready for shared memory integration - Red-black tree and slab allocator patterns researched - Compatible with original nginx-module-vts node system - Prepared for ngx-rust shared memory APIs ## Implementation Status: - ✅ Core statistics data structure - ✅ Basic statistics collection - ✅ Module configuration framework - 🔄 Shared memory integration (next phase) - 🔄 Request tracking hooks (next phase) This provides the foundation for efficient, persistent virtual host traffic monitoring with nginx's shared memory system. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Implement proper parsing of zone name and size parameters for vts_zone directive - Add support for size units (k/K, m/M, g/G) with proper validation - Add comprehensive error handling for invalid configurations - Update README.md with detailed vts_zone directive documentation - Add shared memory zone initialization callback - Include unit tests for size parsing functionality - Improve configuration examples and architecture documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Apply cargo fmt to resolve CI formatting check failures. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add #[allow(dead_code)] annotations for unused structs and methods - Remove unnecessary type casts (usize -> usize) - Replace or_insert_with with or_default() for better performance - Use &raw const for mutable static reference to fix safety warning - Ensure all clippy warnings are resolved for CI compliance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request implements a comprehensive vts_zone directive for the nginx-module-vts Rust implementation, adding proper shared memory configuration capabilities. The changes establish the foundation for traffic statistics collection by enabling zone name and size parsing with support for standard memory units.
- Enhanced the
vts_zonedirective implementation with proper argument parsing and validation - Added a new VTS node system for statistics data structures and management
- Updated documentation with detailed directive usage and configuration examples
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/vts_node.rs |
Introduces VTS statistics data structures and a temporary in-memory stats manager |
src/lib.rs |
Implements vts_zone directive parsing, shared memory zone creation, and size unit parsing |
README.md |
Updates documentation with vts_zone directive details and enhanced configuration examples |
Comments suppressed due to low confidence (1)
src/lib.rs:184
- [nitpick] The error message should be consistent with nginx's standard error message format. Consider using "takes" instead of "requires" to match nginx's typical phrasing: "vts_zone directive takes exactly 2 arguments: zone_name and size".
let error_msg = "vts_zone directive requires exactly 2 arguments: zone_name and size\0";
| } | ||
|
|
||
| // Update timestamps | ||
| let current_time = ngx_time() as u64; |
Copilot
AI
Jul 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ngx_time() function is called without proper safety checks. This is an unsafe FFI call that should be wrapped in an unsafe block, and the function should verify that nginx's time system is properly initialized.
|
|
||
| /// Simple VTS statistics manager (without shared memory for now) | ||
| /// | ||
| /// This will be replaced with shared memory implementation later |
Copilot
AI
Jul 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment indicates this is a temporary implementation that will be replaced. Consider adding a TODO or FIXME annotation to make this more explicit for future development: /// TODO: Replace with shared memory implementation.
| /// This will be replaced with shared memory implementation later | |
| /// TODO: Replace with shared memory implementation |
|
|
||
| let num: usize = num_str.parse().map_err(|_| "Invalid number")?; | ||
|
|
||
| num.checked_mul(multiplier).ok_or("Size overflow") |
Copilot
AI
Jul 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number multipliers (1024, 1024*1024, etc.) should be defined as named constants for better maintainability. Consider defining const KILOBYTE: usize = 1024;, const MEGABYTE: usize = 1024 * 1024;, etc.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
vts_zonedirective with zone name and size parsingChanges Made
Core Implementation (
src/lib.rs)ngx_http_set_vts_zonefunction to properly parse directive argumentsparse_size_stringhelper function supporting k/m/g size unitsvts_init_shm_zonecallback for shared memory initializationDocumentation (
README.md)vts_zonedirective documentation with parameters and examplesvts_zone main 10musageKey Features
Test Plan
parse_size_stringfunction passConfiguration Example
This enhancement provides a solid foundation for nginx-module-vts functionality with proper documentation and robust configuration handling.
🤖 Generated with Claude Code