From af522e463e682db03170d40b02c26242c6bd3baf Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Tue, 16 Nov 2021 18:40:39 +0000 Subject: [PATCH] app: Move retry types into the app-outbound crate The retry crate is hardcoded to use the `linkerd_app_core::dst::Route` type as its target. This is inflexible, especially if we want to reorganize the outbound stack to support things like header-based overrides. This change movers the retry layer into the outbound crate so that it can be changed to use outbound-specific types. No functional changes. --- Cargo.lock | 4 ++-- linkerd/app/core/Cargo.toml | 2 -- linkerd/app/core/src/classify.rs | 2 +- linkerd/app/core/src/lib.rs | 1 - linkerd/app/outbound/Cargo.toml | 2 ++ linkerd/app/outbound/src/http.rs | 1 + linkerd/app/outbound/src/http/logical.rs | 4 ++-- .../{core/src => outbound/src/http}/retry.rs | 22 ++++++++++--------- 8 files changed, 20 insertions(+), 18 deletions(-) rename linkerd/app/{core/src => outbound/src/http}/retry.rs (93%) diff --git a/Cargo.lock b/Cargo.lock index 1078dadbe5..905f9c3f04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -839,7 +839,6 @@ dependencies = [ "linkerd-exp-backoff", "linkerd-http-classify", "linkerd-http-metrics", - "linkerd-http-retry", "linkerd-identity", "linkerd-io", "linkerd-meshtls", @@ -856,7 +855,6 @@ dependencies = [ "linkerd-proxy-tcp", "linkerd-proxy-transport", "linkerd-reconnect", - "linkerd-retry", "linkerd-service-profiles", "linkerd-stack", "linkerd-stack-metrics", @@ -966,11 +964,13 @@ dependencies = [ "hyper", "linkerd-app-core", "linkerd-app-test", + "linkerd-http-classify", "linkerd-http-retry", "linkerd-identity", "linkerd-io", "linkerd-meshtls", "linkerd-meshtls-rustls", + "linkerd-retry", "linkerd-tracing", "parking_lot", "pin-project", diff --git a/linkerd/app/core/Cargo.toml b/linkerd/app/core/Cargo.toml index 2a63fde69c..24a8fe8c82 100644 --- a/linkerd/app/core/Cargo.toml +++ b/linkerd/app/core/Cargo.toml @@ -32,7 +32,6 @@ linkerd-error-respond = { path = "../../error-respond" } linkerd-exp-backoff = { path = "../../exp-backoff" } linkerd-http-classify = { path = "../../http-classify" } linkerd-http-metrics = { path = "../../http-metrics" } -linkerd-http-retry = { path = "../../http-retry" } linkerd-identity = { path = "../../identity" } linkerd-io = { path = "../../io" } linkerd-meshtls = { path = "../../meshtls", default-features = false } @@ -49,7 +48,6 @@ linkerd-proxy-tap = { path = "../../proxy/tap" } linkerd-proxy-tcp = { path = "../../proxy/tcp" } linkerd-proxy-transport = { path = "../../proxy/transport" } linkerd-reconnect = { path = "../../reconnect" } -linkerd-retry = { path = "../../retry" } linkerd-service-profiles = { path = "../../service-profiles" } linkerd-stack = { path = "../../stack" } linkerd-stack-metrics = { path = "../../stack/metrics" } diff --git a/linkerd/app/core/src/classify.rs b/linkerd/app/core/src/classify.rs index 1b90cd66aa..c654948545 100644 --- a/linkerd/app/core/src/classify.rs +++ b/linkerd/app/core/src/classify.rs @@ -214,7 +214,7 @@ fn h2_error(err: &Error) -> String { // === impl Class === impl Class { - pub(super) fn is_failure(&self) -> bool { + pub fn is_failure(&self) -> bool { matches!( self, Class::Default(SuccessOrFailure::Failure) diff --git a/linkerd/app/core/src/lib.rs b/linkerd/app/core/src/lib.rs index 5c418cdd5c..9df24fe07e 100644 --- a/linkerd/app/core/src/lib.rs +++ b/linkerd/app/core/src/lib.rs @@ -41,7 +41,6 @@ pub mod errors; pub mod http_tracing; pub mod metrics; pub mod proxy; -pub mod retry; pub mod serve; pub mod svc; pub mod telemetry; diff --git a/linkerd/app/outbound/Cargo.toml b/linkerd/app/outbound/Cargo.toml index ea6c9138b9..b93ef1df06 100644 --- a/linkerd/app/outbound/Cargo.toml +++ b/linkerd/app/outbound/Cargo.toml @@ -19,8 +19,10 @@ bytes = "1" http = "0.2" futures = { version = "0.3", default-features = false } linkerd-app-core = { path = "../core" } +linkerd-http-classify = { path = "../../http-classify" } linkerd-http-retry = { path = "../../http-retry" } linkerd-identity = { path = "../../identity" } +linkerd-retry = { path = "../../retry" } parking_lot = "0.11" thiserror = "1.0" tokio = { version = "1", features = ["sync"] } diff --git a/linkerd/app/outbound/src/http.rs b/linkerd/app/outbound/src/http.rs index 7adaadd3a2..d13de90695 100644 --- a/linkerd/app/outbound/src/http.rs +++ b/linkerd/app/outbound/src/http.rs @@ -3,6 +3,7 @@ mod endpoint; pub mod logical; mod proxy_connection_close; mod require_id_header; +mod retry; mod server; mod strip_proxy_error; diff --git a/linkerd/app/outbound/src/http/logical.rs b/linkerd/app/outbound/src/http/logical.rs index 3d1c5ac4bd..b64aaee37b 100644 --- a/linkerd/app/outbound/src/http/logical.rs +++ b/linkerd/app/outbound/src/http/logical.rs @@ -1,4 +1,4 @@ -use super::{CanonicalDstHeader, Concrete, Endpoint, Logical}; +use super::{retry, CanonicalDstHeader, Concrete, Endpoint, Logical}; use crate::{endpoint, resolve, stack_labels, Outbound}; use linkerd_app_core::{ classify, config, dst, profiles, @@ -8,7 +8,7 @@ use linkerd_app_core::{ http, resolve::map_endpoint, }, - retry, svc, Error, Infallible, + svc, Error, Infallible, }; use tracing::debug_span; diff --git a/linkerd/app/core/src/retry.rs b/linkerd/app/outbound/src/http/retry.rs similarity index 93% rename from linkerd/app/core/src/retry.rs rename to linkerd/app/outbound/src/http/retry.rs index 6059b8c0e0..0da2ba9e9a 100644 --- a/linkerd/app/core/src/retry.rs +++ b/linkerd/app/outbound/src/http/retry.rs @@ -1,15 +1,17 @@ -use super::classify; -use super::dst::Route; -use super::http_metrics::retries::Handle; -use super::metrics::HttpRouteRetry; -use crate::profiles; use futures::future; -use linkerd_error::Error; +use linkerd_app_core::{ + classify, + dst::Route, + http_metrics::retries::Handle, + metrics::HttpRouteRetry, + profiles, + proxy::http::{ClientHandle, HttpBody}, + svc::{layer, Either, Param}, + Error, +}; use linkerd_http_classify::{Classify, ClassifyEos, ClassifyResponse}; use linkerd_http_retry::ReplayBody; -use linkerd_proxy_http::ClientHandle; use linkerd_retry as retry; -use linkerd_stack::{layer, Either, Param}; use std::sync::Arc; pub fn layer( @@ -60,7 +62,7 @@ impl retry::NewPolicy for NewRetryPolicy { impl retry::Policy>, http::Response, E> for RetryPolicy where - A: http_body::Body + Unpin, + A: HttpBody + Unpin, A::Error: Into, { type Future = future::Ready; @@ -125,7 +127,7 @@ where impl retry::PrepareRequest, http::Response, E> for RetryPolicy where - A: http_body::Body + Unpin, + A: HttpBody + Unpin, A::Error: Into, { type RetryRequest = http::Request>;