Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions linkerd/app/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,10 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
OUTBOUND_CONNECT_BASE,
DEFAULT_OUTBOUND_CONNECT_BACKOFF,
)?,
http2: h2::ClientParams {
flow_control: Some(h2::FlowControl::Fixed {
initial_stream_window_size,
initial_connection_window_size,
}),
..Default::default()
},
http2: http2::parse_client(
strings,
"LINKERD2_PROXY_OUTBOUND_CONNECT_HTTP2",
)?,
http1: h1::PoolSettings {
max_idle,
idle_timeout: connection_pool_timeout
Expand Down Expand Up @@ -634,13 +631,10 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
INBOUND_CONNECT_BASE,
DEFAULT_INBOUND_CONNECT_BACKOFF,
)?,
http2: h2::ClientParams {
flow_control: Some(h2::FlowControl::Fixed {
initial_stream_window_size,
initial_connection_window_size,
}),
..Default::default()
},
http2: http2::parse_client(
strings,
"LINKERD2_PROXY_INBOUND_CONNECT_HTTP2",
)?,
http1: h1::PoolSettings {
max_idle,
idle_timeout: connection_pool_timeout,
Expand Down
95 changes: 94 additions & 1 deletion linkerd/app/src/env/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ pub(super) fn parse_server<S: Strings>(
})
}

pub(super) fn parse_client<S: Strings>(
strings: &S,
base: &str,
) -> Result<h2::ClientParams, EnvError> {
Ok(h2::ClientParams {
flow_control: Some(parse_flow_control(strings, base)?),
keep_alive: parse_client_keep_alive(strings, &format!("{base}_KEEP_ALIVE"))?,
max_concurrent_reset_streams: parse(
strings,
&format!("{base}_MAX_CONCURRENT_RESET_STREAMS"),
parse_number,
)?,
max_frame_size: parse(strings, &format!("{base}_MAX_FRAME_SIZE"), parse_number)?,
max_header_list_size: parse(
strings,
&format!("{base}_MAX_HEADER_LIST_SIZE"),
parse_number,
)?,
max_send_buf_size: parse(strings, &format!("{base}_MAX_SEND_BUF_SIZE"), parse_number)?,
})
}

fn parse_flow_control<S: Strings>(strings: &S, base: &str) -> Result<h2::FlowControl, EnvError> {
if let Some(true) = parse(
strings,
Expand Down Expand Up @@ -77,6 +99,25 @@ fn parse_keep_alive<S: Strings>(
Ok(None)
}

fn parse_client_keep_alive<S: Strings>(
strings: &S,
base: &str,
) -> Result<Option<h2::ClientKeepAlive>, EnvError> {
if let (Some(timeout), Some(interval)) = (
parse(strings, &format!("{base}_TIMEOUT"), parse_duration)?,
parse(strings, &format!("{base}_INTERVAL"), parse_duration)?,
) {
let while_idle = parse(
strings,
&format!("{base}_WHILE_IDLE"),
parse_bool,
)?.unwrap_or(false);
return Ok(Some(h2::ClientKeepAlive { interval, timeout, while_idle }));
}

Ok(None)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -147,4 +188,56 @@ mod tests {
}
);
}
}

#[test]
fn client_params() {
let mut env = HashMap::default();

// Produces empty params if no relevant env vars are set.
let default = h2::ClientParams {
flow_control: Some(h2::FlowControl::Fixed {
initial_stream_window_size: super::super::DEFAULT_INITIAL_STREAM_WINDOW_SIZE,
initial_connection_window_size:
super::super::DEFAULT_INITIAL_CONNECTION_WINDOW_SIZE,
}),
..Default::default()
};
assert_eq!(parse_client(&env, "TEST").unwrap(), default);

// Set all the fields.
env.insert("TEST_MAX_FRAME_SIZE", "4");
env.insert("TEST_MAX_HEADER_LIST_SIZE", "5");
env.insert("TEST_MAX_SEND_BUF_SIZE", "7");
env.insert("TEST_KEEP_ALIVE_TIMEOUT", "1s");
env.insert("TEST_KEEP_ALIVE_INTERVAL", "2s");
env.insert("TEST_KEEP_ALIVE_WHILE_IDLE", "true");
env.insert("TEST_INITIAL_STREAM_WINDOW_SIZE", "1");
env.insert("TEST_INITIAL_CONNECTION_WINDOW_SIZE", "2");
let expected = h2::ClientParams {
flow_control: Some(h2::FlowControl::Fixed {
initial_stream_window_size: 1,
initial_connection_window_size: 2,
}),
keep_alive: Some(h2::ClientKeepAlive {
interval: Duration::from_secs(2),
timeout: Duration::from_secs(1),
while_idle: true,
}),
max_frame_size: Some(4),
max_header_list_size: Some(5),
max_send_buf_size: Some(7),
..Default::default()
};
assert_eq!(parse_client(&env, "TEST").unwrap(), expected);

// Enable adaptive flow control, overriding other flow control settings.
env.insert("TEST_ADAPTIVE_FLOW_CONTROL", "true");
assert_eq!(
parse_client(&env, "TEST").unwrap(),
h2::ClientParams {
flow_control: Some(h2::FlowControl::Adaptive),
..expected.clone()
}
);
}
}
4 changes: 4 additions & 0 deletions linkerd/http/h2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct ClientParams {
pub max_concurrent_reset_streams: Option<usize>,
pub max_frame_size: Option<u32>,
pub max_send_buf_size: Option<usize>,
pub max_header_list_size: Option<u32>,
}

#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -58,6 +59,9 @@ impl ClientParams {
.or(self.max_concurrent_reset_streams),
max_frame_size: overrides.max_frame_size.or(self.max_frame_size),
max_send_buf_size: overrides.max_send_buf_size.or(self.max_send_buf_size),
max_header_list_size: overrides
.max_header_list_size
.or(self.max_header_list_size),
}
}
}
4 changes: 4 additions & 0 deletions linkerd/proxy/http/src/h2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ where
max_concurrent_reset_streams,
max_frame_size,
max_send_buf_size,
max_header_list_size,
} = self.params;

let connect = self
Expand Down Expand Up @@ -122,6 +123,9 @@ where
if let Some(sz) = max_send_buf_size {
builder.max_send_buf_size(sz);
}
if let Some(sz) = max_header_list_size {
builder.max_header_list_size(sz);
}

let (tx, conn) = builder
.handshake(hyper_util::rt::TokioIo::new(io))
Expand Down