-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: implement event-driven connection statistics
- Extract connection statistics into dedicated StatsManager - Add configurable stats management with StatsConfig - Implement event-based stats collection using StatEvent enum - Move connection tracking logic from ConnectionManager to StatsManager - Add comprehensive test coverage for connection lifecycle - Replace direct counter updates with async event channel - Improve error handling and logging for stats operations - Fix connection cleanup by separating stats and connection state
- Loading branch information
Showing
13 changed files
with
952 additions
and
470 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::time::Duration; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct Config { | ||
#[serde(with = "humantime_serde")] | ||
pub cleanup_interval: Duration, | ||
#[serde(with = "humantime_serde")] | ||
pub idle_timeout: Duration, | ||
#[serde(with = "humantime_serde")] | ||
pub error_timeout: Duration, | ||
pub max_events_per_second: u32, | ||
} | ||
|
||
impl Default for Config { | ||
fn default() -> Self { | ||
Self { | ||
cleanup_interval: Duration::from_secs(60), | ||
idle_timeout: Duration::from_secs(300), | ||
error_timeout: Duration::from_secs(300), | ||
max_events_per_second: 10000, | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,7 +1,26 @@ | ||
use std::time::Duration; | ||
use super::{stats::ClientStats, ConnectionStats}; | ||
use std::net::SocketAddr; | ||
use tokio::sync::oneshot; | ||
|
||
#[derive(Debug, Clone)] | ||
#[derive(Debug)] | ||
pub enum StatEvent { | ||
Request { success: bool }, | ||
ResponseTime(Duration), | ||
/// Client connected from address | ||
ClientConnected(SocketAddr), | ||
/// Client disconnected from address | ||
ClientDisconnected(SocketAddr), | ||
/// Request processed with success/failure and duration | ||
RequestProcessed { | ||
addr: SocketAddr, | ||
success: bool, | ||
duration_ms: u64, | ||
}, | ||
/// Query stats for specific address | ||
QueryStats { | ||
addr: SocketAddr, | ||
response_tx: oneshot::Sender<ClientStats>, | ||
}, | ||
/// Query global connection stats | ||
QueryConnectionStats { | ||
response_tx: oneshot::Sender<ConnectionStats>, | ||
}, | ||
} |
This file contains 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
Oops, something went wrong.