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 feature parsing code #14629

Merged
merged 3 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions source/common/upstream/upstream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,8 @@ ClusterInfoImpl::ClusterInfoImpl(
? std::make_unique<OptionalClusterStats>(
config, *stats_scope_, factory_context.clusterManager())
: nullptr),
features_(ClusterInfoImpl::HttpProtocolOptionsConfigImpl::parseFeatures(
config, http_protocol_options_)),
features_(
ClusterInfoImpl::HttpProtocolOptionsConfigImpl::parseFeatures(*http_protocol_options_)),
resource_managers_(config, runtime, name_, *stats_scope_,
factory_context.clusterManager().clusterCircuitBreakersStatNames()),
maintenance_mode_runtime_key_(absl::StrCat("upstream.maintenance_mode.", name_)),
Expand Down
28 changes: 7 additions & 21 deletions source/extensions/upstreams/http/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,19 @@ 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 ProtocolOptionsConfigImpl::parseFeatures(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 (options.use_http2_) {
features |= Upstream::ClusterInfo::Features::HTTP2;
}
if (config.close_connections_on_host_health_failure()) {
features |= Upstream::ClusterInfo::Features::CLOSE_CONNECTIONS_ON_HOST_HEALTH_FAILURE;
if (options.use_downstream_protocol_) {
features |= Upstream::ClusterInfo::Features::USE_DOWNSTREAM_PROTOCOL;
}
if (options->use_alpn_) {
if (options.use_alpn_) {
features |= Upstream::ClusterInfo::Features::USE_ALPN;
}

return features;
}

Expand Down
7 changes: 3 additions & 4 deletions source/extensions/upstreams/http/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ 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);
// Given the supplied protocol options configuration, returns a unit64_t representing the enabled
// Upstream::ClusterInfo::Features.
static uint64_t parseFeatures(const ProtocolOptionsConfigImpl& options);

const Envoy::Http::Http1Settings http1_settings_;
const envoy::config::core::v3::Http2ProtocolOptions http2_options_;
Expand Down
4 changes: 4 additions & 0 deletions test/common/upstream/cluster_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ TEST_F(ClusterManagerImplTest, MultipleProtocolCluster) {
protocol_selection: USE_DOWNSTREAM_PROTOCOL
)EOF";
create(parseBootstrapFromV3Yaml(yaml));
auto info =
cluster_manager_->clusters().active_clusters_.find("http12_cluster")->second.get().info();
EXPECT_NE(0, info->features() & Upstream::ClusterInfo::Features::USE_DOWNSTREAM_PROTOCOL);

checkConfigDump(R"EOF(
static_clusters:
- cluster:
Expand Down