Skip to content

Commit

Permalink
chore(hyper): enable deprecated feature flag
Browse files Browse the repository at this point in the history
this is a prepatory chore, laying more ground to facilitate upgrading
our hyper dependency to the 1.0 major release. this commit adds the
`deprecated` cargo feature to each of the hyper dependencies in the
cargo workspace.

to prevent this from introducing a large number of compiler warnings to
the build, the `#[allow(deprecated)]` attribute is added to relevant
expressions.

these uses of deprecated interfaces will be updated in subsequent
commits. broadly, these fall into a few common cases:

* `hyper::client::conn::SendRequest` now has protocol specific `h1` and
  `h2` variants.

* `hyper::server::conn::Builder` now has protocol specific `h1` and
  `h2` variants.

* `hyper::server::conn::Http` is deprecated.

* functions like `hyper::body::aggregate(..)` and
  `hyper::body::to_bytes(..)` are deprecated.

see linkerd/linkerd2#8733 for more information
on the hyper 1.0 upgrade process.

Signed-off-by: katelyn martin <kate@buoyant.io>
  • Loading branch information
cratelyn committed Dec 2, 2024
1 parent 4019c28 commit 13c8d44
Show file tree
Hide file tree
Showing 34 changed files with 103 additions and 56 deletions.
2 changes: 1 addition & 1 deletion hyper-balance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
[dependencies]
futures = { version = "0.3", default-features = false }
http = "0.2"
hyper = "0.14"
hyper = { version = "0.14", features = ["deprecated"] }
pin-project = "1"
tower = { version = "0.4", default-features = false, features = ["load"] }
tokio = { version = "1", features = ["macros"] }
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/admin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ log-streaming = ["linkerd-tracing/stream"]
[dependencies]
deflate = { version = "1", optional = true, features = ["gzip"] }
http = "0.2"
hyper = { version = "0.14", features = ["http1", "http2"] }
hyper = { version = "0.14", features = ["deprecated", "http1", "http2"] }
futures = { version = "0.3", default-features = false }
pprof = { version = "0.14", optional = true, features = ["prost-codec"] }
serde = "1"
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/admin/src/server/log/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ where
}

http::Method::PUT => {
#[allow(deprecated)] // linkerd/linkerd2#8733
let body = hyper::body::aggregate(req.into_body())
.await
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/admin/src/server/log/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ where
// If the request is a QUERY, use the request body
method if method.as_str() == "QUERY" => {
// TODO(eliza): validate that the request has a content-length...
#[allow(deprecated)] // linkerd/linkerd2#8733
let body = recover!(
hyper::body::aggregate(req.into_body())
.await
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bytes = "1"
drain = { version = "0.1", features = ["retain"] }
http = "0.2"
http-body = "0.4"
hyper = { version = "0.14", features = ["http1", "http2"] }
hyper = { version = "0.14", features = ["deprecated", "http1", "http2"] }
futures = { version = "0.3", default-features = false }
ipnet = "2.10"
prometheus-client = "0.22"
Expand Down
4 changes: 2 additions & 2 deletions linkerd/app/inbound/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ path = "../../proxy/server-policy"
features = ["proto"]

[target.'cfg(fuzzing)'.dependencies]
hyper = { version = "0.14", features = ["http1", "http2"] }
hyper = { version = "0.14", features = ["deprecated", "http1", "http2"] }
linkerd-app-test = { path = "../test" }
arbitrary = { version = "1", features = ["derive"] }
libfuzzer-sys = { version = "0.4", features = ["arbitrary-derive"] }

[dev-dependencies]
hyper = { version = "0.14", features = ["http1", "http2"] }
hyper = { version = "0.14", features = ["deprecated", "http1", "http2"] }
linkerd-app-test = { path = "../test" }
linkerd-http-metrics = { path = "../../http/metrics", features = ["test-util"] }
linkerd-idle-cache = { path = "../../idle-cache", features = ["test-util"] }
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/inbound/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cargo-fuzz = true

[target.'cfg(fuzzing)'.dependencies]
arbitrary = { version = "1", features = ["derive"] }
hyper = { version = "0.14", features = ["http1", "http2"] }
hyper = { version = "0.14", features = ["deprecated", "http1", "http2"] }
http = "0.2"
libfuzzer-sys = { version = "0.4", features = ["arbitrary-derive"] }
linkerd-app-core = { path = "../../core" }
Expand Down
47 changes: 34 additions & 13 deletions linkerd/app/inbound/src/http/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
},
Config, Inbound,
};
use hyper::{body::HttpBody, client::conn::Builder as ClientBuilder, Body, Request, Response};
use hyper::{body::HttpBody, Body, Request, Response};
use linkerd_app_core::{
classify,
errors::respond::L5D_PROXY_ERROR,
Expand Down Expand Up @@ -46,9 +46,11 @@ where

#[tokio::test(flavor = "current_thread")]
async fn unmeshed_http1_hello_world() {
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut server = hyper::server::conn::Http::new();
server.http1_only(true);
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
let _trace = trace_init();

// Build a mock "connector" that returns the upstream "server" IO.
Expand Down Expand Up @@ -82,9 +84,11 @@ async fn unmeshed_http1_hello_world() {
#[tokio::test(flavor = "current_thread")]
async fn downgrade_origin_form() {
// Reproduces https://github.com/linkerd/linkerd2/issues/5298
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut server = hyper::server::conn::Http::new();
server.http1_only(true);
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
client.http2_only(true);
let _trace = trace_init();

Expand Down Expand Up @@ -120,9 +124,11 @@ async fn downgrade_origin_form() {

#[tokio::test(flavor = "current_thread")]
async fn downgrade_absolute_form() {
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut server = hyper::server::conn::Http::new();
server.http1_only(true);
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
client.http2_only(true);
let _trace = trace_init();

Expand Down Expand Up @@ -165,7 +171,8 @@ async fn http1_bad_gateway_meshed_response_error_header() {

// Build a client using the connect that always errors so that responses
// are BAD_GATEWAY.
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
let profiles = profile::resolver();
let profile_tx =
profiles.profile_tx(NameAddr::from_str_and_port("foo.svc.cluster.local", 5550).unwrap());
Expand Down Expand Up @@ -203,7 +210,8 @@ async fn http1_bad_gateway_unmeshed_response() {

// Build a client using the connect that always errors so that responses
// are BAD_GATEWAY.
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
let profiles = profile::resolver();
let profile_tx =
profiles.profile_tx(NameAddr::from_str_and_port("foo.svc.cluster.local", 5550).unwrap());
Expand Down Expand Up @@ -238,12 +246,14 @@ async fn http1_connect_timeout_meshed_response_error_header() {

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

// Build a client using the connect that always sleeps so that responses
// are GATEWAY_TIMEOUT.
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
let profiles = profile::resolver();
let profile_tx =
profiles.profile_tx(NameAddr::from_str_and_port("foo.svc.cluster.local", 5550).unwrap());
Expand Down Expand Up @@ -280,12 +290,14 @@ async fn http1_connect_timeout_unmeshed_response_error_header() {

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

// Build a client using the connect that always sleeps so that responses
// are GATEWAY_TIMEOUT.
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
let profiles = profile::resolver();
let profile_tx =
profiles.profile_tx(NameAddr::from_str_and_port("foo.svc.cluster.local", 5550).unwrap());
Expand Down Expand Up @@ -321,7 +333,8 @@ async fn h2_response_meshed_error_header() {
let connect = support::connect().endpoint_fn_boxed(Target::addr(), connect_error());

// Build a client using the connect that always errors.
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
client.http2_only(true);
let profiles = profile::resolver();
let profile_tx =
Expand Down Expand Up @@ -359,7 +372,8 @@ async fn h2_response_unmeshed_error_header() {
let connect = support::connect().endpoint_fn_boxed(Target::addr(), connect_error());

// Build a client using the connect that always errors.
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
client.http2_only(true);
let profiles = profile::resolver();
let profile_tx =
Expand Down Expand Up @@ -399,7 +413,8 @@ async fn grpc_meshed_response_error_header() {
let connect = support::connect().endpoint_fn_boxed(Target::addr(), connect_error());

// Build a client using the connect that always errors.
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
client.http2_only(true);
let profiles = profile::resolver();
let profile_tx =
Expand Down Expand Up @@ -438,7 +453,8 @@ async fn grpc_unmeshed_response_error_header() {
let connect = support::connect().endpoint_fn_boxed(Target::addr(), connect_error());

// Build a client using the connect that always errors.
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
client.http2_only(true);
let profiles = profile::resolver();
let profile_tx =
Expand Down Expand Up @@ -477,6 +493,7 @@ async fn grpc_response_class() {

// Build a mock connector serves a gRPC server that returns errors.
let connect = {
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut server = hyper::server::conn::Http::new();
server.http2_only(true);
support::connect().endpoint_fn_boxed(
Expand All @@ -486,7 +503,8 @@ async fn grpc_response_class() {
};

// Build a client using the connect that always errors.
let mut client = ClientBuilder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
client.http2_only(true);
let profiles = profile::resolver();
let profile_tx =
Expand Down Expand Up @@ -550,6 +568,7 @@ async fn grpc_response_class() {
}

#[tracing::instrument]
#[allow(deprecated)] // linkerd/linkerd2#8733
fn hello_server(
http: hyper::server::conn::Http,
) -> impl Fn(Remote<ServerAddr>) -> io::Result<io::BoxedIo> {
Expand All @@ -571,6 +590,7 @@ fn hello_server(
}

#[tracing::instrument]
#[allow(deprecated)] // linkerd/linkerd2#8733
fn grpc_status_server(
http: hyper::server::conn::Http,
status: tonic::Code,
Expand Down Expand Up @@ -617,6 +637,7 @@ fn connect_error() -> impl Fn(Remote<ServerAddr>) -> io::Result<io::BoxedIo> {
}

#[tracing::instrument]
#[allow(deprecated)] // linkerd/linkerd2#8733
fn connect_timeout(
http: hyper::server::conn::Http,
) -> Box<dyn FnMut(Remote<ServerAddr>) -> ConnectFuture + Send> {
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ h2 = "0.3"
http = "0.2"
http-body = "0.4"
hyper = { version = "0.14", features = [
"deprecated",
"http1",
"http2",
"stream",
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/integration/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ where
let _ = listening_tx.send(());
}

#[allow(deprecated)] // linkerd/linkerd2#8733
let mut http = hyper::server::conn::Http::new().with_executor(TracingExecutor);
http.http2_only(true);
loop {
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/integration/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl Server {
async move {
tracing::info!("support server running");
let mut new_svc = NewSvc(Arc::new(self.routes));
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut http = hyper::server::conn::Http::new().with_executor(TracingExecutor);
match self.version {
Run::Http1 => http.http1_only(true),
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/integration/src/tap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ where
// just can't prove it.
let req = futures::executor::block_on(async move {
let (parts, body) = req.into_parts();
#[allow(deprecated)] // linkerd/linkerd2#8733
let body = match hyper::body::to_bytes(body).await {
Ok(body) => body,
Err(_) => unreachable!("body should not fail"),
Expand Down
20 changes: 10 additions & 10 deletions linkerd/app/integration/src/tests/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,16 +481,16 @@ mod http2 {

let res = fut.await.expect("beta response");
assert_eq!(res.status(), http::StatusCode::OK);
assert_eq!(
String::from_utf8(
hyper::body::to_bytes(res.into_body())
.await
.unwrap()
.to_vec(),
)
.unwrap(),
"beta"
);

#[allow(deprecated)] // linkerd/linkerd2#8733
let body = String::from_utf8(
hyper::body::to_bytes(res.into_body())
.await
.unwrap()
.to_vec(),
)
.unwrap();
assert_eq!(body, "beta");
}
}

Expand Down
1 change: 1 addition & 0 deletions linkerd/app/integration/src/tests/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ impl TestBuilder {
async move {
// Read the entire body before responding, so that the
// client doesn't fail when writing it out.
#[allow(deprecated)] // linkerd/linkerd2#8733
let _body = hyper::body::to_bytes(req.into_body()).await;
tracing::debug!(body = ?_body.as_ref().map(|body| body.len()), "recieved body");
Ok::<_, Error>(if fail {
Expand Down
13 changes: 8 additions & 5 deletions linkerd/app/integration/src/tests/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ async fn h2_exercise_goaways_connections() {

let bodies = resps
.into_iter()
.map(|resp| {
hyper::body::aggregate(resp.into_body())
// Make sure the bodies weren't cut off
.map_ok(|buf| assert_eq!(buf.remaining(), RESPONSE_SIZE))
})
.map(
#[allow(deprecated)] // linkerd/linkerd2#8733
|resp| {
hyper::body::aggregate(resp.into_body())
// Make sure the bodies weren't cut off
.map_ok(|buf| assert_eq!(buf.remaining(), RESPONSE_SIZE))
},
)
.collect::<Vec<_>>();

// See that the proxy gives us all the bodies.
Expand Down
7 changes: 3 additions & 4 deletions linkerd/app/integration/src/tests/tap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,9 @@ async fn grpc_headers_end() {
.unwrap();
assert_eq!(res.status(), 200);
assert_eq!(res.headers()["grpc-status"], "1");
assert_eq!(
hyper::body::to_bytes(res.into_body()).await.unwrap().len(),
0
);
#[allow(deprecated)] // linkerd/linkerd2#8733
let bytes = hyper::body::to_bytes(res.into_body()).await.unwrap().len();
assert_eq!(bytes, 0);

let event = events.skip(2).next().await.expect("2nd").expect("stream");
assert_eq!(event.response_end_eos_grpc(), 1);
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/integration/src/tests/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ async fn metrics_compression() {
);
}

#[allow(deprecated)] // linkerd/linkerd2#8733
let mut body = hyper::body::aggregate(resp.into_body())
.await
.expect("response body concat");
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/integration/src/tests/transparency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,7 @@ async fn http2_request_without_authority() {
let io = tokio::net::TcpStream::connect(&addr)
.await
.expect("connect error");
#[allow(deprecated)] // linkerd/linkerd2#8733
let (mut client, conn) = hyper::client::conn::Builder::new()
.http2_only(true)
.handshake(io)
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/outbound/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ linkerd-tonic-watch = { path = "../../tonic-watch" }
[dev-dependencies]
futures-util = "0.3"
http-body = "0.4"
hyper = { version = "0.14", features = ["http1", "http2"] }
hyper = { version = "0.14", features = ["deprecated", "http1", "http2"] }
tokio = { version = "1", features = ["macros", "sync", "time"] }
tokio-rustls = "0.24"
tokio-test = "0.4"
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/outbound/src/http/endpoint/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ fn serve(version: ::http::Version) -> io::Result<io::BoxedIo> {
future::ok::<_, Infallible>(rsp.body(hyper::Body::default()).unwrap())
});

#[allow(deprecated)] // linkerd/linkerd2#8733
let mut http = hyper::server::conn::Http::new();
match version {
::http::Version::HTTP_10 | ::http::Version::HTTP_11 => http.http1_only(true),
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/outbound/src/http/logical/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ async fn assert_rsp<T: std::fmt::Debug>(
{
let rsp = rsp.await.expect("response must not fail");
assert_eq!(rsp.status(), status, "expected status code to be {status}");
#[allow(deprecated)] // linkerd/linkerd2#8733
let body = hyper::body::to_bytes(rsp.into_body())
.await
.expect("body must not fail");
Expand Down
Loading

0 comments on commit 13c8d44

Please sign in to comment.