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

http: moving exceptions out of http_server_properties_cache_manager_impl #27829

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
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ HttpServerPropertiesCacheManagerImpl::HttpServerPropertiesCacheManagerImpl(
HttpServerPropertiesCacheSharedPtr HttpServerPropertiesCacheManagerImpl::getCache(
const envoy::config::core::v3::AlternateProtocolsCacheOptions& options,
Event::Dispatcher& dispatcher) {
if (options.has_key_value_store_config() && data_.concurrency_ != 1) {
throw EnvoyException(
fmt::format("options has key value store but Envoy has concurrency = {} : {}",
data_.concurrency_, options.DebugString()));
}

const auto& existing_cache = (*slot_).caches_.find(options.name());
if (existing_cache != (*slot_).caches_.end()) {
if (!Protobuf::util::MessageDifferencer::Equivalent(options, existing_cache->second.options_)) {
throw EnvoyException(fmt::format(
IS_ENVOY_BUG(fmt::format(
"options specified alternate protocols cache '{}' with different settings"
" first '{}' second '{}'",
options.name(), existing_cache->second.options_.DebugString(), options.DebugString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Filter::Filter(const FilterConfigSharedPtr& config, Event::Dispatcher& dispatche
: cache_(config->getAlternateProtocolCache(dispatcher)), time_source_(config->timeSource()) {}

Http::FilterHeadersStatus Filter::encodeHeaders(Http::ResponseHeaderMap& headers, bool) {

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given I've got another PR in this space and github is broken I'll do in my follow up :-)

if (!cache_) {
return Http::FilterHeadersStatus::Continue;
}
Expand Down
14 changes: 11 additions & 3 deletions source/extensions/upstreams/http/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,21 @@ bool useHttp3(const envoy::extensions::upstreams::http::v3::HttpProtocolOptions&

absl::optional<const envoy::config::core::v3::AlternateProtocolsCacheOptions>
getAlternateProtocolsCacheOptions(
const envoy::extensions::upstreams::http::v3::HttpProtocolOptions& options) {
const envoy::extensions::upstreams::http::v3::HttpProtocolOptions& options,
Server::Configuration::ServerFactoryContext& server_context) {
if (options.has_auto_config() && options.auto_config().has_http3_protocol_options()) {
if (!options.auto_config().has_alternate_protocols_cache_options()) {
throw EnvoyException(fmt::format("alternate protocols cache must be configured when HTTP/3 "
"is enabled with auto_config"));
}
return options.auto_config().alternate_protocols_cache_options();
auto cache_options = options.auto_config().alternate_protocols_cache_options();
if (cache_options.has_key_value_store_config() && server_context.options().concurrency() != 1) {
throw EnvoyException(
fmt::format("options has key value store but Envoy has concurrency = {} : {}",
server_context.options().concurrency(), cache_options.DebugString()));
}

return cache_options;
}
return absl::nullopt;
}
Expand Down Expand Up @@ -178,7 +186,7 @@ ProtocolOptionsConfigImpl::ProtocolOptionsConfigImpl(
options.upstream_http_protocol_options())
: absl::nullopt),
http_filters_(options.http_filters()),
alternate_protocol_cache_options_(getAlternateProtocolsCacheOptions(options)),
alternate_protocol_cache_options_(getAlternateProtocolsCacheOptions(options, server_context)),
header_validator_factory_(createHeaderValidatorFactory(options, server_context)),
use_downstream_protocol_(options.has_use_downstream_protocol_config()),
use_http2_(useHttp2(options)), use_http3_(useHttp3(options)),
Expand Down
14 changes: 3 additions & 11 deletions test/common/http/http_server_properties_cache_manager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ TEST_F(HttpServerPropertiesCacheManagerTest, GetCacheWithCanonicalEntry) {
EXPECT_TRUE(cache->findAlternatives(origin).has_value());
}

TEST_F(HttpServerPropertiesCacheManagerTest, GetCacheWithFlushingAndConcurrency) {
EXPECT_CALL(context_.options_, concurrency()).WillOnce(Return(5));
options1_.mutable_key_value_store_config();
initialize();
EXPECT_THROW_WITH_REGEX(manager_->getCache(options1_, dispatcher_), EnvoyException,
"options has key value store but Envoy has concurrency = 5");
}

TEST_F(HttpServerPropertiesCacheManagerTest, GetCacheForDifferentOptions) {
initialize();
HttpServerPropertiesCacheSharedPtr cache1 = manager_->getCache(options1_, dispatcher_);
Expand All @@ -120,9 +112,9 @@ TEST_F(HttpServerPropertiesCacheManagerTest, GetCacheForConflictingOptions) {
initialize();
HttpServerPropertiesCacheSharedPtr cache1 = manager_->getCache(options1_, dispatcher_);
options2_.set_name(options1_.name());
EXPECT_THROW_WITH_REGEX(
manager_->getCache(options2_, dispatcher_), EnvoyException,
"options specified alternate protocols cache 'name1' with different settings.*");
EXPECT_ENVOY_BUG(manager_->getCache(options2_, dispatcher_),
"options specified alternate protocols cache 'name1' with different settings "
"first 'name: \"name1\"");
}

} // namespace
Expand Down
12 changes: 12 additions & 0 deletions test/extensions/upstreams/http/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ TEST_F(ConfigTest, AutoHttp3NoCache) {
"alternate protocols cache must be configured when HTTP/3 is enabled with auto_config");
}

TEST_F(ConfigTest, KvStoreConcurrencyFail) {
options_.mutable_auto_config();
options_.mutable_auto_config()->mutable_http3_protocol_options();
options_.mutable_auto_config()
->mutable_alternate_protocols_cache_options()
->mutable_key_value_store_config();
server_context_.options_.concurrency_ = 2;
EXPECT_THROW_WITH_MESSAGE(
ProtocolOptionsConfigImpl config(options_, server_context_), EnvoyException,
"options has key value store but Envoy has concurrency = 2 : key_value_store_config {\n}\n");
}

namespace {

class TestHeaderValidatorFactoryConfig : public ::Envoy::Http::HeaderValidatorFactoryConfig {
Expand Down
1 change: 0 additions & 1 deletion tools/code_format/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ paths:
- source/common/http/filter_chain_helper.h
- source/common/http/conn_manager_utility.cc
- source/common/http/match_delegate/config.cc
- source/common/http/http_server_properties_cache_manager_impl.cc
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, rad!

- source/common/protobuf/yaml_utility.cc
- source/common/protobuf/visitor_helper.h
- source/common/protobuf/visitor.cc
Expand Down