-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement real-time server zone statistics collection #11
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5bc4fa8
feat: implement real-time server zone statistics collection
u5surf f97c9aa
fix: resolve test race condition in integration tests
u5surf b7c40dc
fix: remove redundant unsafe in src/lib.rs
u5surf ca403d5
fix: Always calculate request time using request stat in src/ngx_vts_…
u5surf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -302,6 +302,33 @@ pub extern "C" fn vts_collect_nginx_connections() { | |||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /// Update server zone statistics from nginx request processing | ||||||||||
| /// This should be called from nginx log phase for each request | ||||||||||
| /// | ||||||||||
| /// # Safety | ||||||||||
| /// | ||||||||||
| /// The `server_name` pointer must be a valid null-terminated C string. | ||||||||||
| /// The caller must ensure the pointer remains valid for the duration of this call. | ||||||||||
| #[no_mangle] | ||||||||||
| pub unsafe extern "C" fn vts_update_server_stats_ffi( | ||||||||||
| server_name: *const c_char, | ||||||||||
| status: u16, | ||||||||||
| bytes_in: u64, | ||||||||||
| bytes_out: u64, | ||||||||||
| request_time: u64, | ||||||||||
| ) { | ||||||||||
| if server_name.is_null() { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| let server_name_str = match std::ffi::CStr::from_ptr(server_name).to_str() { | ||||||||||
| Ok(s) => s, | ||||||||||
| Err(_) => return, | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| update_server_zone_stats(server_name_str, status, bytes_in, bytes_out, request_time); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /// Update VTS statistics from nginx (to be called periodically) | ||||||||||
| /// This should be called from nginx worker process periodically to collect | ||||||||||
| /// all types of statistics including connections, server zones, and upstream data | ||||||||||
|
|
@@ -311,7 +338,7 @@ pub extern "C" fn vts_update_statistics() { | |||||||||
| vts_collect_nginx_connections(); | ||||||||||
|
|
||||||||||
| // Note: Server zone statistics are updated automatically when requests are processed | ||||||||||
| // via update_server_zone_stats() calls from nginx request processing | ||||||||||
| // via vts_update_server_stats_ffi() calls from nginx request processing | ||||||||||
|
|
||||||||||
| // Note: Upstream statistics are updated automatically when upstream requests complete | ||||||||||
| // via vts_update_upstream_stats_ffi() calls from nginx upstream processing | ||||||||||
|
|
@@ -327,7 +354,7 @@ pub extern "C" fn vts_update_statistics() { | |||||||||
| /// The returned pointer is valid until the next call to this function. | ||||||||||
| /// The caller must not free the returned pointer. | ||||||||||
| #[no_mangle] | ||||||||||
| pub extern "C" fn ngx_http_vts_get_status() -> *const c_char { | ||||||||||
| pub unsafe extern "C" fn ngx_http_vts_get_status() -> *const c_char { | ||||||||||
| use std::sync::Mutex; | ||||||||||
|
|
||||||||||
| static STATUS_CACHE: Mutex<Option<std::ffi::CString>> = Mutex::new(None); | ||||||||||
|
|
@@ -400,7 +427,8 @@ http_request_handler!(vts_status_handler, |request: &mut http::Request| { | |||||||||
| /// | ||||||||||
| /// A formatted string containing VTS status information | ||||||||||
| fn generate_vts_status_content() -> String { | ||||||||||
| // First, collect current nginx connection statistics | ||||||||||
| // Collect current nginx connection statistics only in production | ||||||||||
| #[cfg(not(test))] | ||||||||||
|
Comment on lines
+430
to
+431
|
||||||||||
| // Collect current nginx connection statistics only in production | |
| #[cfg(not(test))] | |
| #[cfg(not(test))] | |
| // Collect current nginx connection statistics only in production |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 function is already marked as
unsafe, making the innerunsafeblock redundant. Remove the inner unsafe block since the entire function body is already in an unsafe context.