feat(smart-proxy): add UDP transport support with QUIC/HTTP3 routing and datagram handler relay

This commit is contained in:
2026-03-19 15:06:27 +00:00
parent cfa958cf3d
commit 4fb91cd868
34 changed files with 2978 additions and 55 deletions

View File

@@ -26,6 +26,11 @@ pub struct Metrics {
pub total_http_requests: u64,
pub http_requests_per_sec: u64,
pub http_requests_per_sec_recent: u64,
// UDP metrics
pub active_udp_sessions: u64,
pub total_udp_sessions: u64,
pub total_datagrams_in: u64,
pub total_datagrams_out: u64,
}
/// Per-route metrics.
@@ -136,6 +141,12 @@ pub struct MetricsCollector {
pending_http_requests: AtomicU64,
http_request_throughput: Mutex<ThroughputTracker>,
// ── UDP metrics ──
active_udp_sessions: AtomicU64,
total_udp_sessions: AtomicU64,
total_datagrams_in: AtomicU64,
total_datagrams_out: AtomicU64,
// ── Lock-free pending throughput counters (hot path) ──
global_pending_tp_in: AtomicU64,
global_pending_tp_out: AtomicU64,
@@ -180,6 +191,10 @@ impl MetricsCollector {
backend_pool_hits: DashMap::new(),
backend_pool_misses: DashMap::new(),
backend_h2_failures: DashMap::new(),
active_udp_sessions: AtomicU64::new(0),
total_udp_sessions: AtomicU64::new(0),
total_datagrams_in: AtomicU64::new(0),
total_datagrams_out: AtomicU64::new(0),
total_http_requests: AtomicU64::new(0),
pending_http_requests: AtomicU64::new(0),
http_request_throughput: Mutex::new(ThroughputTracker::new(retention_seconds)),
@@ -350,6 +365,29 @@ impl MetricsCollector {
self.pending_http_requests.fetch_add(1, Ordering::Relaxed);
}
// ── UDP session recording methods ──
/// Record a new UDP session opened.
pub fn udp_session_opened(&self) {
self.active_udp_sessions.fetch_add(1, Ordering::Relaxed);
self.total_udp_sessions.fetch_add(1, Ordering::Relaxed);
}
/// Record a UDP session closed.
pub fn udp_session_closed(&self) {
self.active_udp_sessions.fetch_sub(1, Ordering::Relaxed);
}
/// Record a UDP datagram (inbound or outbound).
pub fn record_datagram_in(&self) {
self.total_datagrams_in.fetch_add(1, Ordering::Relaxed);
}
/// Record an outbound UDP datagram.
pub fn record_datagram_out(&self) {
self.total_datagrams_out.fetch_add(1, Ordering::Relaxed);
}
// ── Per-backend recording methods ──
/// Record a successful backend connection with its connect duration.
@@ -769,6 +807,10 @@ impl MetricsCollector {
total_http_requests: self.total_http_requests.load(Ordering::Relaxed),
http_requests_per_sec: http_rps,
http_requests_per_sec_recent: http_rps_recent,
active_udp_sessions: self.active_udp_sessions.load(Ordering::Relaxed),
total_udp_sessions: self.total_udp_sessions.load(Ordering::Relaxed),
total_datagrams_in: self.total_datagrams_in.load(Ordering::Relaxed),
total_datagrams_out: self.total_datagrams_out.load(Ordering::Relaxed),
}
}
}