From bf6e534714b21468ba6539f3db87d9fccf734fe6 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 15 Apr 2020 09:24:55 -0700 Subject: [PATCH] Accept either "" or "/" as the prefix for the default route. --- .../ext/filters/client_channel/xds/xds_api.cc | 5 +++-- test/cpp/end2end/xds_end2end_test.cc | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/core/ext/filters/client_channel/xds/xds_api.cc b/src/core/ext/filters/client_channel/xds/xds_api.cc index 4cf5d8c26a2..3898fe4d5f1 100644 --- a/src/core/ext/filters/client_channel/xds/xds_api.cc +++ b/src/core/ext/filters/client_channel/xds/xds_api.cc @@ -1022,8 +1022,9 @@ grpc_error* RouteConfigParse( "No prefix field found in RouteMatch."); } const upb_strview prefix = envoy_api_v2_route_RouteMatch_prefix(match); - if (!upb_strview_eql(prefix, upb_strview_makez(""))) { - return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Prefix is not empty string."); + if (!upb_strview_eql(prefix, upb_strview_makez("")) && + !upb_strview_eql(prefix, upb_strview_makez("/"))) { + return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Prefix is not \"\" or \"/\"."); } if (!envoy_api_v2_route_Route_has_route(route)) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING( diff --git a/test/cpp/end2end/xds_end2end_test.cc b/test/cpp/end2end/xds_end2end_test.cc index 809ee59ee3d..7c03070190f 100644 --- a/test/cpp/end2end/xds_end2end_test.cc +++ b/test/cpp/end2end/xds_end2end_test.cc @@ -1799,6 +1799,26 @@ TEST_P(XdsResolverOnlyTest, RestartsRequestsUponReconnection) { EXPECT_EQ(0, std::get<1>(counts)); } +TEST_P(XdsResolverOnlyTest, DefaultRouteSpecifiesSlashPrefix) { + RouteConfiguration route_config = + balancers_[0]->ads_service()->default_route_config(); + route_config.mutable_virtual_hosts(0) + ->mutable_routes(0) + ->mutable_match() + ->set_prefix("/"); + balancers_[0]->ads_service()->SetLdsResource( + AdsServiceImpl::BuildListener(route_config), kDefaultResourceName); + SetNextResolution({}); + SetNextResolutionForLbChannelAllBalancers(); + AdsServiceImpl::EdsResourceArgs args({ + {"locality0", GetBackendPorts()}, + }); + balancers_[0]->ads_service()->SetEdsResource( + AdsServiceImpl::BuildEdsResource(args), kDefaultResourceName); + // We need to wait for all backends to come online. + WaitForAllBackends(); +} + class XdsResolverLoadReportingOnlyTest : public XdsEnd2endTest { public: XdsResolverLoadReportingOnlyTest() : XdsEnd2endTest(4, 1, 3) {}