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

upstream: clean up code location #14580

Merged
merged 2 commits into from
Jan 7, 2021
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
34 changes: 2 additions & 32 deletions source/common/upstream/upstream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<const ClusterInfoImpl::HttpProtocolOptionsConfigImpl> 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 =
Expand Down Expand Up @@ -758,7 +727,8 @@ ClusterInfoImpl::ClusterInfoImpl(
? std::make_unique<OptionalClusterStats>(
config, *stats_scope_, factory_context.clusterManager())
: nullptr),
features_(parseFeatures(config, http_protocol_options_)),
features_(ClusterInfoImpl::HttpProtocolOptionsConfigImpl::parseFeatures(
config, http_protocol_options_)),
Comment on lines +730 to +731
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems odd to me that we are calling into extension code still in the upstream code? But I guess that is unavoidable due to legacy design here? (Ultimately it would be nice if the core cluster code had no real understanding of HTTP but that is probably a bit too asipirational for now.)

resource_managers_(config, runtime, name_, *stats_scope_,
factory_context.clusterManager().clusterCircuitBreakersStatNames()),
maintenance_mode_runtime_key_(absl::StrCat("upstream.maintenance_mode.", name_)),
Expand Down
1 change: 1 addition & 0 deletions source/extensions/upstreams/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
32 changes: 32 additions & 0 deletions source/extensions/upstreams/http/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <string>
#include <vector>

#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"
Expand Down Expand Up @@ -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<const ProtocolOptionsConfigImpl> 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))),
Expand Down
5 changes: 5 additions & 0 deletions source/extensions/upstreams/http/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class ProtocolOptionsConfigImpl : public Upstream::ProtocolOptionsConfig {
const absl::optional<envoy::config::core::v3::UpstreamHttpProtocolOptions> 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<const ProtocolOptionsConfigImpl> 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_;
Expand Down