Skip to content

Commit 54407b9

Browse files
authored
chore(app/inbound): address server::conn::Http deprecations (#3432)
this addresses hyper 1.0 deprecations in the server side of the inbound proxy's http unit test suite logic. see linkerd/linkerd2#8733 for more information. the client end of this change ends up being slightly involved, due to changes that will need to be made in linkerd_app_test::http_util. accordingly, those deprecations will be addressed in a subsequent commit. --- * refactor(app/inbound): remove unused `Http` parameter this was not being flagged as an unused variable, due to the `#[instrument]` attribute. (😉 _it's used as a field in the generated span!_) `connect_timeout(..)` doesn't use its parameter. to address some deprecations, and avoid the need for polymorphism / refactoring related to http/1 and http/2 connections being represented as distinct types in the hyper 1.0 api, we remove it. Signed-off-by: katelyn martin <[email protected]> * chore(app/inbound): address `server::conn::Http` deprecations this addresses hyper 1.0 deprecations in the server side of the inbound proxy's http unit test suite logic. see <linkerd/linkerd2#8733> for more information. the client end of this change ends up being slightly involved, due to changes that will need to be made in `linkerd_app_test::http_util`. accordingly, those deprecations will be addressed in a subsequent commit. Signed-off-by: katelyn martin <[email protected]> --------- Signed-off-by: katelyn martin <[email protected]>
1 parent b1d7ded commit 54407b9

File tree

1 file changed

+36
-47
lines changed

1 file changed

+36
-47
lines changed

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

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use linkerd_app_core::{
1212
errors::respond::L5D_PROXY_ERROR,
1313
identity, io, metrics,
1414
proxy::http,
15-
svc::{self, NewService, Param},
15+
svc::{self, http::TracingExecutor, NewService, Param},
1616
tls,
1717
transport::{ClientAddr, OrigDstAddr, Remote, ServerAddr},
1818
NameAddr, ProxyRuntime,
@@ -47,9 +47,7 @@ where
4747

4848
#[tokio::test(flavor = "current_thread")]
4949
async fn unmeshed_http1_hello_world() {
50-
#[allow(deprecated)] // linkerd/linkerd2#8733
51-
let mut server = hyper::server::conn::Http::new();
52-
server.http1_only(true);
50+
let server = hyper::server::conn::http1::Builder::new();
5351
#[allow(deprecated)] // linkerd/linkerd2#8733
5452
let mut client = hyper::client::conn::Builder::new();
5553
let _trace = trace_init();
@@ -88,9 +86,7 @@ async fn unmeshed_http1_hello_world() {
8886
#[tokio::test(flavor = "current_thread")]
8987
async fn downgrade_origin_form() {
9088
// Reproduces https://github.com/linkerd/linkerd2/issues/5298
91-
#[allow(deprecated)] // linkerd/linkerd2#8733
92-
let mut server = hyper::server::conn::Http::new();
93-
server.http1_only(true);
89+
let server = hyper::server::conn::http1::Builder::new();
9490
#[allow(deprecated)] // linkerd/linkerd2#8733
9591
let mut client = hyper::client::conn::Builder::new();
9692
client.http2_only(true);
@@ -131,9 +127,7 @@ async fn downgrade_origin_form() {
131127

132128
#[tokio::test(flavor = "current_thread")]
133129
async fn downgrade_absolute_form() {
134-
#[allow(deprecated)] // linkerd/linkerd2#8733
135-
let mut server = hyper::server::conn::Http::new();
136-
server.http1_only(true);
130+
let server = hyper::server::conn::http1::Builder::new();
137131
#[allow(deprecated)] // linkerd/linkerd2#8733
138132
let mut client = hyper::client::conn::Builder::new();
139133
client.http2_only(true);
@@ -262,9 +256,7 @@ async fn http1_connect_timeout_meshed_response_error_header() {
262256

263257
// Build a mock connect that sleeps longer than the default inbound
264258
// connect timeout.
265-
#[allow(deprecated)] // linkerd/linkerd2#8733
266-
let server = hyper::server::conn::Http::new();
267-
let connect = support::connect().endpoint(Target::addr(), connect_timeout(server));
259+
let connect = support::connect().endpoint(Target::addr(), connect_timeout());
268260

269261
// Build a client using the connect that always sleeps so that responses
270262
// are GATEWAY_TIMEOUT.
@@ -309,9 +301,7 @@ async fn http1_connect_timeout_unmeshed_response_error_header() {
309301

310302
// Build a mock connect that sleeps longer than the default inbound
311303
// connect timeout.
312-
#[allow(deprecated)] // linkerd/linkerd2#8733
313-
let server = hyper::server::conn::Http::new();
314-
let connect = support::connect().endpoint(Target::addr(), connect_timeout(server));
304+
let connect = support::connect().endpoint(Target::addr(), connect_timeout());
315305

316306
// Build a client using the connect that always sleeps so that responses
317307
// are GATEWAY_TIMEOUT.
@@ -527,9 +517,7 @@ async fn grpc_response_class() {
527517

528518
// Build a mock connector serves a gRPC server that returns errors.
529519
let connect = {
530-
#[allow(deprecated)] // linkerd/linkerd2#8733
531-
let mut server = hyper::server::conn::Http::new();
532-
server.http2_only(true);
520+
let server = hyper::server::conn::http2::Builder::new(TracingExecutor);
533521
support::connect().endpoint_fn_boxed(
534522
Target::addr(),
535523
grpc_status_server(server, tonic::Code::Unknown),
@@ -606,9 +594,8 @@ async fn grpc_response_class() {
606594
}
607595

608596
#[tracing::instrument]
609-
#[allow(deprecated)] // linkerd/linkerd2#8733
610597
fn hello_server(
611-
http: hyper::server::conn::Http,
598+
server: hyper::server::conn::http1::Builder,
612599
) -> impl Fn(Remote<ServerAddr>) -> io::Result<io::BoxedIo> {
613600
move |endpoint| {
614601
let span = tracing::info_span!("hello_server", ?endpoint);
@@ -620,7 +607,8 @@ fn hello_server(
620607
Ok::<_, io::Error>(Response::new(Body::from("Hello world!")))
621608
});
622609
tokio::spawn(
623-
http.serve_connection(server_io, hello_svc)
610+
server
611+
.serve_connection(server_io, hello_svc)
624612
.in_current_span(),
625613
);
626614
Ok(io::BoxedIo::new(client_io))
@@ -630,7 +618,7 @@ fn hello_server(
630618
#[tracing::instrument]
631619
#[allow(deprecated)] // linkerd/linkerd2#8733
632620
fn grpc_status_server(
633-
http: hyper::server::conn::Http,
621+
server: hyper::server::conn::http2::Builder<TracingExecutor>,
634622
status: tonic::Code,
635623
) -> impl Fn(Remote<ServerAddr>) -> io::Result<io::BoxedIo> {
636624
move |endpoint| {
@@ -639,26 +627,30 @@ fn grpc_status_server(
639627
tracing::info!("mock connecting");
640628
let (client_io, server_io) = support::io::duplex(4096);
641629
tokio::spawn(
642-
http.serve_connection(
643-
server_io,
644-
hyper::service::service_fn(move |request: Request<Body>| async move {
645-
tracing::info!(?request);
646-
let (mut tx, rx) = Body::channel();
647-
tokio::spawn(async move {
648-
let mut trls = ::http::HeaderMap::new();
649-
trls.insert("grpc-status", (status as u32).to_string().parse().unwrap());
650-
tx.send_trailers(trls).await
651-
});
652-
Ok::<_, io::Error>(
653-
http::Response::builder()
654-
.version(::http::Version::HTTP_2)
655-
.header("content-type", "application/grpc")
656-
.body(rx)
657-
.unwrap(),
658-
)
659-
}),
660-
)
661-
.in_current_span(),
630+
server
631+
.serve_connection(
632+
server_io,
633+
hyper::service::service_fn(move |request: Request<Body>| async move {
634+
tracing::info!(?request);
635+
let (mut tx, rx) = Body::channel();
636+
tokio::spawn(async move {
637+
let mut trls = ::http::HeaderMap::new();
638+
trls.insert(
639+
"grpc-status",
640+
(status as u32).to_string().parse().unwrap(),
641+
);
642+
tx.send_trailers(trls).await
643+
});
644+
Ok::<_, io::Error>(
645+
http::Response::builder()
646+
.version(::http::Version::HTTP_2)
647+
.header("content-type", "application/grpc")
648+
.body(rx)
649+
.unwrap(),
650+
)
651+
}),
652+
)
653+
.in_current_span(),
662654
);
663655
Ok(io::BoxedIo::new(client_io))
664656
}
@@ -675,10 +667,7 @@ fn connect_error() -> impl Fn(Remote<ServerAddr>) -> io::Result<io::BoxedIo> {
675667
}
676668

677669
#[tracing::instrument]
678-
#[allow(deprecated)] // linkerd/linkerd2#8733
679-
fn connect_timeout(
680-
http: hyper::server::conn::Http,
681-
) -> Box<dyn FnMut(Remote<ServerAddr>) -> ConnectFuture + Send> {
670+
fn connect_timeout() -> Box<dyn FnMut(Remote<ServerAddr>) -> ConnectFuture + Send> {
682671
Box::new(move |endpoint| {
683672
let span = tracing::info_span!("connect_timeout", ?endpoint);
684673
Box::pin(

0 commit comments

Comments
 (0)