Skip to content

Commit d2046b5

Browse files
committed
chore(http): split h2 client and server config
Hyper supports a variety of configuration options for for the HTTP/2 client and servers. The proxy's http client and server types do not support modifying these parameters. We want to support configuring HTTP/2 server and client keep-alives; and if we are exposing these parameters to the control plane, it also makes sense to include the others, especially the per-connection stream concurrency limit and the initial window sizes. This commit splits the h2 'Settings' type into 'ClientParams' and 'ServerParams', including the appropriate per-connection settings for each. These parameters are wired into the hyper client and server builders. These parameters are not yet exposed to the control plane via configuration interfaces.
1 parent 5268124 commit d2046b5

File tree

17 files changed

+216
-96
lines changed

17 files changed

+216
-96
lines changed

linkerd/app/admin/src/stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Config {
128128
move |t: &Http| {
129129
http::ServerParams {
130130
version: t.version,
131-
h2: Default::default(),
131+
http2: Default::default(),
132132
drain: drain.clone(),
133133
}
134134
}

linkerd/app/core/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ use std::time::Duration;
1010
pub struct ServerConfig {
1111
pub addr: DualListenAddr,
1212
pub keepalive: Keepalive,
13-
pub h2_settings: h2::Settings,
13+
pub http2: h2::ServerParams,
1414
}
1515

1616
#[derive(Clone, Debug)]
1717
pub struct ConnectConfig {
1818
pub backoff: ExponentialBackoff,
1919
pub timeout: Duration,
2020
pub keepalive: Keepalive,
21-
pub h1_settings: h1::PoolSettings,
22-
pub h2_settings: h2::Settings,
21+
pub http1: h1::PoolSettings,
22+
pub http2: h2::ClientParams,
2323
}
2424

2525
#[derive(Clone, Debug)]

linkerd/app/core/src/control.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Config {
128128
.push(tls::Client::layer(identity))
129129
.push_connect_timeout(self.connect.timeout)
130130
.push_map_target(|(_version, target)| target)
131-
.push(self::client::layer(self.connect.h2_settings))
131+
.push(self::client::layer(self.connect.http2))
132132
.push_on_service(svc::MapErr::layer_boxed())
133133
.into_new_service();
134134

@@ -330,7 +330,6 @@ mod client {
330330
svc, tls,
331331
transport::{Remote, ServerAddr},
332332
};
333-
use linkerd_proxy_http::h2::Settings as H2Settings;
334333
use std::net::SocketAddr;
335334

336335
#[derive(Clone, Hash, Debug, Eq, PartialEq)]
@@ -368,11 +367,11 @@ mod client {
368367
// === impl Layer ===
369368

370369
pub fn layer<C, B>(
371-
settings: H2Settings,
372-
) -> impl svc::Layer<C, Service = http::h2::Connect<C, B>> + Copy
370+
h2: http::h2::ClientParams,
371+
) -> impl svc::Layer<C, Service = http::h2::Connect<C, B>> + Clone
373372
where
374373
http::h2::Connect<C, B>: tower::Service<Target>,
375374
{
376-
svc::layer::mk(move |mk_conn| http::h2::Connect::new(mk_conn, settings))
375+
svc::layer::mk(move |mk_conn| http::h2::Connect::new(mk_conn, h2.clone()))
377376
}
378377
}

linkerd/app/inbound/src/http/router.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ impl<C> Inbound<C> {
9494
.check_service::<Http>()
9595
.push_map_target(|(_version, target)| target)
9696
.push(http::client::layer(
97-
config.proxy.connect.h1_settings,
98-
config.proxy.connect.h2_settings,
97+
config.proxy.connect.http1,
98+
config.proxy.connect.http2.clone(),
9999
))
100100
.check_service::<Http>()
101101
.push_on_service(svc::MapErr::layer_boxed())

linkerd/app/inbound/src/http/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ impl<H> Inbound<H> {
112112
HSvc::Future: Send,
113113
{
114114
self.map_stack(|config, rt, http| {
115-
let h2 = config.proxy.server.h2_settings;
115+
let h2 = config.proxy.server.http2.clone();
116116
let drain = rt.drain.clone();
117117

118118
http.check_new_service::<T, http::Request<http::BoxBody>>()
119119
.unlift_new()
120120
.check_new_new_service::<T, http::ClientHandle, http::Request<_>>()
121121
.push(http::NewServeHttp::layer(move |t: &T| http::ServerParams {
122122
version: t.param(),
123-
h2,
123+
http2: h2.clone(),
124124
drain: drain.clone(),
125125
}))
126126
.check_new_service::<T, I>()

linkerd/app/inbound/src/test_util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn default_config() -> Config {
5959
server: config::ServerConfig {
6060
addr: DualListenAddr(([0, 0, 0, 0], 0).into(), None),
6161
keepalive: Keepalive(None),
62-
h2_settings: h2::Settings::default(),
62+
http2: h2::ServerParams::default(),
6363
},
6464
connect: config::ConnectConfig {
6565
keepalive: Keepalive(None),
@@ -70,11 +70,11 @@ pub fn default_config() -> Config {
7070
0.1,
7171
)
7272
.unwrap(),
73-
h1_settings: h1::PoolSettings {
73+
http1: h1::PoolSettings {
7474
max_idle: 1,
7575
idle_timeout: Duration::from_secs(1),
7676
},
77-
h2_settings: h2::Settings::default(),
77+
http2: h2::ClientParams::default(),
7878
},
7979
max_in_flight_requests: 10_000,
8080
detect_protocol_timeout: Duration::from_secs(10),

linkerd/app/outbound/src/http/endpoint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ impl<C> Outbound<C> {
5454
{
5555
self.map_stack(|config, _, inner| {
5656
let config::ConnectConfig {
57-
h1_settings,
58-
h2_settings,
57+
http1: h1_settings,
58+
http2: ref h2_settings,
5959
..
6060
} = config.proxy.connect;
6161

@@ -65,7 +65,7 @@ impl<C> Outbound<C> {
6565
svc::stack(inner.into_inner().into_service())
6666
.check_service::<Connect<T>>()
6767
.push_map_target(|(version, inner)| Connect { version, inner })
68-
.push(http::client::layer(h1_settings, h2_settings))
68+
.push(http::client::layer(h1_settings, h2_settings.clone()))
6969
.push_on_service(svc::MapErr::layer_boxed())
7070
.check_service::<T>()
7171
.into_new_service()

linkerd/app/outbound/src/http/server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(crate) struct ServerRescue {
99

1010
#[derive(Clone, Debug)]
1111
pub struct ExtractServerParams {
12-
h2: http::h2::Settings,
12+
h2: http::h2::ServerParams,
1313
drain: drain::Watch,
1414
}
1515

@@ -86,7 +86,7 @@ impl<N> Outbound<N> {
8686
http.unlift_new()
8787
.push(svc::ArcNewService::layer())
8888
.push(http::NewServeHttp::layer(ExtractServerParams {
89-
h2: config.proxy.server.h2_settings,
89+
h2: config.proxy.server.http2.clone(),
9090
drain: rt.drain.clone(),
9191
}))
9292
})
@@ -194,7 +194,7 @@ where
194194
fn extract_param(&self, t: &T) -> http::ServerParams {
195195
http::ServerParams {
196196
version: t.param(),
197-
h2: self.h2,
197+
http2: self.h2.clone(),
198198
drain: self.drain.clone(),
199199
}
200200
}

linkerd/app/outbound/src/ingress.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@ impl<N> Outbound<N> {
301301
http.check_new_service::<Http<T>, http::Request<_>>()
302302
.unlift_new()
303303
.push(http::NewServeHttp::layer({
304-
let h2 = config.proxy.server.h2_settings;
304+
let h2 = config.proxy.server.http2.clone();
305305
let drain = rt.drain.clone();
306306
move |http: &Http<T>| http::ServerParams {
307307
version: http.version,
308-
h2,
308+
http2: h2.clone(),
309309
drain: drain.clone()
310310
}
311311
}))

linkerd/app/outbound/src/protocol.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ impl<N> Outbound<N> {
4747
let opaq = self.clone().into_stack();
4848

4949
let http = self.with_stack(http).map_stack(|config, rt, stk| {
50-
let h2 = config.proxy.server.h2_settings;
50+
let h2 = config.proxy.server.http2.clone();
5151
let drain = rt.drain.clone();
5252
stk.unlift_new()
5353
.push(http::NewServeHttp::layer(move |t: &Http<T>| {
5454
http::ServerParams {
5555
version: t.version,
56-
h2,
56+
http2: h2.clone(),
5757
drain: drain.clone(),
5858
}
5959
}))

linkerd/app/outbound/src/test_util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn default_config() -> Config {
2626
server: config::ServerConfig {
2727
addr: DualListenAddr(([0, 0, 0, 0], 0).into(), None),
2828
keepalive: Keepalive(None),
29-
h2_settings: h2::Settings::default(),
29+
http2: h2::ServerParams::default(),
3030
},
3131
connect: config::ConnectConfig {
3232
keepalive: Keepalive(None),
@@ -37,11 +37,11 @@ pub(crate) fn default_config() -> Config {
3737
0.1,
3838
)
3939
.unwrap(),
40-
h1_settings: h1::PoolSettings {
40+
http1: h1::PoolSettings {
4141
max_idle: 1,
4242
idle_timeout: Duration::from_secs(1),
4343
},
44-
h2_settings: h2::Settings::default(),
44+
http2: h2::ClientParams::default(),
4545
},
4646
max_in_flight_requests: 10_000,
4747
detect_protocol_timeout: Duration::from_secs(3),

linkerd/app/src/env.rs

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -425,21 +425,13 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
425425
);
426426
let dst_profile_networks = parse(strings, ENV_DESTINATION_PROFILE_NETWORKS, parse_networks);
427427

428-
let initial_stream_window_size = parse(strings, ENV_INITIAL_STREAM_WINDOW_SIZE, parse_number);
429-
let initial_connection_window_size =
430-
parse(strings, ENV_INITIAL_CONNECTION_WINDOW_SIZE, parse_number);
431-
432428
let tap = parse_tap_config(strings);
433429

434-
let h2_settings = h2::Settings {
435-
initial_stream_window_size: Some(
436-
initial_stream_window_size?.unwrap_or(DEFAULT_INITIAL_STREAM_WINDOW_SIZE),
437-
),
438-
initial_connection_window_size: Some(
439-
initial_connection_window_size?.unwrap_or(DEFAULT_INITIAL_CONNECTION_WINDOW_SIZE),
440-
),
441-
..Default::default()
442-
};
430+
let initial_stream_window_size = parse(strings, ENV_INITIAL_STREAM_WINDOW_SIZE, parse_number)?
431+
.unwrap_or(DEFAULT_INITIAL_STREAM_WINDOW_SIZE);
432+
let initial_connection_window_size =
433+
parse(strings, ENV_INITIAL_CONNECTION_WINDOW_SIZE, parse_number)?
434+
.unwrap_or(DEFAULT_INITIAL_CONNECTION_WINDOW_SIZE);
443435

444436
let dst_profile_suffixes = dst_profile_suffixes?
445437
.unwrap_or_else(|| parse_dns_suffixes(DEFAULT_DESTINATION_PROFILE_SUFFIXES).unwrap());
@@ -481,7 +473,13 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
481473
let server = ServerConfig {
482474
addr,
483475
keepalive,
484-
h2_settings,
476+
http2: h2::ServerParams {
477+
flow_control: Some(h2::FlowControl::Fixed {
478+
initial_stream_window_size,
479+
initial_connection_window_size,
480+
}),
481+
..Default::default()
482+
},
485483
};
486484
let discovery_idle_timeout =
487485
outbound_discovery_idle_timeout?.unwrap_or(DEFAULT_OUTBOUND_DISCOVERY_IDLE_TIMEOUT);
@@ -502,8 +500,14 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
502500
OUTBOUND_CONNECT_BASE,
503501
DEFAULT_OUTBOUND_CONNECT_BACKOFF,
504502
)?,
505-
h2_settings,
506-
h1_settings: h1::PoolSettings {
503+
http2: h2::ClientParams {
504+
flow_control: Some(h2::FlowControl::Fixed {
505+
initial_stream_window_size,
506+
initial_connection_window_size,
507+
}),
508+
..Default::default()
509+
},
510+
http1: h1::PoolSettings {
507511
max_idle,
508512
idle_timeout: connection_pool_timeout
509513
.unwrap_or(DEFAULT_OUTBOUND_HTTP1_CONNECTION_POOL_IDLE_TIMEOUT),
@@ -563,7 +567,13 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
563567
let server = ServerConfig {
564568
addr,
565569
keepalive,
566-
h2_settings,
570+
http2: h2::ServerParams {
571+
flow_control: Some(h2::FlowControl::Fixed {
572+
initial_stream_window_size,
573+
initial_connection_window_size,
574+
}),
575+
..Default::default()
576+
},
567577
};
568578
let discovery_idle_timeout =
569579
inbound_discovery_idle_timeout?.unwrap_or(DEFAULT_INBOUND_DISCOVERY_IDLE_TIMEOUT);
@@ -584,8 +594,14 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
584594
INBOUND_CONNECT_BASE,
585595
DEFAULT_INBOUND_CONNECT_BACKOFF,
586596
)?,
587-
h2_settings,
588-
h1_settings: h1::PoolSettings {
597+
http2: h2::ClientParams {
598+
flow_control: Some(h2::FlowControl::Fixed {
599+
initial_stream_window_size,
600+
initial_connection_window_size,
601+
}),
602+
..Default::default()
603+
},
604+
http1: h1::PoolSettings {
589605
max_idle,
590606
idle_timeout: connection_pool_timeout,
591607
},
@@ -758,7 +774,13 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
758774
server: ServerConfig {
759775
addr: DualListenAddr(admin_listener_addr, None),
760776
keepalive: inbound.proxy.server.keepalive,
761-
h2_settings,
777+
http2: h2::ServerParams {
778+
flow_control: Some(h2::FlowControl::Fixed {
779+
initial_stream_window_size,
780+
initial_connection_window_size,
781+
}),
782+
..Default::default()
783+
},
762784
},
763785

764786
// TODO(ver) Currently we always enable profiling when the pprof feature
@@ -817,7 +839,13 @@ pub fn parse_config<S: Strings>(strings: &S) -> Result<super::Config, EnvError>
817839
config: ServerConfig {
818840
addr: DualListenAddr(addr, None),
819841
keepalive: inbound.proxy.server.keepalive,
820-
h2_settings,
842+
http2: h2::ServerParams {
843+
flow_control: Some(h2::FlowControl::Fixed {
844+
initial_stream_window_size,
845+
initial_connection_window_size,
846+
}),
847+
..Default::default()
848+
},
821849
},
822850
})
823851
.unwrap_or(super::tap::Config::Disabled);

linkerd/app/src/tap.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::{collections::HashSet, pin::Pin};
1313
use tower::util::{service_fn, ServiceExt};
1414

1515
#[derive(Clone, Debug)]
16+
#[allow(clippy::large_enum_variant)]
1617
pub enum Config {
1718
Disabled,
1819
Enabled {

0 commit comments

Comments
 (0)