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

xds: enable the is_optional field for HttpFilter #16119

Merged
merged 16 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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 @@ -911,7 +911,7 @@ message HttpFilter {
// If true, clients that do not support this filter may ignore the
// filter but otherwise accept the config.
// Otherwise, clients that do not support this filter must reject the config.
// [#not-implemented-hide:]
// This is also same with typed per filter config.
bool is_optional = 6;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Removed Config or Runtime

New Features
------------
* http: a new field `is_optional` is added to `extensions.filters.network.http_connection_manager.v3.HttpFilter`. When
value is `true`, the unsupported http filter will be ignored by envoy. This is also same with unsupported http filter
in the typed per filter config. For more information, please reference
:ref:`HttpFilter <envoy_v3_api_field_extensions.filters.network.http_connection_manager.v3.HttpFilter.is_optional>`.

Deprecated
----------

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions include/envoy/router/route_config_provider_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Router {
class RouteConfigProviderManager {
public:
virtual ~RouteConfigProviderManager() = default;
using OptionalHttpFilters = std::set<std::string>;
soulxu marked this conversation as resolved.
Show resolved Hide resolved

/**
* Get a RouteConfigProviderPtr for a route from RDS. Ownership of the RouteConfigProvider is the
Expand All @@ -33,25 +34,29 @@ class RouteConfigProviderManager {
* the RouteConfigProvider. This method creates a RouteConfigProvider which may share the
* underlying RDS subscription with the same (route_config_name, cluster).
* @param rds supplies the proto configuration of an RDS-configured RouteConfigProvider.
* @param optional_http_filters a set of optional http filter names.
* @param factory_context is the context to use for the route config provider.
* @param stat_prefix supplies the stat_prefix to use for the provider stats.
* @param init_manager the Init::Manager used to coordinate initialization of a the underlying RDS
* subscription.
*/
virtual RouteConfigProviderSharedPtr createRdsRouteConfigProvider(
const envoy::extensions::filters::network::http_connection_manager::v3::Rds& rds,
const OptionalHttpFilters& optional_http_filters,
Server::Configuration::ServerFactoryContext& factory_context, const std::string& stat_prefix,
Init::Manager& init_manager) PURE;

/**
* Get a RouteConfigSharedPtr for a statically defined route. Ownership is as described for
* getRdsRouteConfigProvider above. This method always create a new RouteConfigProvider.
* @param route_config supplies the RouteConfiguration for this route
* @param optional_http_filters a set of optional http filter names.
* @param factory_context is the context to use for the route config provider.
* @param validator is the message validator for route config.
*/
virtual RouteConfigProviderPtr
createStaticRouteConfigProvider(const envoy::config::route::v3::RouteConfiguration& route_config,
const OptionalHttpFilters& optional_http_filters,
Server::Configuration::ServerFactoryContext& factory_context,
ProtobufMessage::ValidationVisitor& validator) PURE;
};
Expand Down
46 changes: 46 additions & 0 deletions source/common/config/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,29 @@ class Utility {
return *factory;
}

/**
* Get a Factory from the registry with a particular name (and templated type) with error checking
* to ensure the name and factory are valid.
* @param name string identifier for the particular implementation.
* @param is_optional exception will be throw when the value is false and no factory found.
* @return factory the factory requested or nullptr if it does not exist.
*/
template <class Factory>
static Factory* getAndCheckFactoryByName(const std::string& name, bool is_optional) {
soulxu marked this conversation as resolved.
Show resolved Hide resolved
if (name.empty()) {
ExceptionUtil::throwEnvoyException("Provided name for static registration lookup was empty.");
}

Factory* factory = Registry::FactoryRegistry<Factory>::getFactory(name);

if (factory == nullptr && !is_optional) {
ExceptionUtil::throwEnvoyException(
fmt::format("Didn't find a registered implementation for name: '{}'", name));
}

return factory;
}

/**
* Get a Factory from the registry with a particular name or return nullptr.
* @param name string identifier for the particular implementation.
Expand Down Expand Up @@ -307,6 +330,29 @@ class Utility {
return Utility::getAndCheckFactoryByName<Factory>(message.name());
}

/**
* Get a Factory from the registry with error checking to ensure the name and the factory are
* valid. And a flag to control return nullptr or throw an exception.
* @param message proto that contains fields 'name' and 'typed_config'.
* @param is_optional an exception will be throw when the value is true and no factory found.
* @return factory the factory requested or nullptr if it does not exist.
*/
template <class Factory, class ProtoMessage>
static Factory* getAndCheckFactory(const ProtoMessage& message, bool is_optional) {
soulxu marked this conversation as resolved.
Show resolved Hide resolved
Factory* factory = Utility::getFactoryByType<Factory>(message.typed_config());
if (factory != nullptr) {
return factory;
}

factory = Utility::getFactoryByName<Factory>(message.name());

if (factory == nullptr && !is_optional) {
ExceptionUtil::throwEnvoyException(
fmt::format("Didn't find a registered implementation for name: '{}'", message.name()));
}
return factory;
}

/**
* Get type URL from a typed config.
* @param typed_config for the extension config.
Expand Down
Loading