-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
outbound: Return a default endpoint on reject (#690)
When the resolver rejects resolution, we currently propagate that error so that it can be handled via fallback. And due to recent HTTP router changes, these resolution errors can propagate up across splits, etc. This change simplifies this behavior by isntead synthesizing a resolution with a default endpoint. The `not_http` reason has been removed, as it's no longer useful.
- Loading branch information
Showing
11 changed files
with
134 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use super::Rejected; | ||
use futures::{future, prelude::*, stream}; | ||
use linkerd2_app_core::{ | ||
proxy::core::{Resolve, Update}, | ||
svc, Error, | ||
}; | ||
use std::{ | ||
future::Future, | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
}; | ||
|
||
pub fn layer<S>() -> impl svc::Layer<S, Service = RecoverDefaultResolve<S>> + Clone { | ||
svc::layer::mk(RecoverDefaultResolve) | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct RecoverDefaultResolve<S>(S); | ||
|
||
impl<T, S> tower::Service<T> for RecoverDefaultResolve<S> | ||
where | ||
for<'t> &'t T: Into<std::net::SocketAddr>, | ||
S: Resolve<T, Error = Error>, | ||
S::Endpoint: Default + Send + 'static, | ||
S::Resolution: Send + 'static, | ||
S::Future: Send + 'static, | ||
stream::Once<future::Ready<Result<Update<S::Endpoint>, S::Error>>>: | ||
stream::TryStream<Ok = Update<S::Endpoint>, Error = S::Error>, | ||
{ | ||
type Response = future::Either< | ||
S::Resolution, | ||
stream::Once<future::Ready<Result<Update<S::Endpoint>, Error>>>, | ||
>; | ||
type Error = Error; | ||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Error>> + Send + 'static>>; | ||
|
||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
self.0.poll_ready(cx) | ||
} | ||
|
||
fn call(&mut self, t: T) -> Self::Future { | ||
let addr = (&t).into(); | ||
Box::pin( | ||
self.0 | ||
.resolve(t) | ||
.map_ok(future::Either::Left) | ||
.or_else(move |error| { | ||
if Rejected::matches(&*error) { | ||
tracing::debug!(%error, %addr, "Synthesizing endpoint"); | ||
let endpoint = (addr, S::Endpoint::default()); | ||
let res = stream::once(future::ok(Update::Reset(vec![endpoint]))); | ||
future::ok(future::Either::Right(res)) | ||
} else { | ||
future::err(error) | ||
} | ||
}), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.