diff --git a/include/envoy/router/router.h b/include/envoy/router/router.h index 91d8feb4267e..9d8fd7bc1aa5 100644 --- a/include/envoy/router/router.h +++ b/include/envoy/router/router.h @@ -37,6 +37,7 @@ namespace Envoy { namespace Upstream { class ClusterManager; class LoadBalancerContext; +class ThreadLocalCluster; } // namespace Upstream namespace Router { @@ -1306,7 +1307,7 @@ class GenericConnPoolFactory : public Envoy::Config::TypedFactory { * @return may be null */ virtual GenericConnPoolPtr - createGenericConnPool(Upstream::ClusterManager& cm, bool is_connect, + createGenericConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, const RouteEntry& route_entry, absl::optional downstream_protocol, Upstream::LoadBalancerContext* ctx) const PURE; diff --git a/include/envoy/tcp/upstream.h b/include/envoy/tcp/upstream.h index 71d266b9f1fc..aeb711a08c0e 100644 --- a/include/envoy/tcp/upstream.h +++ b/include/envoy/tcp/upstream.h @@ -10,6 +10,7 @@ namespace Envoy { namespace Upstream { class LoadBalancerContext; +class ThreadLocalCluster; } // namespace Upstream namespace TcpProxy { @@ -116,15 +117,14 @@ class GenericConnPoolFactory : public Envoy::Config::TypedFactory { envoy::extensions::filters::network::tcp_proxy::v3::TcpProxy_TunnelingConfig; /* - * @param cluster_name the name of the cluster to use - * @param cm the cluster manager to get the connection pool from + * @param thread_local_cluster the thread local cluster to use for conn pool creation. * @param config the tunneling config, if doing connect tunneling. * @param context the load balancing context for this connection. * @param upstream_callbacks the callbacks to provide to the connection if successfully created. * @return may be null if there is no cluster with the given name. */ virtual GenericConnPoolPtr - createGenericConnPool(const std::string& cluster_name, Upstream::ClusterManager& cm, + createGenericConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, const absl::optional& config, Upstream::LoadBalancerContext* context, Tcp::ConnectionPool::UpstreamCallbacks& upstream_callbacks) const PURE; diff --git a/source/common/router/router.cc b/source/common/router/router.cc index ef3ddd025a46..439a33997b43 100644 --- a/source/common/router/router.cc +++ b/source/common/router/router.cc @@ -491,7 +491,7 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::RequestHeaderMap& headers, transport_socket_options_ = Network::TransportSocketOptionsUtility::fromFilterState( *callbacks_->streamInfo().filterState()); - std::unique_ptr generic_conn_pool = createConnPool(); + std::unique_ptr generic_conn_pool = createConnPool(*cluster); if (!generic_conn_pool) { sendNoHealthyUpstreamResponse(); @@ -595,7 +595,8 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::RequestHeaderMap& headers, return Http::FilterHeadersStatus::StopIteration; } -std::unique_ptr Filter::createConnPool() { +std::unique_ptr +Filter::createConnPool(Upstream::ThreadLocalCluster& thread_local_cluster) { GenericConnPoolFactory* factory = nullptr; if (cluster_->upstreamConfig().has_value()) { factory = &Envoy::Config::Utility::getAndCheckFactory( @@ -607,7 +608,7 @@ std::unique_ptr Filter::createConnPool() { const bool should_tcp_proxy = route_entry_->connectConfig().has_value() && downstream_headers_->getMethodValue() == Http::Headers::get().MethodValues.Connect; - return factory->createGenericConnPool(config_.cm_, should_tcp_proxy, *route_entry_, + return factory->createGenericConnPool(thread_local_cluster, should_tcp_proxy, *route_entry_, callbacks_->streamInfo().protocol(), this); } @@ -1533,7 +1534,14 @@ void Filter::doRetry() { ASSERT(pending_retries_ > 0); pending_retries_--; - std::unique_ptr generic_conn_pool = createConnPool(); + // Clusters can technically get removed by CDS during a retry. Make sure it still exists. + const auto cluster = config_.cm_.getThreadLocalCluster(route_entry_->clusterName()); + std::unique_ptr generic_conn_pool; + if (cluster != nullptr) { + cluster_ = cluster->info(); + generic_conn_pool = createConnPool(*cluster); + } + if (!generic_conn_pool) { sendNoHealthyUpstreamResponse(); cleanup(); diff --git a/source/common/router/router.h b/source/common/router/router.h index 6688d973098d..24cfff0dcb7a 100644 --- a/source/common/router/router.h +++ b/source/common/router/router.h @@ -462,7 +462,8 @@ class Filter : Logger::Loggable, Event::Dispatcher& dispatcher, TimeSource& time_source, Upstream::ResourcePriority priority) PURE; - std::unique_ptr createConnPool(); + std::unique_ptr + createConnPool(Upstream::ThreadLocalCluster& thread_local_cluster); UpstreamRequestPtr createUpstreamRequest(); void maybeDoShadowing(); diff --git a/source/common/tcp_proxy/tcp_proxy.cc b/source/common/tcp_proxy/tcp_proxy.cc index 20d6fa297ab0..fe64127a0aa1 100644 --- a/source/common/tcp_proxy/tcp_proxy.cc +++ b/source/common/tcp_proxy/tcp_proxy.cc @@ -434,7 +434,7 @@ Network::FilterStatus Filter::initializeUpstreamConnection() { downstreamConnection()->streamInfo().filterState()); } - if (!maybeTunnel(*thread_local_cluster, cluster_name)) { + if (!maybeTunnel(*thread_local_cluster)) { // Either cluster is unknown or there are no healthy hosts. tcpConnPool() increments // cluster->stats().upstream_cx_none_healthy in the latter case. getStreamInfo().setResponseFlag(StreamInfo::ResponseFlag::NoHealthyUpstream); @@ -443,7 +443,7 @@ Network::FilterStatus Filter::initializeUpstreamConnection() { return Network::FilterStatus::StopIteration; } -bool Filter::maybeTunnel(Upstream::ThreadLocalCluster& cluster, const std::string& cluster_name) { +bool Filter::maybeTunnel(Upstream::ThreadLocalCluster& cluster) { GenericConnPoolFactory* factory = nullptr; if (cluster.info()->upstreamConfig().has_value()) { factory = Envoy::Config::Utility::getFactory( @@ -456,8 +456,8 @@ bool Filter::maybeTunnel(Upstream::ThreadLocalCluster& cluster, const std::strin return false; } - generic_conn_pool_ = factory->createGenericConnPool( - cluster_name, cluster_manager_, config_->tunnelingConfig(), this, *upstream_callbacks_); + generic_conn_pool_ = factory->createGenericConnPool(cluster, config_->tunnelingConfig(), this, + *upstream_callbacks_); if (generic_conn_pool_) { connecting_ = true; connect_attempts_++; diff --git a/source/common/tcp_proxy/tcp_proxy.h b/source/common/tcp_proxy/tcp_proxy.h index de61eb665139..a5e43e6e8ca5 100644 --- a/source/common/tcp_proxy/tcp_proxy.h +++ b/source/common/tcp_proxy/tcp_proxy.h @@ -345,7 +345,7 @@ class Filter : public Network::ReadFilter, void initialize(Network::ReadFilterCallbacks& callbacks, bool set_connection_stats); Network::FilterStatus initializeUpstreamConnection(); - bool maybeTunnel(Upstream::ThreadLocalCluster& cluster, const std::string& cluster_name); + bool maybeTunnel(Upstream::ThreadLocalCluster& cluster); void onConnectTimeout(); void onDownstreamEvent(Network::ConnectionEvent event); void onUpstreamData(Buffer::Instance& data, bool end_stream); diff --git a/source/common/tcp_proxy/upstream.cc b/source/common/tcp_proxy/upstream.cc index c5bbce249cc7..5b286f64dbc7 100644 --- a/source/common/tcp_proxy/upstream.cc +++ b/source/common/tcp_proxy/upstream.cc @@ -135,17 +135,11 @@ void HttpUpstream::doneWriting() { } } -TcpConnPool::TcpConnPool(const std::string& cluster_name, Upstream::ClusterManager& cluster_manager, +TcpConnPool::TcpConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, Upstream::LoadBalancerContext* context, Tcp::ConnectionPool::UpstreamCallbacks& upstream_callbacks) : upstream_callbacks_(upstream_callbacks) { - // TODO(mattklein123): Pass thread local cluster into this function, removing an additional - // map lookup and moving the error handling closer to the source (where it is likely already - // done). - const auto thread_local_cluster = cluster_manager.getThreadLocalCluster(cluster_name); - if (thread_local_cluster != nullptr) { - conn_pool_ = thread_local_cluster->tcpConnPool(Upstream::ResourcePriority::Default, context); - } + conn_pool_ = thread_local_cluster.tcpConnPool(Upstream::ResourcePriority::Default, context); } TcpConnPool::~TcpConnPool() { @@ -185,20 +179,13 @@ void TcpConnPool::onPoolReady(Tcp::ConnectionPool::ConnectionDataPtr&& conn_data latched_data->connection().streamInfo().downstreamSslConnection()); } -HttpConnPool::HttpConnPool(const std::string& cluster_name, - Upstream::ClusterManager& cluster_manager, +HttpConnPool::HttpConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, Upstream::LoadBalancerContext* context, const TunnelingConfig& config, Tcp::ConnectionPool::UpstreamCallbacks& upstream_callbacks, Http::CodecClient::Type type) : hostname_(config.hostname()), type_(type), upstream_callbacks_(upstream_callbacks) { - // TODO(mattklein123): Pass thread local cluster into this function, removing an additional - // map lookup and moving the error handling closer to the source (where it is likely already - // done). - const auto thread_local_cluster = cluster_manager.getThreadLocalCluster(cluster_name); - if (thread_local_cluster != nullptr) { - conn_pool_ = thread_local_cluster->httpConnPool(Upstream::ResourcePriority::Default, - absl::nullopt, context); - } + conn_pool_ = thread_local_cluster.httpConnPool(Upstream::ResourcePriority::Default, absl::nullopt, + context); } HttpConnPool::~HttpConnPool() { diff --git a/source/common/tcp_proxy/upstream.h b/source/common/tcp_proxy/upstream.h index 8d8a1ad8ef18..1aed24c8093e 100644 --- a/source/common/tcp_proxy/upstream.h +++ b/source/common/tcp_proxy/upstream.h @@ -14,7 +14,7 @@ namespace TcpProxy { class TcpConnPool : public GenericConnPool, public Tcp::ConnectionPool::Callbacks { public: - TcpConnPool(const std::string& cluster_name, Upstream::ClusterManager& cluster_manager, + TcpConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, Upstream::LoadBalancerContext* context, Tcp::ConnectionPool::UpstreamCallbacks& upstream_callbacks); ~TcpConnPool() override; @@ -44,7 +44,7 @@ class HttpConnPool : public GenericConnPool, public Http::ConnectionPool::Callba using TunnelingConfig = envoy::extensions::filters::network::tcp_proxy::v3::TcpProxy_TunnelingConfig; - HttpConnPool(const std::string& cluster_name, Upstream::ClusterManager& cluster_manager, + HttpConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, Upstream::LoadBalancerContext* context, const TunnelingConfig& config, Tcp::ConnectionPool::UpstreamCallbacks& upstream_callbacks, Http::CodecClient::Type type); diff --git a/source/extensions/upstreams/http/generic/config.cc b/source/extensions/upstreams/http/generic/config.cc index 3404f49bf46a..caedb4babd78 100644 --- a/source/extensions/upstreams/http/generic/config.cc +++ b/source/extensions/upstreams/http/generic/config.cc @@ -10,16 +10,17 @@ namespace Http { namespace Generic { Router::GenericConnPoolPtr GenericGenericConnPoolFactory::createGenericConnPool( - Upstream::ClusterManager& cm, bool is_connect, const Router::RouteEntry& route_entry, + Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, + const Router::RouteEntry& route_entry, absl::optional downstream_protocol, Upstream::LoadBalancerContext* ctx) const { if (is_connect) { - auto ret = std::make_unique(cm, is_connect, route_entry, - downstream_protocol, ctx); + auto ret = std::make_unique( + thread_local_cluster, is_connect, route_entry, downstream_protocol, ctx); return (ret->valid() ? std::move(ret) : nullptr); } - auto ret = std::make_unique(cm, is_connect, route_entry, - downstream_protocol, ctx); + auto ret = std::make_unique( + thread_local_cluster, is_connect, route_entry, downstream_protocol, ctx); return (ret->valid() ? std::move(ret) : nullptr); } diff --git a/source/extensions/upstreams/http/generic/config.h b/source/extensions/upstreams/http/generic/config.h index 1c2f1a2f16d3..62f9d72602c7 100644 --- a/source/extensions/upstreams/http/generic/config.h +++ b/source/extensions/upstreams/http/generic/config.h @@ -18,7 +18,7 @@ class GenericGenericConnPoolFactory : public Router::GenericConnPoolFactory { std::string name() const override { return "envoy.filters.connection_pools.http.generic"; } std::string category() const override { return "envoy.upstreams"; } Router::GenericConnPoolPtr - createGenericConnPool(Upstream::ClusterManager& cm, bool is_connect, + createGenericConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, const Router::RouteEntry& route_entry, absl::optional downstream_protocol, Upstream::LoadBalancerContext* ctx) const override; diff --git a/source/extensions/upstreams/http/http/config.cc b/source/extensions/upstreams/http/http/config.cc index e8c933f45216..a6084a1219d8 100644 --- a/source/extensions/upstreams/http/http/config.cc +++ b/source/extensions/upstreams/http/http/config.cc @@ -9,10 +9,12 @@ namespace Http { namespace Http { Router::GenericConnPoolPtr HttpGenericConnPoolFactory::createGenericConnPool( - Upstream::ClusterManager& cm, bool is_connect, const Router::RouteEntry& route_entry, + Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, + const Router::RouteEntry& route_entry, absl::optional downstream_protocol, Upstream::LoadBalancerContext* ctx) const { - auto ret = std::make_unique(cm, is_connect, route_entry, downstream_protocol, ctx); + auto ret = std::make_unique(thread_local_cluster, is_connect, route_entry, + downstream_protocol, ctx); return (ret->valid() ? std::move(ret) : nullptr); } diff --git a/source/extensions/upstreams/http/http/config.h b/source/extensions/upstreams/http/http/config.h index 4c6036ddf3b5..e438999e7dac 100644 --- a/source/extensions/upstreams/http/http/config.h +++ b/source/extensions/upstreams/http/http/config.h @@ -18,7 +18,7 @@ class HttpGenericConnPoolFactory : public Router::GenericConnPoolFactory { std::string name() const override { return "envoy.filters.connection_pools.http.http"; } std::string category() const override { return "envoy.upstreams"; } Router::GenericConnPoolPtr - createGenericConnPool(Upstream::ClusterManager& cm, bool is_connect, + createGenericConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, const Router::RouteEntry& route_entry, absl::optional downstream_protocol, Upstream::LoadBalancerContext* ctx) const override; diff --git a/source/extensions/upstreams/http/http/upstream_request.h b/source/extensions/upstreams/http/http/upstream_request.h index c2c2755f31fc..a83cbddb3dba 100644 --- a/source/extensions/upstreams/http/http/upstream_request.h +++ b/source/extensions/upstreams/http/http/upstream_request.h @@ -20,18 +20,13 @@ namespace Http { class HttpConnPool : public Router::GenericConnPool, public Envoy::Http::ConnectionPool::Callbacks { public: // GenericConnPool - HttpConnPool(Upstream::ClusterManager& cm, bool is_connect, const Router::RouteEntry& route_entry, + HttpConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, + const Router::RouteEntry& route_entry, absl::optional downstream_protocol, Upstream::LoadBalancerContext* ctx) { ASSERT(!is_connect); - // TODO(mattklein123): Pass thread local cluster into this function, removing an additional - // map lookup and moving the error handling closer to the source (where it is likely already - // done). - const auto thread_local_cluster = cm.getThreadLocalCluster(route_entry.clusterName()); - if (thread_local_cluster != nullptr) { - conn_pool_ = - thread_local_cluster->httpConnPool(route_entry.priority(), downstream_protocol, ctx); - } + conn_pool_ = + thread_local_cluster.httpConnPool(route_entry.priority(), downstream_protocol, ctx); } ~HttpConnPool() override { ASSERT(conn_pool_stream_handle_ == nullptr, "conn_pool_stream_handle not null"); diff --git a/source/extensions/upstreams/http/tcp/config.cc b/source/extensions/upstreams/http/tcp/config.cc index 15c01f524af7..8f0df971dc9f 100644 --- a/source/extensions/upstreams/http/tcp/config.cc +++ b/source/extensions/upstreams/http/tcp/config.cc @@ -9,10 +9,12 @@ namespace Http { namespace Tcp { Router::GenericConnPoolPtr TcpGenericConnPoolFactory::createGenericConnPool( - Upstream::ClusterManager& cm, bool is_connect, const Router::RouteEntry& route_entry, + Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, + const Router::RouteEntry& route_entry, absl::optional downstream_protocol, Upstream::LoadBalancerContext* ctx) const { - auto ret = std::make_unique(cm, is_connect, route_entry, downstream_protocol, ctx); + auto ret = std::make_unique(thread_local_cluster, is_connect, route_entry, + downstream_protocol, ctx); return (ret->valid() ? std::move(ret) : nullptr); } diff --git a/source/extensions/upstreams/http/tcp/config.h b/source/extensions/upstreams/http/tcp/config.h index 5ff4df42f5b3..784e8f15b502 100644 --- a/source/extensions/upstreams/http/tcp/config.h +++ b/source/extensions/upstreams/http/tcp/config.h @@ -18,7 +18,7 @@ class TcpGenericConnPoolFactory : public Router::GenericConnPoolFactory { std::string name() const override { return "envoy.filters.connection_pools.http.tcp"; } std::string category() const override { return "envoy.upstreams"; } Router::GenericConnPoolPtr - createGenericConnPool(Upstream::ClusterManager& cm, bool is_connect, + createGenericConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, const Router::RouteEntry& route_entry, absl::optional downstream_protocol, Upstream::LoadBalancerContext* ctx) const override; diff --git a/source/extensions/upstreams/http/tcp/upstream_request.h b/source/extensions/upstreams/http/tcp/upstream_request.h index 1b9f6a238680..2739620e179a 100644 --- a/source/extensions/upstreams/http/tcp/upstream_request.h +++ b/source/extensions/upstreams/http/tcp/upstream_request.h @@ -21,16 +21,11 @@ namespace Tcp { class TcpConnPool : public Router::GenericConnPool, public Envoy::Tcp::ConnectionPool::Callbacks { public: - TcpConnPool(Upstream::ClusterManager& cm, bool is_connect, const Router::RouteEntry& route_entry, - absl::optional, Upstream::LoadBalancerContext* ctx) { + TcpConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, + const Router::RouteEntry& route_entry, absl::optional, + Upstream::LoadBalancerContext* ctx) { ASSERT(is_connect); - // TODO(mattklein123): Pass thread local cluster into this function, removing an additional - // map lookup and moving the error handling closer to the source (where it is likely already - // done). - const auto thread_local_cluster = cm.getThreadLocalCluster(route_entry.clusterName()); - if (thread_local_cluster != nullptr) { - conn_pool_ = thread_local_cluster->tcpConnPool(Upstream::ResourcePriority::Default, ctx); - } + conn_pool_ = thread_local_cluster.tcpConnPool(route_entry.priority(), ctx); } void newStream(Router::GenericConnectionPoolCallbacks* callbacks) override { callbacks_ = callbacks; diff --git a/source/extensions/upstreams/tcp/generic/config.cc b/source/extensions/upstreams/tcp/generic/config.cc index c8c3a53cfdba..1a71c3c5bc04 100644 --- a/source/extensions/upstreams/tcp/generic/config.cc +++ b/source/extensions/upstreams/tcp/generic/config.cc @@ -12,23 +12,20 @@ namespace Tcp { namespace Generic { TcpProxy::GenericConnPoolPtr GenericConnPoolFactory::createGenericConnPool( - const std::string& cluster_name, Upstream::ClusterManager& cluster_manager, + Upstream::ThreadLocalCluster& thread_local_cluster, const absl::optional& config, Upstream::LoadBalancerContext* context, Envoy::Tcp::ConnectionPool::UpstreamCallbacks& upstream_callbacks) const { if (config.has_value()) { - auto* cluster = cluster_manager.getThreadLocalCluster(cluster_name); - if (!cluster) { - return nullptr; - } - auto pool_type = ((cluster->info()->features() & Upstream::ClusterInfo::Features::HTTP2) != 0) - ? Http::CodecClient::Type::HTTP2 - : Http::CodecClient::Type::HTTP1; + auto pool_type = + ((thread_local_cluster.info()->features() & Upstream::ClusterInfo::Features::HTTP2) != 0) + ? Http::CodecClient::Type::HTTP2 + : Http::CodecClient::Type::HTTP1; auto ret = std::make_unique( - cluster_name, cluster_manager, context, config.value(), upstream_callbacks, pool_type); + thread_local_cluster, context, config.value(), upstream_callbacks, pool_type); return (ret->valid() ? std::move(ret) : nullptr); } - auto ret = std::make_unique(cluster_name, cluster_manager, context, - upstream_callbacks); + auto ret = + std::make_unique(thread_local_cluster, context, upstream_callbacks); return (ret->valid() ? std::move(ret) : nullptr); } diff --git a/source/extensions/upstreams/tcp/generic/config.h b/source/extensions/upstreams/tcp/generic/config.h index 5ba6171ac691..36d1d76cb2e0 100644 --- a/source/extensions/upstreams/tcp/generic/config.h +++ b/source/extensions/upstreams/tcp/generic/config.h @@ -18,7 +18,7 @@ class GenericConnPoolFactory : public TcpProxy::GenericConnPoolFactory { std::string name() const override { return "envoy.filters.connection_pools.tcp.generic"; } std::string category() const override { return "envoy.upstreams"; } TcpProxy::GenericConnPoolPtr createGenericConnPool( - const std::string& cluster_name, Upstream::ClusterManager& cm, + Upstream::ThreadLocalCluster& thread_local_cluster, const absl::optional& config, Upstream::LoadBalancerContext* context, Envoy::Tcp::ConnectionPool::UpstreamCallbacks& upstream_callbacks) const override; diff --git a/test/extensions/upstreams/http/tcp/upstream_request_test.cc b/test/extensions/upstreams/http/tcp/upstream_request_test.cc index f921bcbf6336..e0ee478f9306 100644 --- a/test/extensions/upstreams/http/tcp/upstream_request_test.cc +++ b/test/extensions/upstreams/http/tcp/upstream_request_test.cc @@ -40,8 +40,8 @@ class TcpConnPoolTest : public ::testing::Test { NiceMock cm; cm.initializeThreadLocalClusters({"fake_cluster"}); EXPECT_CALL(cm.thread_local_cluster_, tcpConnPool(_, _)).WillOnce(Return(&mock_pool_)); - conn_pool_ = std::make_unique(cm, true, route_entry, Envoy::Http::Protocol::Http11, - nullptr); + conn_pool_ = std::make_unique(cm.thread_local_cluster_, true, route_entry, + Envoy::Http::Protocol::Http11, nullptr); } std::unique_ptr conn_pool_; diff --git a/test/extensions/upstreams/tcp/generic/config_test.cc b/test/extensions/upstreams/tcp/generic/config_test.cc index 844431466216..ffc603614491 100644 --- a/test/extensions/upstreams/tcp/generic/config_test.cc +++ b/test/extensions/upstreams/tcp/generic/config_test.cc @@ -18,18 +18,17 @@ namespace Generic { class TcpConnPoolTest : public ::testing::Test { public: - NiceMock cluster_manager_; - const std::string cluster_name_{"cluster_name"}; + NiceMock thread_local_cluster_; GenericConnPoolFactory factory_; NiceMock callbacks_; }; -TEST_F(TcpConnPoolTest, TestNoMatchingClusterName) { +TEST_F(TcpConnPoolTest, TestNoConnPool) { envoy::extensions::filters::network::tcp_proxy::v3::TcpProxy_TunnelingConfig config; config.set_hostname("host"); - EXPECT_CALL(cluster_manager_, getThreadLocalCluster(_)).WillOnce(Return(nullptr)); - EXPECT_EQ(nullptr, factory_.createGenericConnPool(cluster_name_, cluster_manager_, config, - nullptr, callbacks_)); + EXPECT_CALL(thread_local_cluster_, httpConnPool(_, _, _)).WillOnce(Return(nullptr)); + EXPECT_EQ(nullptr, + factory_.createGenericConnPool(thread_local_cluster_, config, nullptr, callbacks_)); } } // namespace Generic diff --git a/test/integration/upstreams/per_host_upstream_config.h b/test/integration/upstreams/per_host_upstream_config.h index 06095235a4a5..bfa8ba595033 100644 --- a/test/integration/upstreams/per_host_upstream_config.h +++ b/test/integration/upstreams/per_host_upstream_config.h @@ -70,11 +70,11 @@ class PerHostHttpUpstream : public Extensions::Upstreams::Http::Http::HttpUpstre class PerHostHttpConnPool : public Extensions::Upstreams::Http::Http::HttpConnPool { public: - PerHostHttpConnPool(Upstream::ClusterManager& cm, bool is_connect, + PerHostHttpConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, const Router::RouteEntry& route_entry, absl::optional downstream_protocol, Upstream::LoadBalancerContext* ctx) - : HttpConnPool(cm, is_connect, route_entry, downstream_protocol, ctx) {} + : HttpConnPool(thread_local_cluster, is_connect, route_entry, downstream_protocol, ctx) {} void onPoolReady(Envoy::Http::RequestEncoder& callbacks_encoder, Upstream::HostDescriptionConstSharedPtr host, const StreamInfo::StreamInfo& info, @@ -95,7 +95,7 @@ class PerHostGenericConnPoolFactory : public Router::GenericConnPoolFactory { std::string name() const override { return "envoy.filters.connection_pools.http.per_host"; } std::string category() const override { return "envoy.upstreams"; } Router::GenericConnPoolPtr - createGenericConnPool(Upstream::ClusterManager& cm, bool is_connect, + createGenericConnPool(Upstream::ThreadLocalCluster& thread_local_cluster, bool is_connect, const Router::RouteEntry& route_entry, absl::optional downstream_protocol, Upstream::LoadBalancerContext* ctx) const override { @@ -104,7 +104,7 @@ class PerHostGenericConnPoolFactory : public Router::GenericConnPoolFactory { return nullptr; } auto upstream_http_conn_pool = std::make_unique( - cm, is_connect, route_entry, downstream_protocol, ctx); + thread_local_cluster, is_connect, route_entry, downstream_protocol, ctx); return (upstream_http_conn_pool->valid() ? std::move(upstream_http_conn_pool) : nullptr); }