Skip to content

router: deprecate optional http filters and add route/vh level is_optional support in the typed_per_filter_config #27263

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

Merged
merged 20 commits into from
Jun 1, 2023
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
3 changes: 2 additions & 1 deletion api/envoy/config/route/v3/route_components.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,6 @@ message InternalRedirectPolicy {
// :ref:`Route.typed_per_filter_config<envoy_v3_api_field_config.route.v3.Route.typed_per_filter_config>`,
// or :ref:`WeightedCluster.ClusterWeight.typed_per_filter_config<envoy_v3_api_field_config.route.v3.WeightedCluster.ClusterWeight.typed_per_filter_config>`
// to add additional flags to the filter.
// [#not-implemented-hide:]
message FilterConfig {
// The filter config.
google.protobuf.Any config = 1;
Expand All @@ -2398,5 +2397,7 @@ message FilterConfig {
// created and it is too late to change the chain.
//
// This field only make sense for the downstream HTTP filters for now.
//
// [#not-implemented-hide:]
bool disabled = 3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,6 @@ 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.
// This is also same with typed per filter config.
bool is_optional = 6;
}

Expand Down
18 changes: 18 additions & 0 deletions changelogs/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ bug_fixes:
Fixed the bug that updating :ref:`scope_key_builder
<envoy_v3_api_field_extensions.filters.network.http_connection_manager.v3.ScopedRoutes.scope_key_builder>`
of SRDS config doesn't work and multiple HCM share the same ``scope_key_builder``.
- area: http
change: |
The :ref:`is_optional
<envoy_v3_api_field_extensions.filters.network.http_connection_manager.v3.HttpFilter.is_optional>`
field of HTTP filter can only be used for configuration loading of
:ref:`HTTP filter <envoy_v3_api_msg_extensions.filters.network.http_connection_manager.v3.HttpFilter>`
and will be ignored for loading of route or virtual host level filter config. This behavioral change
can be temporarily reverted by setting runtime guard
``envoy.reloadable_features.ignore_optional_option_from_hcm_for_route_config`` to false.
You can also use
:ref:`route/virtual host optional flag <envoy_v3_api_field_config.route.v3.FilterConfig.is_optional>`
as a replacement of the feature.
- area: logging
change: |
Do not display GRPC_STATUS_NUMBER for non gRPC requests.
Expand Down Expand Up @@ -238,6 +250,12 @@ new_features:
- area: admin
change: |
Adds a new admin stats html bucket-mode ``detailed`` to generate all recorded buckets and summary percentiles.
- area: http
change: |
Add support to the route/virtual host level
:ref:`is_optional <envoy_v3_api_field_config.route.v3.FilterConfig.is_optional>` field.
A route/virtual host level per filter config can be marked as optional, which means that if
the filter fails to load, the configuration will no be rejected.
- area: upstream
change: |
Added :ref:`cluster provided extension
Expand Down
57 changes: 48 additions & 9 deletions source/common/router/config_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2104,11 +2104,10 @@ RouteConstSharedPtr ConfigImpl::route(const RouteCallback& cb,
}

RouteSpecificFilterConfigConstSharedPtr PerFilterConfigs::createRouteSpecificFilterConfig(
const std::string& name, const ProtobufWkt::Any& typed_config,
const OptionalHttpFilters& optional_http_filters,
const std::string& name, const ProtobufWkt::Any& typed_config, bool is_optional,
Server::Configuration::ServerFactoryContext& factory_context,
ProtobufMessage::ValidationVisitor& validator) {
bool is_optional = (optional_http_filters.find(name) != optional_http_filters.end());

Server::Configuration::NamedHttpFilterConfigFactory* factory =
Envoy::Config::Utility::getFactoryByType<Server::Configuration::NamedHttpFilterConfigFactory>(
typed_config);
Expand Down Expand Up @@ -2148,12 +2147,52 @@ PerFilterConfigs::PerFilterConfigs(
const OptionalHttpFilters& optional_http_filters,
Server::Configuration::ServerFactoryContext& factory_context,
ProtobufMessage::ValidationVisitor& validator) {
for (const auto& it : typed_configs) {
const auto& name = it.first;
auto object = createRouteSpecificFilterConfig(name, it.second, optional_http_filters,
factory_context, validator);
if (object != nullptr) {
configs_[name] = std::move(object);

const bool ignore_optional_option_from_hcm_for_route_config(Runtime::runtimeFeatureEnabled(
"envoy.reloadable_features.ignore_optional_option_from_hcm_for_route_config"));

absl::string_view filter_config_type =
envoy::config::route::v3::FilterConfig::default_instance().GetDescriptor()->full_name();

for (const auto& per_filter_config : typed_configs) {
const std::string& name = per_filter_config.first;
RouteSpecificFilterConfigConstSharedPtr config;

// There are two ways to mark a route/virtual host per filter configuration as optional:
// 1. Mark it as optional in the HTTP filter of HCM. This way is deprecated but still works
// when the runtime flag
// `envoy.reloadable_features.ignore_optional_option_from_hcm_for_route_config`
// is explicitly set to false.
// 2. Mark it as optional in the route/virtual host per filter configuration. This way is
// recommended.
//
// We check the first way first to ensure if this filter configuration is marked as optional
// or not. This will be true if the runtime flag is explicitly reverted to false and the
// config name is in the optional http filter list.
bool is_optional_by_hcm = !ignore_optional_option_from_hcm_for_route_config &&
(optional_http_filters.find(name) != optional_http_filters.end());

if (TypeUtil::typeUrlToDescriptorFullName(per_filter_config.second.type_url()) ==
filter_config_type) {
envoy::config::route::v3::FilterConfig filter_config;
Envoy::Config::Utility::translateOpaqueConfig(per_filter_config.second, validator,
filter_config);

if (!filter_config.has_config()) {
throw EnvoyException(
fmt::format("Empty route/virtual host per filter configuration for {} filter", name));
}

config = createRouteSpecificFilterConfig(name, filter_config.config(),
is_optional_by_hcm || filter_config.is_optional(),
factory_context, validator);
} else {
config = createRouteSpecificFilterConfig(name, per_filter_config.second, is_optional_by_hcm,
factory_context, validator);
}

if (config != nullptr) {
configs_[name] = std::move(config);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions source/common/router/config_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ class PerFilterConfigs : public Logger::Loggable<Logger::Id::http> {
private:
RouteSpecificFilterConfigConstSharedPtr
createRouteSpecificFilterConfig(const std::string& name, const ProtobufWkt::Any& typed_config,
const OptionalHttpFilters& optional_http_filters,
bool is_optional,
Server::Configuration::ServerFactoryContext& factory_context,
ProtobufMessage::ValidationVisitor& validator);

absl::node_hash_map<std::string, RouteSpecificFilterConfigConstSharedPtr> configs_;
};

Expand Down
1 change: 1 addition & 0 deletions source/common/runtime/runtime_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ RUNTIME_GUARD(envoy_reloadable_features_http_ext_auth_failure_mode_allow_header_
RUNTIME_GUARD(envoy_reloadable_features_http_filter_avoid_reentrant_local_reply);
RUNTIME_GUARD(envoy_reloadable_features_http_reject_path_with_fragment);
RUNTIME_GUARD(envoy_reloadable_features_http_strip_fragment_from_path_unsafe_if_disabled);
RUNTIME_GUARD(envoy_reloadable_features_ignore_optional_option_from_hcm_for_route_config);
RUNTIME_GUARD(envoy_reloadable_features_initialize_upstream_filters);
RUNTIME_GUARD(envoy_reloadable_features_no_extension_lookup_by_name);
RUNTIME_GUARD(envoy_reloadable_features_no_full_scan_certs_on_sni_mismatch);
Expand Down
2 changes: 2 additions & 0 deletions test/common/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ envoy_cc_test(
"//test/mocks/server:instance_mocks",
"//test/mocks/thread_local:thread_local_mocks",
"//test/test_common:simulated_time_system_lib",
"//test/test_common:test_runtime_lib",
"//test/test_common:utility_lib",
"@envoy_api//envoy/admin/v3:pkg_cc_proto",
"@envoy_api//envoy/config/route/v3:pkg_cc_proto",
Expand Down Expand Up @@ -169,6 +170,7 @@ envoy_cc_test(
"//test/mocks/router:router_mocks",
"//test/mocks/server:instance_mocks",
"//test/test_common:simulated_time_system_lib",
"//test/test_common:test_runtime_lib",
"//test/test_common:utility_lib",
"@envoy_api//envoy/admin/v3:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
Expand Down
137 changes: 136 additions & 1 deletion test/common/router/config_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10288,6 +10288,11 @@ TEST_F(PerFilterConfigsTest, DefaultFilterImplementationAnyWithCheckPerVirtualHo
}

TEST_F(PerFilterConfigsTest, OptionalDefaultFilterImplementationAnyWithCheckPerVirtualHost) {
// TODO(wbpcode): This test should be removed once the deprecated flag is removed.
TestScopedRuntime scoped_runtime;
scoped_runtime.mergeValues(
{{"envoy.reloadable_features.ignore_optional_option_from_hcm_for_route_config", "false"}});

const std::string yaml = R"EOF(
virtual_hosts:
- name: bar
Expand Down Expand Up @@ -10330,6 +10335,11 @@ TEST_F(PerFilterConfigsTest, DefaultFilterImplementationAnyWithCheckPerRoute) {
}

TEST_F(PerFilterConfigsTest, OptionalDefaultFilterImplementationAnyWithCheckPerRoute) {
// TODO(wbpcode): This test should be removed once the deprecated flag is removed.
TestScopedRuntime scoped_runtime;
scoped_runtime.mergeValues(
{{"envoy.reloadable_features.ignore_optional_option_from_hcm_for_route_config", "false"}});

const std::string yaml = R"EOF(
virtual_hosts:
- name: bar
Expand Down Expand Up @@ -10369,6 +10379,11 @@ TEST_F(PerFilterConfigsTest, PerVirtualHostWithUnknownFilter) {
}

TEST_F(PerFilterConfigsTest, PerVirtualHostWithOptionalUnknownFilter) {
// TODO(wbpcode): This test should be removed once the deprecated flag is removed.
TestScopedRuntime scoped_runtime;
scoped_runtime.mergeValues(
{{"envoy.reloadable_features.ignore_optional_option_from_hcm_for_route_config", "false"}});

const std::string yaml = R"EOF(
virtual_hosts:
- name: bar
Expand Down Expand Up @@ -10406,7 +10421,12 @@ TEST_F(PerFilterConfigsTest, PerRouteWithUnknownFilter) {
"'google.protobuf.BoolValue'");
}

TEST_F(PerFilterConfigsTest, PerRouteWithOptionalUnknownFilter) {
TEST_F(PerFilterConfigsTest, PerRouteWithHcmOptionalUnknownFilterLegacy) {
// TODO(wbpcode): This test should be removed once the deprecated flag is removed.
TestScopedRuntime scoped_runtime;
scoped_runtime.mergeValues(
{{"envoy.reloadable_features.ignore_optional_option_from_hcm_for_route_config", "false"}});

const std::string yaml = R"EOF(
virtual_hosts:
- name: bar
Expand All @@ -10425,6 +10445,121 @@ TEST_F(PerFilterConfigsTest, PerRouteWithOptionalUnknownFilter) {
checkNoPerFilterConfig(yaml, "filter.unknown", optional_http_filters);
}

TEST_F(PerFilterConfigsTest, PerRouteWithHcmOptionalUnknownFilter) {
const std::string yaml = R"EOF(
virtual_hosts:
- name: bar
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: baz }
typed_per_filter_config:
filter.unknown:
"@type": type.googleapis.com/google.protobuf.BoolValue
)EOF";

factory_context_.cluster_manager_.initializeClusters({"baz"}, {});
OptionalHttpFilters optional_http_filters;
optional_http_filters.insert("filter.unknown");

EXPECT_THROW_WITH_MESSAGE(
TestConfigImpl(parseRouteConfigurationFromYaml(yaml), factory_context_, true,
optional_http_filters),
EnvoyException,
"Didn't find a registered implementation for 'filter.unknown' with type URL: "
"'google.protobuf.BoolValue'");
}

TEST_F(PerFilterConfigsTest, OptionalDefaultFilterImplementationAny) {
const std::string yaml = R"EOF(
typed_per_filter_config:
test.default.filter:
"@type": type.googleapis.com/envoy.config.route.v3.FilterConfig
is_optional: true
config:
"@type": type.googleapis.com/google.protobuf.Struct
value:
seconds: 123
virtual_hosts:
- name: bar
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: baz }
typed_per_filter_config:
test.default.filter:
"@type": type.googleapis.com/envoy.config.route.v3.FilterConfig
is_optional: true
config:
"@type": type.googleapis.com/google.protobuf.Struct
value:
seconds: 123
typed_per_filter_config:
test.default.filter:
"@type": type.googleapis.com/envoy.config.route.v3.FilterConfig
is_optional: true
config:
"@type": type.googleapis.com/google.protobuf.Struct
value:
seconds: 123
)EOF";

factory_context_.cluster_manager_.initializeClusters({"baz"}, {});
checkNoPerFilterConfig(yaml, "filter.unknown");
}

TEST_F(PerFilterConfigsTest, OptionalUnknownFilter) {
const std::string yaml = R"EOF(
typed_per_filter_config:
filter.unknown:
"@type": type.googleapis.com/envoy.config.route.v3.FilterConfig
is_optional: true
config:
"@type": type.googleapis.com/google.protobuf.BoolValue
virtual_hosts:
- name: bar
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: baz }
typed_per_filter_config:
filter.unknown:
"@type": type.googleapis.com/envoy.config.route.v3.FilterConfig
is_optional: true
config:
"@type": type.googleapis.com/google.protobuf.BoolValue
typed_per_filter_config:
filter.unknown:
"@type": type.googleapis.com/envoy.config.route.v3.FilterConfig
is_optional: true
config:
"@type": type.googleapis.com/google.protobuf.BoolValue
)EOF";

factory_context_.cluster_manager_.initializeClusters({"baz"}, {});
checkNoPerFilterConfig(yaml, "filter.unknown");
}

TEST_F(PerFilterConfigsTest, FilterConfigWithoutConfig) {
const std::string yaml = R"EOF(
virtual_hosts:
- name: bar
domains: ["*"]
routes:
- match: { prefix: "/" }
route: { cluster: baz }
typed_per_filter_config:
filter.unknown:
"@type": type.googleapis.com/envoy.config.route.v3.FilterConfig
is_optional: true
)EOF";

EXPECT_THROW_WITH_MESSAGE(
TestConfigImpl(parseRouteConfigurationFromYaml(yaml), factory_context_, false),
EnvoyException,
"Empty route/virtual host per filter configuration for filter.unknown filter");
}

TEST_F(PerFilterConfigsTest, RouteLocalTypedConfig) {
const std::string yaml = R"EOF(
typed_per_filter_config:
Expand Down
Loading