Skip to content

Commit bd21b7e

Browse files
zh-jqcursoragent
andcommitted
vey-bench: wire LimitedStream for thrift tcp traffic stats
ThriftRuntimeStats already reported traffic fields; wrap connections so byte counters are actually updated and covered in CI JSON asserts. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 8e2be73 commit bd21b7e

4 files changed

Lines changed: 34 additions & 17 deletions

File tree

scripts/coverage/vey-bench/target_thrift_tcp.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ JSON_FILE="${JSON_OUT_DIR}/thrift-tcp.json"
3232
vey_bench thrift tcp --target 127.0.0.1:8888 --check-message-length 22 --binary echo ${KITEX_REQUEST} -n 3 -c 1 --json-file "${JSON_FILE}"
3333
assert_json_report "${JSON_FILE}" thrift/tcp 1 3
3434
assert_json_type "${JSON_FILE}" .connections object
35+
assert_json_tcp_traffic "${JSON_FILE}"
3536
assert_hist_snapshot "${JSON_FILE}" .histograms.conn_used_times
3637
assert_json_null "${JSON_FILE}" .histograms.durations_ns.connect
3738
assert_json_null "${JSON_FILE}" .tls

vey-bench/src/target/thrift/tcp/opts.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ use clap::{Arg, ArgAction, ArgGroup, ArgMatches, Command, value_parser};
1313
use tokio::io::{AsyncRead, AsyncReadExt};
1414
use tokio::net::TcpStream;
1515

16-
use vey_io_ext::LimitedReadExt;
16+
use vey_io_ext::{AsyncStream, LimitedReadExt, LimitedStream};
1717
use vey_types::collection::{SelectiveVec, WeightedValue};
1818
use vey_types::net::UpstreamAddr;
1919

2020
use super::header::{HeaderBuilder, KitexTTHeaderBuilder, ThriftTHeaderBuilder};
21-
use super::{MultiplexTransfer, SimplexTransfer, ThriftTcpResponse, ThriftTcpResponseError};
21+
use super::{
22+
MultiplexTransfer, SimplexTransfer, ThriftRuntimeStats, ThriftTcpResponse,
23+
ThriftTcpResponseError,
24+
};
2225
use crate::module::socket::{AppendSocketArgs, SocketArgs};
2326
use crate::opts::ProcArgs;
2427
use crate::target::thrift::{AppendThriftArgs, ThriftGlobalArgs};
@@ -82,39 +85,49 @@ impl ThriftTcpArgs {
8285

8386
pub(super) async fn new_tcp_connection(
8487
&self,
88+
stats: &Arc<ThriftRuntimeStats>,
8589
proc_args: &ProcArgs,
86-
) -> anyhow::Result<TcpStream> {
90+
) -> anyhow::Result<(LimitedStream<TcpStream>, SocketAddr)> {
8791
let addrs = self
8892
.target_addrs
8993
.as_ref()
9094
.ok_or_else(|| anyhow!("no target addr set"))?;
9195
let peer = *proc_args.select_peer(addrs);
9296

93-
self.socket.tcp_connect_to(peer).await
97+
let stream = self.socket.tcp_connect_to(peer).await?;
98+
let local_addr = stream
99+
.local_addr()
100+
.map_err(|e| anyhow!("failed to get local address: {e:?}"))?;
101+
102+
let speed_limit = &proc_args.tcp_sock_speed_limit;
103+
Ok((
104+
LimitedStream::local_limited(
105+
stream,
106+
speed_limit.shift_millis,
107+
speed_limit.max_south,
108+
speed_limit.max_north,
109+
Arc::clone(stats),
110+
),
111+
local_addr,
112+
))
94113
}
95114

96115
pub(super) async fn new_multiplex_connection(
97116
self: &Arc<Self>,
117+
stats: &Arc<ThriftRuntimeStats>,
98118
proc_args: &ProcArgs,
99119
) -> anyhow::Result<MultiplexTransfer> {
100-
let tcp_stream = self.new_tcp_connection(proc_args).await?;
101-
let local_addr = tcp_stream
102-
.local_addr()
103-
.map_err(|e| anyhow!("failed to get local address: {e:?}"))?;
104-
120+
let (tcp_stream, local_addr) = self.new_tcp_connection(stats, proc_args).await?;
105121
let (r, w) = tcp_stream.into_split();
106122
MultiplexTransfer::start(self.clone(), r, w, local_addr, self.timeout)
107123
}
108124

109125
pub(super) async fn new_simplex_connection(
110126
self: &Arc<Self>,
127+
stats: &Arc<ThriftRuntimeStats>,
111128
proc_args: &ProcArgs,
112129
) -> anyhow::Result<SimplexTransfer> {
113-
let tcp_stream = self.new_tcp_connection(proc_args).await?;
114-
let local_addr = tcp_stream
115-
.local_addr()
116-
.map_err(|e| anyhow!("failed to get local address: {e:?}"))?;
117-
130+
let (tcp_stream, local_addr) = self.new_tcp_connection(stats, proc_args).await?;
118131
let (r, w) = tcp_stream.into_split();
119132
SimplexTransfer::new(self.clone(), r, w, local_addr)
120133
}

vey-bench/src/target/thrift/tcp/pool.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ impl ThriftConnectionUnlocked {
7171
self.runtime_stats.add_conn_attempt();
7272
let handle = match tokio::time::timeout(
7373
self.args.connect_timeout,
74-
self.args.new_multiplex_connection(&self.proc_args),
74+
self.args
75+
.new_multiplex_connection(&self.runtime_stats, &self.proc_args),
7576
)
7677
.await
7778
{

vey-bench/src/target/thrift/tcp/task.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ impl ThriftTcpTaskContext {
8383
self.runtime_stats.add_conn_attempt();
8484
let handle = match tokio::time::timeout(
8585
self.args.connect_timeout,
86-
self.args.new_multiplex_connection(&self.proc_args),
86+
self.args
87+
.new_multiplex_connection(&self.runtime_stats, &self.proc_args),
8788
)
8889
.await
8990
{
@@ -115,7 +116,8 @@ impl ThriftTcpTaskContext {
115116
self.runtime_stats.add_conn_attempt();
116117
match tokio::time::timeout(
117118
self.args.connect_timeout,
118-
self.args.new_simplex_connection(&self.proc_args),
119+
self.args
120+
.new_simplex_connection(&self.runtime_stats, &self.proc_args),
119121
)
120122
.await
121123
{

0 commit comments

Comments
 (0)