fix(rustproxy-http): report streamed HTTP and WebSocket bytes per chunk for real-time throughput metrics

This commit is contained in:
2026-03-15 21:44:32 +00:00
parent 211d5cf835
commit aa9e6dfd94
4 changed files with 27 additions and 37 deletions

View File

@@ -1919,6 +1919,9 @@ impl HttpProxyService {
let conn_act_u2c = conn_activity.as_ref().map(|ca| (Arc::clone(&ca.last_activity), ca.start));
let la1 = Arc::clone(&last_activity);
let metrics_c2u = Arc::clone(&metrics);
let route_c2u = route_id_owned.clone();
let ip_c2u = source_ip_owned.clone();
let c2u = tokio::spawn(async move {
let mut buf = vec![0u8; 65536];
let mut total = 0u64;
@@ -1931,6 +1934,7 @@ impl HttpProxyService {
break;
}
total += n as u64;
metrics_c2u.record_bytes(n as u64, 0, route_c2u.as_deref(), Some(&ip_c2u));
la1.store(start.elapsed().as_millis() as u64, Ordering::Relaxed);
if let Some((ref ca, ca_start)) = conn_act_c2u {
ca.store(ca_start.elapsed().as_millis() as u64, Ordering::Relaxed);
@@ -1941,6 +1945,9 @@ impl HttpProxyService {
});
let la2 = Arc::clone(&last_activity);
let metrics_u2c = Arc::clone(&metrics);
let route_u2c = route_id_owned.clone();
let ip_u2c = source_ip_owned.clone();
let u2c = tokio::spawn(async move {
let mut buf = vec![0u8; 65536];
let mut total = 0u64;
@@ -1953,6 +1960,7 @@ impl HttpProxyService {
break;
}
total += n as u64;
metrics_u2c.record_bytes(0, n as u64, route_u2c.as_deref(), Some(&ip_u2c));
la2.store(start.elapsed().as_millis() as u64, Ordering::Relaxed);
if let Some((ref ca, ca_start)) = conn_act_u2c {
ca.store(ca_start.elapsed().as_millis() as u64, Ordering::Relaxed);
@@ -2013,9 +2021,7 @@ impl HttpProxyService {
debug!("WebSocket tunnel closed: {} bytes in, {} bytes out", bytes_in, bytes_out);
upstream_selector.connection_ended(&upstream_key_owned);
if let Some(ref rid) = route_id_owned {
metrics.record_bytes(bytes_in, bytes_out, Some(rid.as_str()), Some(&source_ip_owned));
}
// Bytes already reported per-chunk in the copy loops above
});
let body: BoxBody<Bytes, hyper::Error> = BoxBody::new(