@ -7745,24 +7745,6 @@ TEST_P(RlsTest, XdsRoutingClusterSpecifierPlugin) {
TEST_P ( RlsTest , XdsRoutingClusterSpecifierPluginNacksUndefinedSpecifier ) {
gpr_setenv ( " GRPC_EXPERIMENTAL_XDS_RLS_LB " , " true " ) ;
const char * kNewClusterName = " new_cluster " ;
const char * kNewEdsServiceName = " new_eds_service_name " ;
// Populate new EDS resources.
EdsResourceArgs args ( {
{ " locality0 " , CreateEndpointsForBackends ( 0 , 1 ) } ,
} ) ;
EdsResourceArgs args1 ( {
{ " locality0 " , CreateEndpointsForBackends ( 1 , 2 ) } ,
} ) ;
balancer_ - > ads_service ( ) - > SetEdsResource ( BuildEdsResource ( args ) ) ;
balancer_ - > ads_service ( ) - > SetEdsResource (
BuildEdsResource ( args1 , kNewEdsServiceName ) ) ;
// Populate new CDS resources.
Cluster new_cluster = default_cluster_ ;
new_cluster . set_name ( kNewClusterName ) ;
new_cluster . mutable_eds_cluster_config ( ) - > set_service_name (
kNewEdsServiceName ) ;
balancer_ - > ads_service ( ) - > SetCdsResource ( new_cluster ) ;
RouteConfiguration new_route_config = default_route_config_ ;
auto * default_route =
new_route_config . mutable_virtual_hosts ( 0 ) - > mutable_routes ( 0 ) ;
@ -7774,16 +7756,51 @@ TEST_P(RlsTest, XdsRoutingClusterSpecifierPluginNacksUndefinedSpecifier) {
ASSERT_TRUE ( response_state . has_value ( ) ) < < " timed out waiting for NACK " ;
EXPECT_THAT ( response_state - > error_message ,
: : testing : : HasSubstr ( " RouteAction cluster contains cluster "
" specifier plugin name not configured. " ) ) ;
" specifier plugin name not configured: " ) ) ;
gpr_unsetenv ( " GRPC_XDS_EXPERIMENTAL_XDS_RLS_LB " ) ;
}
TEST_P ( RlsTest , XdsRoutingClusterSpecifierPluginNacksDuplicateSpecifier ) {
gpr_setenv ( " GRPC_EXPERIMENTAL_XDS_RLS_LB " , " true " ) ;
// Prepare the RLSLookupConfig: change route configurations to use cluster
// specifier plugin.
RouteLookupConfig route_lookup_config ;
auto * key_builder = route_lookup_config . add_grpc_keybuilders ( ) ;
auto * name = key_builder - > add_names ( ) ;
name - > set_service ( kRlsServiceValue ) ;
name - > set_method ( kRlsMethodValue ) ;
auto * header = key_builder - > add_headers ( ) ;
header - > set_key ( kRlsTestKey ) ;
header - > add_names ( kRlsTestKey1 ) ;
route_lookup_config . set_lookup_service (
absl : : StrCat ( " localhost: " , rls_server_ - > port ( ) ) ) ;
route_lookup_config . set_cache_size_bytes ( 5000 ) ;
RouteLookupClusterSpecifier rls ;
* rls . mutable_route_lookup_config ( ) = std : : move ( route_lookup_config ) ;
RouteConfiguration new_route_config = default_route_config_ ;
auto * plugin = new_route_config . add_cluster_specifier_plugins ( ) ;
plugin - > mutable_extension ( ) - > set_name ( kRlsClusterSpecifierPluginInstanceName ) ;
plugin - > mutable_extension ( ) - > mutable_typed_config ( ) - > PackFrom ( rls ) ;
auto * duplicate_plugin = new_route_config . add_cluster_specifier_plugins ( ) ;
duplicate_plugin - > mutable_extension ( ) - > set_name (
kRlsClusterSpecifierPluginInstanceName ) ;
duplicate_plugin - > mutable_extension ( ) - > mutable_typed_config ( ) - > PackFrom ( rls ) ;
auto * default_route =
new_route_config . mutable_virtual_hosts ( 0 ) - > mutable_routes ( 0 ) ;
default_route - > mutable_route ( ) - > set_cluster_specifier_plugin (
kRlsClusterSpecifierPluginInstanceName ) ;
SetRouteConfiguration ( balancer_ . get ( ) , new_route_config ) ;
const auto response_state = WaitForRdsNack ( ) ;
ASSERT_TRUE ( response_state . has_value ( ) ) < < " timed out waiting for NACK " ;
EXPECT_THAT ( response_state - > error_message ,
: : testing : : HasSubstr ( absl : : StrCat (
" Duplicated definition of cluster_specifier_plugin " ,
kRlsClusterSpecifierPluginInstanceName ) ) ) ;
gpr_unsetenv ( " GRPC_XDS_EXPERIMENTAL_XDS_RLS_LB " ) ;
}
TEST_P ( RlsTest , XdsRoutingClusterSpecifierPluginNacksUnknownSpecifierProto ) {
// TODO(donnadionne): Doug is working on adding a new is_optional field to
// ClusterSpecifierPlugin in envoyproxy/envoy#20301. Once that goes in, the
// behavior we want in this case is that if is_optional is true, then we
// ignore that plugin and ignore any routes that refer to that plugin.
// However, if is_optional is false, then we want to NACK.
TEST_P ( RlsTest ,
XdsRoutingClusterSpecifierPluginNacksUnknownSpecifierProtoNotOptional ) {
gpr_setenv ( " GRPC_EXPERIMENTAL_XDS_RLS_LB " , " true " ) ;
const char * kNewClusterName = " new_cluster " ;
const char * kNewEdsServiceName = " new_eds_service_name " ;
@ -7820,10 +7837,40 @@ TEST_P(RlsTest, XdsRoutingClusterSpecifierPluginNacksUnknownSpecifierProto) {
SetRouteConfiguration ( balancer_ . get ( ) , new_route_config ) ;
const auto response_state = WaitForRdsNack ( ) ;
ASSERT_TRUE ( response_state . has_value ( ) ) < < " timed out waiting for NACK " ;
EXPECT_THAT (
response_state - > error_message ,
: : testing : : HasSubstr (
" Unable to locate the cluster specifier plugin in the registry " ) ) ;
EXPECT_THAT ( response_state - > error_message ,
: : testing : : HasSubstr ( " Unknown ClusterSpecifierPlugin type "
" grpc.lookup.v1.RouteLookupConfig " ) ) ;
gpr_unsetenv ( " GRPC_XDS_EXPERIMENTAL_XDS_RLS_LB " ) ;
}
TEST_P ( RlsTest ,
XdsRoutingClusterSpecifierPluginIgnoreUnknownSpecifierProtoOptional ) {
gpr_setenv ( " GRPC_EXPERIMENTAL_XDS_RLS_LB " , " true " ) ;
EdsResourceArgs args ( {
{ " locality0 " , CreateEndpointsForBackends ( 0 , 1 ) } ,
} ) ;
balancer_ - > ads_service ( ) - > SetEdsResource ( BuildEdsResource ( args ) ) ;
// Prepare the RLSLookupConfig: change route configurations to use cluster
// specifier plugin.
RouteLookupConfig route_lookup_config ;
RouteConfiguration new_route_config = default_route_config_ ;
auto * plugin = new_route_config . add_cluster_specifier_plugins ( ) ;
plugin - > mutable_extension ( ) - > set_name ( kRlsClusterSpecifierPluginInstanceName ) ;
// Instead of grpc.lookup.v1.RouteLookupClusterSpecifier, let's say we
// mistakenly packed the inner RouteLookupConfig instead.
plugin - > mutable_extension ( ) - > mutable_typed_config ( ) - > PackFrom (
route_lookup_config ) ;
plugin - > set_is_optional ( true ) ;
auto * route = new_route_config . mutable_virtual_hosts ( 0 ) - > mutable_routes ( 0 ) ;
route - > mutable_route ( ) - > set_cluster_specifier_plugin (
kRlsClusterSpecifierPluginInstanceName ) ;
auto * default_route = new_route_config . mutable_virtual_hosts ( 0 ) - > add_routes ( ) ;
default_route - > mutable_match ( ) - > set_prefix ( " " ) ;
default_route - > mutable_route ( ) - > set_cluster ( kDefaultClusterName ) ;
SetRouteConfiguration ( balancer_ . get ( ) , new_route_config ) ;
// Ensure we ignore the cluster specifier plugin and send traffic according to
// the default route.
WaitForAllBackends ( 0 , 1 ) ;
gpr_unsetenv ( " GRPC_XDS_EXPERIMENTAL_XDS_RLS_LB " ) ;
}