Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outbound: Decouple outbound HTTP server from logical target #2249

Merged
merged 1 commit into from
Feb 20, 2023
Merged
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
20 changes: 5 additions & 15 deletions linkerd/app/outbound/src/http/server.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
use super::{IdentityRequired, Logical, ProxyConnectionClose};
use super::{IdentityRequired, ProxyConnectionClose};
use crate::{http, trace_labels, Outbound};
use linkerd_app_core::{
errors, http_tracing, io,
svc::{self, ExtractParam},
transport::addrs::*,
Addr, Error, Result,
Error, Result,
};

#[derive(Copy, Clone, Debug)]
pub(crate) struct ServerRescue {
emit_headers: bool,
}

#[derive(Copy, Clone, Debug)]
struct Target<T>(T);

impl<N> Outbound<N> {
/// Builds a [`svc::NewService`] stack that prepares HTTP requests to be
/// proxied.
Expand All @@ -37,7 +33,8 @@ impl<N> Outbound<N> {
>,
>
where
T: svc::Param<Logical> + 'static,
// Target
T: svc::Param<http::normalize_uri::DefaultAuthority>,
// HTTP outbound stack
N: svc::NewService<T, Service = NSvc> + Clone + Send + Sync + 'static,
NSvc: svc::Service<http::Request<http::BoxBody>, Response = http::Response<http::BoxBody>>,
Expand Down Expand Up @@ -80,14 +77,7 @@ impl<N> Outbound<N> {
)
// Convert origin form HTTP/1 URIs to absolute form for Hyper's
// `Client`.
.push(http::NewNormalizeUri::layer_via(|target: &T| {
let addr = match target.param() {
Logical::Route(addr, _) => Addr::from(addr),
Logical::Forward(Remote(ServerAddr(addr)), _) => Addr::from(addr),
};

http::normalize_uri::DefaultAuthority(Some(addr.to_http_authority()))
}))
.push(http::NewNormalizeUri::layer())
// Record when a HTTP/1 URI originated in absolute form
.push_on_service(http::normalize_uri::MarkAbsoluteForm::layer())
.push(svc::ArcNewService::layer())
Expand Down
9 changes: 9 additions & 0 deletions linkerd/app/outbound/src/ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ impl svc::Param<http::Logical> for Http<http::Logical> {
}
}

impl svc::Param<http::normalize_uri::DefaultAuthority> for Http<http::Logical> {
fn param(&self) -> http::normalize_uri::DefaultAuthority {
http::normalize_uri::DefaultAuthority(match &self.parent {
http::Logical::Route(addr, _) => Some(addr.as_http_authority()),
http::Logical::Forward(..) => None,
})
}
}

impl TryFrom<discover::Discovery<Http<RequestTarget>>> for Http<http::Logical> {
type Error = ProfileRequired;

Expand Down
9 changes: 9 additions & 0 deletions linkerd/app/outbound/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,12 @@ where
self.parent.param()
}
}

impl<T> svc::Param<http::normalize_uri::DefaultAuthority> for Http<T>
where
T: svc::Param<http::normalize_uri::DefaultAuthority>,
{
fn param(&self) -> http::normalize_uri::DefaultAuthority {
self.parent.param()
}
}
9 changes: 9 additions & 0 deletions linkerd/app/outbound/src/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ impl svc::Param<Protocol> for Sidecar {
}
}

impl svc::Param<http::normalize_uri::DefaultAuthority> for Sidecar {
fn param(&self) -> http::normalize_uri::DefaultAuthority {
http::normalize_uri::DefaultAuthority(self.profile.as_ref().and_then(|p| {
p.logical_addr()
.map(|profiles::LogicalAddr(a)| a.as_http_authority())
}))
}
}

impl svc::Param<http::Logical> for Sidecar {
fn param(&self) -> http::Logical {
if let Some(profile) = self.profile.clone() {
Expand Down