Ensuring each action is only generated once in service config, even

if the same one is referred to multiple times by routes.

Added this test case in existing test case.
pull/22787/head
Donna Dionne 5 years ago
parent 6b676440f5
commit 326a81bf87
  1. 8
      src/core/ext/filters/client_channel/xds/xds_client.cc
  2. 3
      test/cpp/end2end/xds_end2end_test.cc

@ -2068,10 +2068,14 @@ grpc_error* XdsClient::CreateServiceConfig(
" { \"xds_routing_experimental\":{\n" " { \"xds_routing_experimental\":{\n"
" \"actions\":{\n"); " \"actions\":{\n");
std::vector<std::string> actions_vector; std::vector<std::string> actions_vector;
std::set<std::string> actions_set;
for (size_t i = 0; i < rds_update.routes.size(); ++i) { for (size_t i = 0; i < rds_update.routes.size(); ++i) {
auto route = rds_update.routes[i]; auto route = rds_update.routes[i];
actions_vector.push_back( if (actions_set.find(route.cluster_name) == actions_set.end()) {
CreateServiceConfigActionCluster(route.cluster_name.c_str())); actions_vector.push_back(
CreateServiceConfigActionCluster(route.cluster_name.c_str()));
actions_set.emplace(route.cluster_name);
}
} }
config_parts.push_back(absl::StrJoin(actions_vector, ",\n")); config_parts.push_back(absl::StrJoin(actions_vector, ",\n"));
config_parts.push_back( config_parts.push_back(

@ -2576,6 +2576,9 @@ TEST_P(LdsTest, XdsRoutingPathMatching) {
auto* route2 = new_route_config.mutable_virtual_hosts(0)->add_routes(); auto* route2 = new_route_config.mutable_virtual_hosts(0)->add_routes();
route2->mutable_match()->set_path("/grpc.testing.EchoTest2Service/Echo2"); route2->mutable_match()->set_path("/grpc.testing.EchoTest2Service/Echo2");
route2->mutable_route()->set_cluster(kNewCluster2Name); route2->mutable_route()->set_cluster(kNewCluster2Name);
auto* route3 = new_route_config.mutable_virtual_hosts(0)->add_routes();
route3->mutable_match()->set_path("/grpc.testing.EchoTest3Service/Echo3");
route3->mutable_route()->set_cluster(kDefaultResourceName);
auto* default_route = new_route_config.mutable_virtual_hosts(0)->add_routes(); auto* default_route = new_route_config.mutable_virtual_hosts(0)->add_routes();
default_route->mutable_match()->set_prefix(""); default_route->mutable_match()->set_prefix("");
default_route->mutable_route()->set_cluster(kDefaultResourceName); default_route->mutable_route()->set_cluster(kDefaultResourceName);

Loading…
Cancel
Save