From c18d469e40826be4d51112d7c935da3e57c11f15 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Mon, 24 Feb 2025 00:00:00 +0000 Subject: [PATCH 1/2] refactor(app/integration): remove `Request`, `Response` aliases see https://github.com/linkerd/linkerd2/issues/8733. this commit removes two type aliases from our test server implementation. these are each tied to the defunct `hyper::Body` type. since much of this code was originally written (between 2017 and 2020) we've since developed some patterns / idioms elsewhere for dealing with request and response bodies. to help set the stage for tweaks to which interfaces need `hyper::body::Incoming`, which types work with our general default of `BoxBody`, and which can be generic across arbitrary `B`-typed bodies, we remove these aliases and provide the body parameter to `Request` and `Response`. Signed-off-by: katelyn martin --- linkerd/app/integration/src/server.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/linkerd/app/integration/src/server.rs b/linkerd/app/integration/src/server.rs index 1b9de085f5..9b50bdd9e6 100644 --- a/linkerd/app/integration/src/server.rs +++ b/linkerd/app/integration/src/server.rs @@ -1,5 +1,6 @@ use super::app_core::svc::http::TracingExecutor; use super::*; +use http::{Request, Response}; use std::{ io, sync::atomic::{AtomicUsize, Ordering}, @@ -41,9 +42,8 @@ pub struct Listening { pub(super) http_version: Option, } -type Request = http::Request; -type Response = http::Response; -type RspFuture = Pin> + Send + Sync + 'static>>; +type RspFuture = + Pin, Error>> + Send + Sync + 'static>>; impl Listening { pub fn connections(&self) -> usize { @@ -123,7 +123,7 @@ impl Server { /// to send back. pub fn route_fn(self, path: &str, cb: F) -> Self where - F: Fn(Request) -> Response + Send + Sync + 'static, + F: Fn(Request) -> Response + Send + Sync + 'static, { self.route_async(path, move |req| { let res = cb(req); @@ -135,8 +135,8 @@ impl Server { /// a response to send back. pub fn route_async(mut self, path: &str, cb: F) -> Self where - F: Fn(Request) -> U + Send + Sync + 'static, - U: TryFuture + Send + Sync + 'static, + F: Fn(Request) -> U + Send + Sync + 'static, + U: TryFuture> + Send + Sync + 'static, U::Error: Into + Send + 'static, { let func = move |req| Box::pin(cb(req).map_err(Into::into)) as RspFuture; @@ -258,7 +258,7 @@ pub(super) enum Run { Http2, } -struct Route(Box RspFuture + Send + Sync>); +struct Route(Box) -> RspFuture + Send + Sync>); impl Route { fn string(body: &str) -> Route { @@ -284,7 +284,7 @@ impl std::fmt::Debug for Route { struct Svc(Arc>); impl Svc { - fn route(&mut self, req: Request) -> RspFuture { + fn route(&mut self, req: Request) -> RspFuture { match self.0.get(req.uri().path()) { Some(Route(ref func)) => { tracing::trace!(path = %req.uri().path(), "found route for path"); @@ -302,8 +302,8 @@ impl Svc { } } -impl tower::Service for Svc { - type Response = Response; +impl tower::Service> for Svc { + type Response = Response; type Error = Error; type Future = RspFuture; @@ -311,7 +311,7 @@ impl tower::Service for Svc { Poll::Ready(Ok(())) } - fn call(&mut self, req: Request) -> Self::Future { + fn call(&mut self, req: Request) -> Self::Future { self.route(req) } } From 349d188eea44e75ab44f02af806be7c7971a69b4 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Mon, 24 Feb 2025 00:00:00 +0000 Subject: [PATCH 2/2] refactor(app/integration): remove `Request`, `Response` aliases see https://github.com/linkerd/linkerd2/issues/8733. this commit removes two type aliases from our test client implementation. these are each tied to the defunct `hyper::Body` type. since much of this code was originally written (between 2017 and 2020) we've since developed some patterns / idioms elsewhere for dealing with request and response bodies. to help set the stage for tweaks to which interfaces need `hyper::body::Incoming`, which types work with our general default of `BoxBody`, and which can be generic across arbitrary `B`-typed bodies, we remove these aliases and provide the body parameter to `Request` and `Response`. Signed-off-by: katelyn martin --- linkerd/app/integration/src/client.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/linkerd/app/integration/src/client.rs b/linkerd/app/integration/src/client.rs index 023869d4e3..fbb4370ad3 100644 --- a/linkerd/app/integration/src/client.rs +++ b/linkerd/app/integration/src/client.rs @@ -1,4 +1,5 @@ use super::*; +use http::{Request, Response}; use linkerd_app_core::proxy::http::TracingExecutor; use parking_lot::Mutex; use std::io; @@ -7,9 +8,10 @@ use tokio_rustls::rustls::{self, ClientConfig}; use tracing::info_span; type ClientError = hyper::Error; -type Request = http::Request; -type Response = http::Response; -type Sender = mpsc::UnboundedSender<(Request, oneshot::Sender>)>; +type Sender = mpsc::UnboundedSender<( + Request, + oneshot::Sender, ClientError>>, +)>; #[derive(Clone)] pub struct TlsConfig { @@ -133,11 +135,12 @@ impl Client { pub fn request( &self, builder: http::request::Builder, - ) -> impl Future> + Send + Sync + 'static { + ) -> impl Future, ClientError>> + Send + Sync + 'static + { self.send_req(builder.body(Bytes::new().into()).unwrap()) } - pub async fn request_body(&self, req: Request) -> Response { + pub async fn request_body(&self, req: Request) -> Response { self.send_req(req).await.expect("response") } @@ -156,8 +159,9 @@ impl Client { #[tracing::instrument(skip(self))] pub(crate) fn send_req( &self, - mut req: Request, - ) -> impl Future> + Send + Sync + 'static { + mut req: Request, + ) -> impl Future, ClientError>> + Send + Sync + 'static + { if req.uri().scheme().is_none() { if self.tls.is_some() { *req.uri_mut() = format!("https://{}{}", self.authority, req.uri().path()) @@ -228,8 +232,10 @@ fn run( version: Run, tls: Option, ) -> (Sender, JoinHandle<()>, Running) { - let (tx, rx) = - mpsc::unbounded_channel::<(Request, oneshot::Sender>)>(); + let (tx, rx) = mpsc::unbounded_channel::<( + Request, + oneshot::Sender, ClientError>>, + )>(); let test_name = thread_name(); let absolute_uris = if let Run::Http1 { absolute_uris } = version {