diff --git a/source/common/upstream/upstream_impl.cc b/source/common/upstream/upstream_impl.cc index dbea77ba8aed..18025dfca211 100644 --- a/source/common/upstream/upstream_impl.cc +++ b/source/common/upstream/upstream_impl.cc @@ -76,37 +76,6 @@ getSourceAddress(const envoy::config::cluster::v3::Cluster& cluster, return nullptr; } -// TODO(alyssawilk) move this to the new config library in a follow-up. -uint64_t -parseFeatures(const envoy::config::cluster::v3::Cluster& config, - std::shared_ptr options) { - uint64_t features = 0; - - if (options) { - if (options->use_http2_) { - features |= ClusterInfoImpl::Features::HTTP2; - } - if (options->use_downstream_protocol_) { - features |= ClusterInfoImpl::Features::USE_DOWNSTREAM_PROTOCOL; - } - } else { - if (config.has_http2_protocol_options()) { - features |= ClusterInfoImpl::Features::HTTP2; - } - if (config.protocol_selection() == - envoy::config::cluster::v3::Cluster::USE_DOWNSTREAM_PROTOCOL) { - features |= ClusterInfoImpl::Features::USE_DOWNSTREAM_PROTOCOL; - } - } - if (config.close_connections_on_host_health_failure()) { - features |= ClusterInfoImpl::Features::CLOSE_CONNECTIONS_ON_HOST_HEALTH_FAILURE; - } - if (options->use_alpn_) { - features |= ClusterInfoImpl::Features::USE_ALPN; - } - return features; -} - Network::TcpKeepaliveConfig parseTcpKeepaliveConfig(const envoy::config::cluster::v3::Cluster& config) { const envoy::config::core::v3::TcpKeepalive& options = @@ -758,7 +727,8 @@ ClusterInfoImpl::ClusterInfoImpl( ? std::make_unique( config, *stats_scope_, factory_context.clusterManager()) : nullptr), - features_(parseFeatures(config, http_protocol_options_)), + features_(ClusterInfoImpl::HttpProtocolOptionsConfigImpl::parseFeatures( + config, http_protocol_options_)), resource_managers_(config, runtime, name_, *stats_scope_, factory_context.clusterManager().clusterCircuitBreakersStatNames()), maintenance_mode_runtime_key_(absl::StrCat("upstream.maintenance_mode.", name_)), diff --git a/source/extensions/upstreams/http/BUILD b/source/extensions/upstreams/http/BUILD index dfcb89550037..cfcf0b407f97 100644 --- a/source/extensions/upstreams/http/BUILD +++ b/source/extensions/upstreams/http/BUILD @@ -21,6 +21,7 @@ envoy_cc_extension( "//source/common/config:utility_lib", "//source/common/http:utility_lib", "//source/common/protobuf:utility_lib", + "@envoy_api//envoy/config/cluster/v3:pkg_cc_proto", "@envoy_api//envoy/config/core/v3:pkg_cc_proto", "@envoy_api//envoy/extensions/upstreams/http/v3:pkg_cc_proto", ], diff --git a/source/extensions/upstreams/http/config.cc b/source/extensions/upstreams/http/config.cc index 7ea60a9f4362..6d8a8090c738 100644 --- a/source/extensions/upstreams/http/config.cc +++ b/source/extensions/upstreams/http/config.cc @@ -5,7 +5,9 @@ #include #include +#include "envoy/config/cluster/v3/cluster.pb.h" #include "envoy/config/core/v3/base.pb.h" +#include "envoy/upstream/upstream.h" #include "common/config/utility.h" #include "common/http/utility.h" @@ -41,6 +43,36 @@ getHttp2Options(const envoy::extensions::upstreams::http::v3::HttpProtocolOption } // namespace +uint64_t +ProtocolOptionsConfigImpl::parseFeatures(const envoy::config::cluster::v3::Cluster& config, + std::shared_ptr options) { + uint64_t features = 0; + + if (options) { + if (options->use_http2_) { + features |= Upstream::ClusterInfo::Features::HTTP2; + } + if (options->use_downstream_protocol_) { + features |= Upstream::ClusterInfo::Features::USE_DOWNSTREAM_PROTOCOL; + } + } else { + if (config.has_http2_protocol_options()) { + features |= Upstream::ClusterInfo::Features::HTTP2; + } + if (config.protocol_selection() == + envoy::config::cluster::v3::Cluster::USE_DOWNSTREAM_PROTOCOL) { + features |= Upstream::ClusterInfo::Features::USE_DOWNSTREAM_PROTOCOL; + } + } + if (config.close_connections_on_host_health_failure()) { + features |= Upstream::ClusterInfo::Features::CLOSE_CONNECTIONS_ON_HOST_HEALTH_FAILURE; + } + if (options->use_alpn_) { + features |= Upstream::ClusterInfo::Features::USE_ALPN; + } + return features; +} + ProtocolOptionsConfigImpl::ProtocolOptionsConfigImpl( const envoy::extensions::upstreams::http::v3::HttpProtocolOptions& options) : http1_settings_(Envoy::Http::Utility::parseHttp1Settings(getHttpOptions(options))), diff --git a/source/extensions/upstreams/http/config.h b/source/extensions/upstreams/http/config.h index 03ab635cc7c7..cb4a1cb0dca9 100644 --- a/source/extensions/upstreams/http/config.h +++ b/source/extensions/upstreams/http/config.h @@ -34,6 +34,11 @@ class ProtocolOptionsConfigImpl : public Upstream::ProtocolOptionsConfig { const absl::optional upstream_options, bool use_downstream_protocol, bool use_http2); + // Given the supplied cluster config, and protocol options configuration, + // returns a unit64_t representing the enabled Upstream::ClusterInfo::Features. + static uint64_t parseFeatures(const envoy::config::cluster::v3::Cluster& config, + std::shared_ptr options); + const Envoy::Http::Http1Settings http1_settings_; const envoy::config::core::v3::Http2ProtocolOptions http2_options_; const envoy::config::core::v3::HttpProtocolOptions common_http_protocol_options_;