Skip to content

Commit

Permalink
hcm: making exception free (#37521)
Browse files Browse the repository at this point in the history
Risk Level: low
Testing: updated tests
Docs Changes: n/a
Release Notes: n/a
envoyproxy/envoy-mobile#176

Signed-off-by: Alyssa Wilk <[email protected]>
  • Loading branch information
alyssawilk authored Dec 11, 2024
1 parent f38f6e3 commit 8abdde3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
28 changes: 13 additions & 15 deletions source/extensions/filters/network/http_connection_manager/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,12 @@ HttpConnectionManagerFilterConfigFactory::createFilterFactoryFromProtoAndHopByHo
Server::Configuration::FactoryContext& context, bool clear_hop_by_hop_headers) {
Utility::Singletons singletons = Utility::createSingletons(context);

auto filter_config = THROW_OR_RETURN_VALUE(
Utility::createConfig(proto_config, context, *singletons.date_provider_,
*singletons.route_config_provider_manager_,
singletons.scoped_routes_config_provider_manager_.get(),
*singletons.tracer_manager_,
*singletons.filter_config_provider_manager_),
std::shared_ptr<HttpConnectionManagerConfig>);
auto config_or_error = Utility::createConfig(
proto_config, context, *singletons.date_provider_, *singletons.route_config_provider_manager_,
singletons.scoped_routes_config_provider_manager_.get(), *singletons.tracer_manager_,
*singletons.filter_config_provider_manager_);
RETURN_IF_NOT_OK_REF(config_or_error.status());
auto filter_config = std::move(*config_or_error);

// This lambda captures the shared_ptrs created above, thus preserving the
// reference count.
Expand Down Expand Up @@ -867,20 +866,19 @@ HttpConnectionManagerConfig::getHeaderValidatorStats([[maybe_unused]] Http::Prot
}
#endif

std::function<Http::ApiListenerPtr(Network::ReadFilterCallbacks&)>
absl::StatusOr<std::function<Http::ApiListenerPtr(Network::ReadFilterCallbacks&)>>
HttpConnectionManagerFactory::createHttpConnectionManagerFactoryFromProto(
const envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
proto_config,
Server::Configuration::FactoryContext& context, bool clear_hop_by_hop_headers) {
Utility::Singletons singletons = Utility::createSingletons(context);

auto filter_config = THROW_OR_RETURN_VALUE(
Utility::createConfig(proto_config, context, *singletons.date_provider_,
*singletons.route_config_provider_manager_,
singletons.scoped_routes_config_provider_manager_.get(),
*singletons.tracer_manager_,
*singletons.filter_config_provider_manager_),
std::shared_ptr<HttpConnectionManagerConfig>);
auto config_or_error = Utility::createConfig(
proto_config, context, *singletons.date_provider_, *singletons.route_config_provider_manager_,
singletons.scoped_routes_config_provider_manager_.get(), *singletons.tracer_manager_,
*singletons.filter_config_provider_manager_);
RETURN_IF_NOT_OK_REF(config_or_error.status());
auto filter_config = std::move(*config_or_error);

// This lambda captures the shared_ptrs created above, thus preserving the
// reference count.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class HttpConnectionManagerConfig : Logger::Loggable<Logger::Id::config>,
*/
class HttpConnectionManagerFactory {
public:
static std::function<Http::ApiListenerPtr(Network::ReadFilterCallbacks&)>
static absl::StatusOr<std::function<Http::ApiListenerPtr(Network::ReadFilterCallbacks&)>>
createHttpConnectionManagerFactoryFromProto(
const envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
proto_config,
Expand Down
18 changes: 13 additions & 5 deletions source/server/api_listener_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ HttpApiListener::create(const envoy::config::listener::v3::Listener& config,
Server::Instance& server, const std::string& name) {
auto address_or_error = Network::Address::resolveProtoAddress(config.address());
RETURN_IF_NOT_OK_REF(address_or_error.status());
return std::unique_ptr<HttpApiListener>(
new HttpApiListener(std::move(address_or_error.value()), config, server, name));
absl::Status creation_status = absl::OkStatus();
auto ret = std::unique_ptr<HttpApiListener>(new HttpApiListener(
std::move(address_or_error.value()), config, server, name, creation_status));
RETURN_IF_NOT_OK_REF(creation_status);
return ret;
}

HttpApiListener::HttpApiListener(Network::Address::InstanceConstSharedPtr&& address,
const envoy::config::listener::v3::Listener& config,
Server::Instance& server, const std::string& name)
Server::Instance& server, const std::string& name,
absl::Status& creation_status)
: ApiListenerImplBase(std::move(address), config, server, name) {
if (config.api_listener().api_listener().type_url() ==
absl::StrCat(
Expand All @@ -66,17 +70,21 @@ HttpApiListener::HttpApiListener(Network::Address::InstanceConstSharedPtr&& addr
EnvoyMobileHttpConnectionManager>(config.api_listener().api_listener(),
factory_context_.messageValidationVisitor());

http_connection_manager_factory_ = Envoy::Extensions::NetworkFilters::HttpConnectionManager::
auto factory_or_error = Envoy::Extensions::NetworkFilters::HttpConnectionManager::
HttpConnectionManagerFactory::createHttpConnectionManagerFactoryFromProto(
typed_config.config(), factory_context_, false);
SET_AND_RETURN_IF_NOT_OK(factory_or_error.status(), creation_status);
http_connection_manager_factory_ = std::move(*factory_or_error);
} else {
auto typed_config = MessageUtil::anyConvertAndValidate<
envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager>(
config.api_listener().api_listener(), factory_context_.messageValidationVisitor());

http_connection_manager_factory_ =
auto factory_or_error =
Envoy::Extensions::NetworkFilters::HttpConnectionManager::HttpConnectionManagerFactory::
createHttpConnectionManagerFactoryFromProto(typed_config, factory_context_, true);
SET_AND_RETURN_IF_NOT_OK(factory_or_error.status(), creation_status);
http_connection_manager_factory_ = std::move(*factory_or_error);
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/server/api_listener_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class HttpApiListener : public ApiListenerImplBase {
private:
HttpApiListener(Network::Address::InstanceConstSharedPtr&& address,
const envoy::config::listener::v3::Listener& config, Server::Instance& server,
const std::string& name);
const std::string& name, absl::Status& creation_status);

// Need to store the factory due to the shared_ptrs that need to be kept alive: date provider,
// route config manager, scoped route config manager.
Expand Down
13 changes: 12 additions & 1 deletion tools/code_format/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,18 @@ paths:
- source/extensions/filters/http/ratelimit
- source/extensions/filters/http/oauth2
- source/extensions/filters/http/wasm
- source/extensions/filters/network
- source/extensions/filters/network/dubbo_proxy
- source/extensions/filters/network/rbac
- source/extensions/filters/network/sni_dynamic_forward_proxy
- source/extensions/filters/network/common
- source/extensions/filters/network/redis_proxy
- source/extensions/filters/network/zookeeper_proxy
- source/extensions/filters/network/ext_authz
- source/extensions/filters/network/mongo_proxy
- source/extensions/filters/network/thrift_proxy
- source/extensions/filters/network/direct_response
- source/extensions/filters/network/generic_proxy
- source/extensions/filters/network/ratelimit
- source/extensions/filters/common
- source/extensions/filters/udp
- source/extensions/filters/listener
Expand Down

0 comments on commit 8abdde3

Please sign in to comment.