From 21296fba5a8c97aced4dee30c10b06b7ccf55cf9 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Fri, 21 May 2021 16:05:33 -0700 Subject: [PATCH] xds: a myriad of cleanups --- xds/csds/csds.go | 38 +-- xds/csds/csds_test.go | 26 +- xds/googledirectpath/googlec2p.go | 4 +- xds/googledirectpath/googlec2p_test.go | 2 +- .../balancer/balancergroup/balancergroup.go | 2 +- .../balancergroup/balancergroup_test.go | 2 +- .../balancer/cdsbalancer/cdsbalancer.go | 20 +- .../cdsbalancer/cdsbalancer_security_test.go | 6 +- .../balancer/cdsbalancer/cdsbalancer_test.go | 7 +- .../balancer/cdsbalancer/cluster_handler.go | 6 +- .../cdsbalancer/cluster_handler_test.go | 2 +- .../balancer/clusterimpl/balancer_test.go | 32 +-- .../balancer/clusterimpl/clusterimpl.go | 220 +++++++++-------- xds/internal/balancer/clusterimpl/picker.go | 6 +- xds/internal/balancer/edsbalancer/eds.go | 226 +++++++++--------- xds/internal/balancer/edsbalancer/eds_impl.go | 13 +- .../balancer/edsbalancer/eds_impl_test.go | 7 +- xds/internal/balancer/edsbalancer/eds_test.go | 15 +- .../balancer/edsbalancer/eds_testutil.go | 2 +- xds/internal/balancer/edsbalancer/util.go | 2 +- .../balancer/edsbalancer/util_test.go | 2 +- .../balancer/edsbalancer/xds_lrs_test.go | 2 +- xds/internal/balancer/edsbalancer/xds_old.go | 12 +- .../balancer/loadstore/load_store_wrapper.go | 2 +- xds/internal/balancer/lrs/balancer.go | 42 ++-- xds/internal/balancer/lrs/balancer_test.go | 2 +- xds/internal/httpfilter/fault/fault_test.go | 2 +- xds/internal/resolver/matcher.go | 2 +- xds/internal/resolver/serviceconfig.go | 2 +- xds/internal/resolver/watch_service.go | 6 +- xds/internal/resolver/watch_service_test.go | 2 +- xds/internal/resolver/xds_resolver.go | 44 ++-- xds/internal/resolver/xds_resolver_test.go | 67 +++--- xds/internal/server/conn_wrapper.go | 2 +- xds/internal/server/listener_wrapper.go | 4 +- xds/internal/server/listener_wrapper_test.go | 2 +- xds/internal/testutils/fakeclient/client.go | 133 +++++------ .../{client => xdsclient}/attributes.go | 2 +- .../bootstrap/bootstrap.go | 0 .../bootstrap/bootstrap_test.go | 0 .../bootstrap/logging.go | 0 .../{client => xdsclient}/callback.go | 2 +- .../{client => xdsclient}/cds_test.go | 2 +- xds/internal/{client => xdsclient}/client.go | 10 +- .../{client => xdsclient}/client_test.go | 4 +- xds/internal/{client => xdsclient}/dump.go | 2 +- .../{client => xdsclient}/eds_test.go | 2 +- xds/internal/{client => xdsclient}/errors.go | 2 +- .../{client => xdsclient}/filter_chain.go | 2 +- .../filter_chain_test.go | 2 +- .../{client => xdsclient}/lds_test.go | 2 +- .../{client => xdsclient}/load/reporter.go | 0 .../{client => xdsclient}/load/store.go | 0 .../{client => xdsclient}/load/store_test.go | 0 .../{client => xdsclient}/loadreport.go | 4 +- xds/internal/{client => xdsclient}/logging.go | 2 +- .../{client => xdsclient}/rds_test.go | 2 +- .../{client => xdsclient}/requests_counter.go | 2 +- .../requests_counter_test.go | 2 +- .../{client => xdsclient}/singleton.go | 4 +- .../{client => xdsclient}/tests/README.md | 0 .../tests/client_test.go | 6 +- .../{client => xdsclient}/tests/dump_test.go | 4 +- .../tests/loadreport_test.go | 8 +- .../{client => xdsclient}/transport_helper.go | 4 +- .../{client => xdsclient}/v2/ack_test.go | 2 +- .../{client => xdsclient}/v2/cds_test.go | 2 +- .../{client => xdsclient}/v2/client.go | 2 +- .../{client => xdsclient}/v2/client_test.go | 2 +- .../{client => xdsclient}/v2/eds_test.go | 2 +- .../{client => xdsclient}/v2/lds_test.go | 2 +- .../{client => xdsclient}/v2/loadreport.go | 2 +- .../{client => xdsclient}/v2/rds_test.go | 2 +- .../{client => xdsclient}/v3/client.go | 2 +- .../{client => xdsclient}/v3/loadreport.go | 2 +- .../{client => xdsclient}/watchers.go | 2 +- .../watchers_cluster_test.go | 2 +- .../watchers_endpoints_test.go | 2 +- .../watchers_listener_test.go | 2 +- .../watchers_route_test.go | 2 +- xds/internal/{client => xdsclient}/xds.go | 2 +- xds/server.go | 32 +-- xds/server_test.go | 12 +- xds/xds.go | 4 +- 84 files changed, 542 insertions(+), 574 deletions(-) rename xds/internal/{client => xdsclient}/attributes.go (98%) rename xds/internal/{client => xdsclient}/bootstrap/bootstrap.go (100%) rename xds/internal/{client => xdsclient}/bootstrap/bootstrap_test.go (100%) rename xds/internal/{client => xdsclient}/bootstrap/logging.go (100%) rename xds/internal/{client => xdsclient}/callback.go (99%) rename xds/internal/{client => xdsclient}/cds_test.go (99%) rename xds/internal/{client => xdsclient}/client.go (98%) rename xds/internal/{client => xdsclient}/client_test.go (99%) rename xds/internal/{client => xdsclient}/dump.go (99%) rename xds/internal/{client => xdsclient}/eds_test.go (99%) rename xds/internal/{client => xdsclient}/errors.go (98%) rename xds/internal/{client => xdsclient}/filter_chain.go (99%) rename xds/internal/{client => xdsclient}/filter_chain_test.go (99%) rename xds/internal/{client => xdsclient}/lds_test.go (99%) rename xds/internal/{client => xdsclient}/load/reporter.go (100%) rename xds/internal/{client => xdsclient}/load/store.go (100%) rename xds/internal/{client => xdsclient}/load/store_test.go (100%) rename xds/internal/{client => xdsclient}/loadreport.go (98%) rename xds/internal/{client => xdsclient}/logging.go (98%) rename xds/internal/{client => xdsclient}/rds_test.go (99%) rename xds/internal/{client => xdsclient}/requests_counter.go (99%) rename xds/internal/{client => xdsclient}/requests_counter_test.go (99%) rename xds/internal/{client => xdsclient}/singleton.go (98%) rename xds/internal/{client => xdsclient}/tests/README.md (100%) rename xds/internal/{client => xdsclient}/tests/client_test.go (93%) rename xds/internal/{client => xdsclient}/tests/dump_test.go (99%) rename xds/internal/{client => xdsclient}/tests/loadreport_test.go (94%) rename xds/internal/{client => xdsclient}/transport_helper.go (99%) rename xds/internal/{client => xdsclient}/v2/ack_test.go (99%) rename xds/internal/{client => xdsclient}/v2/cds_test.go (99%) rename xds/internal/{client => xdsclient}/v2/client.go (99%) rename xds/internal/{client => xdsclient}/v2/client_test.go (99%) rename xds/internal/{client => xdsclient}/v2/eds_test.go (99%) rename xds/internal/{client => xdsclient}/v2/lds_test.go (99%) rename xds/internal/{client => xdsclient}/v2/loadreport.go (98%) rename xds/internal/{client => xdsclient}/v2/rds_test.go (99%) rename xds/internal/{client => xdsclient}/v3/client.go (99%) rename xds/internal/{client => xdsclient}/v3/loadreport.go (98%) rename xds/internal/{client => xdsclient}/watchers.go (99%) rename xds/internal/{client => xdsclient}/watchers_cluster_test.go (99%) rename xds/internal/{client => xdsclient}/watchers_endpoints_test.go (99%) rename xds/internal/{client => xdsclient}/watchers_listener_test.go (99%) rename xds/internal/{client => xdsclient}/watchers_route_test.go (99%) rename xds/internal/{client => xdsclient}/xds.go (99%) diff --git a/xds/csds/csds.go b/xds/csds/csds.go index 73b92e9443ce..5e2407d8941f 100644 --- a/xds/csds/csds.go +++ b/xds/csds/csds.go @@ -38,29 +38,29 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/grpclog" "google.golang.org/grpc/status" - "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" "google.golang.org/protobuf/types/known/timestamppb" - _ "google.golang.org/grpc/xds/internal/client/v2" // Register v2 xds_client. - _ "google.golang.org/grpc/xds/internal/client/v3" // Register v3 xds_client. + _ "google.golang.org/grpc/xds/internal/xdsclient/v2" // Register v2 xds_client. + _ "google.golang.org/grpc/xds/internal/xdsclient/v3" // Register v3 xds_client. ) -// xdsClientInterface contains methods from xdsClient.Client which are used by +// xdsClient contains methods from xdsClient.Client which are used by // the server. This is useful for overriding in unit tests. -type xdsClientInterface interface { - DumpLDS() (string, map[string]client.UpdateWithMD) - DumpRDS() (string, map[string]client.UpdateWithMD) - DumpCDS() (string, map[string]client.UpdateWithMD) - DumpEDS() (string, map[string]client.UpdateWithMD) +type xdsClient interface { + DumpLDS() (string, map[string]xdsclient.UpdateWithMD) + DumpRDS() (string, map[string]xdsclient.UpdateWithMD) + DumpCDS() (string, map[string]xdsclient.UpdateWithMD) + DumpEDS() (string, map[string]xdsclient.UpdateWithMD) BootstrapConfig() *bootstrap.Config Close() } var ( logger = grpclog.Component("xds") - newXDSClient = func() (xdsClientInterface, error) { - return client.New() + newXDSClient = func() (xdsClient, error) { + return xdsclient.New() } ) @@ -68,7 +68,7 @@ var ( type ClientStatusDiscoveryServer struct { // xdsClient will always be the same in practise. But we keep a copy in each // server instance for testing. - xdsClient xdsClientInterface + xdsClient xdsClient } // NewClientStatusDiscoveryServer returns an implementation of the CSDS server that can be @@ -296,17 +296,17 @@ func (s *ClientStatusDiscoveryServer) buildEDSPerXDSConfig() *v3statuspb.PerXdsC } } -func serviceStatusToProto(serviceStatus client.ServiceStatus) v3adminpb.ClientResourceStatus { +func serviceStatusToProto(serviceStatus xdsclient.ServiceStatus) v3adminpb.ClientResourceStatus { switch serviceStatus { - case client.ServiceStatusUnknown: + case xdsclient.ServiceStatusUnknown: return v3adminpb.ClientResourceStatus_UNKNOWN - case client.ServiceStatusRequested: + case xdsclient.ServiceStatusRequested: return v3adminpb.ClientResourceStatus_REQUESTED - case client.ServiceStatusNotExist: + case xdsclient.ServiceStatusNotExist: return v3adminpb.ClientResourceStatus_DOES_NOT_EXIST - case client.ServiceStatusACKed: + case xdsclient.ServiceStatusACKed: return v3adminpb.ClientResourceStatus_ACKED - case client.ServiceStatusNACKed: + case xdsclient.ServiceStatusNACKed: return v3adminpb.ClientResourceStatus_NACKED default: return v3adminpb.ClientResourceStatus_UNKNOWN diff --git a/xds/csds/csds_test.go b/xds/csds/csds_test.go index 6cf88f6d3942..b449798c804f 100644 --- a/xds/csds/csds_test.go +++ b/xds/csds/csds_test.go @@ -36,10 +36,10 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/internal/testutils" "google.golang.org/grpc/internal/xds" - "google.golang.org/grpc/xds/internal/client" _ "google.golang.org/grpc/xds/internal/httpfilter/router" xtestutils "google.golang.org/grpc/xds/internal/testutils" "google.golang.org/grpc/xds/internal/testutils/e2e" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/protobuf/testing/protocmp" "google.golang.org/protobuf/types/known/anypb" "google.golang.org/protobuf/types/known/timestamppb" @@ -59,11 +59,11 @@ const ( defaultTestTimeout = 10 * time.Second ) -type xdsClientInterfaceWithWatch interface { - WatchListener(string, func(client.ListenerUpdate, error)) func() - WatchRouteConfig(string, func(client.RouteConfigUpdate, error)) func() - WatchCluster(string, func(client.ClusterUpdate, error)) func() - WatchEndpoints(string, func(client.EndpointsUpdate, error)) func() +type xdsClientWithWatch interface { + WatchListener(string, func(xdsclient.ListenerUpdate, error)) func() + WatchRouteConfig(string, func(xdsclient.RouteConfigUpdate, error)) func() + WatchCluster(string, func(xdsclient.ClusterUpdate, error)) func() + WatchEndpoints(string, func(xdsclient.EndpointsUpdate, error)) func() } var cmpOpts = cmp.Options{ @@ -174,16 +174,16 @@ func TestCSDS(t *testing.T) { defer cleanup() for _, target := range ldsTargets { - xdsC.WatchListener(target, func(client.ListenerUpdate, error) {}) + xdsC.WatchListener(target, func(xdsclient.ListenerUpdate, error) {}) } for _, target := range rdsTargets { - xdsC.WatchRouteConfig(target, func(client.RouteConfigUpdate, error) {}) + xdsC.WatchRouteConfig(target, func(xdsclient.RouteConfigUpdate, error) {}) } for _, target := range cdsTargets { - xdsC.WatchCluster(target, func(client.ClusterUpdate, error) {}) + xdsC.WatchCluster(target, func(xdsclient.ClusterUpdate, error) {}) } for _, target := range edsTargets { - xdsC.WatchEndpoints(target, func(client.EndpointsUpdate, error) {}) + xdsC.WatchEndpoints(target, func(xdsclient.EndpointsUpdate, error) {}) } for i := 0; i < retryCount; i++ { @@ -250,7 +250,7 @@ func TestCSDS(t *testing.T) { } } -func commonSetup(t *testing.T) (xdsClientInterfaceWithWatch, *e2e.ManagementServer, string, v3statuspbgrpc.ClientStatusDiscoveryService_StreamClientStatusClient, func()) { +func commonSetup(t *testing.T) (xdsClientWithWatch, *e2e.ManagementServer, string, v3statuspbgrpc.ClientStatusDiscoveryService_StreamClientStatusClient, func()) { t.Helper() // Spin up a xDS management server on a local port. @@ -270,12 +270,12 @@ func commonSetup(t *testing.T) (xdsClientInterfaceWithWatch, *e2e.ManagementServ t.Fatal(err) } // Create xds_client. - xdsC, err := client.New() + xdsC, err := xdsclient.New() if err != nil { t.Fatalf("failed to create xds client: %v", err) } oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { + newXDSClient = func() (xdsClient, error) { return xdsC, nil } diff --git a/xds/googledirectpath/googlec2p.go b/xds/googledirectpath/googlec2p.go index 4ccec4ec4120..ccf9f152ca7b 100644 --- a/xds/googledirectpath/googlec2p.go +++ b/xds/googledirectpath/googlec2p.go @@ -38,9 +38,9 @@ import ( "google.golang.org/grpc/internal/xds/env" "google.golang.org/grpc/resolver" _ "google.golang.org/grpc/xds" // To register xds resolvers and balancers. - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" "google.golang.org/grpc/xds/internal/version" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" "google.golang.org/protobuf/types/known/structpb" ) diff --git a/xds/googledirectpath/googlec2p_test.go b/xds/googledirectpath/googlec2p_test.go index 524bb82e0f39..3ea6f1204c1f 100644 --- a/xds/googledirectpath/googlec2p_test.go +++ b/xds/googledirectpath/googlec2p_test.go @@ -31,7 +31,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/internal/xds/env" "google.golang.org/grpc/resolver" - "google.golang.org/grpc/xds/internal/client/bootstrap" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" "google.golang.org/grpc/xds/internal/version" "google.golang.org/protobuf/testing/protocmp" "google.golang.org/protobuf/types/known/structpb" diff --git a/xds/internal/balancer/balancergroup/balancergroup.go b/xds/internal/balancer/balancergroup/balancergroup.go index 5b6d42a25e44..b86dea50e807 100644 --- a/xds/internal/balancer/balancergroup/balancergroup.go +++ b/xds/internal/balancer/balancergroup/balancergroup.go @@ -24,7 +24,7 @@ import ( "time" orcapb "github.com/cncf/udpa/go/udpa/data/orca/v1" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient/load" "google.golang.org/grpc/balancer" "google.golang.org/grpc/connectivity" diff --git a/xds/internal/balancer/balancergroup/balancergroup_test.go b/xds/internal/balancer/balancergroup/balancergroup_test.go index 1ba9195ab1d0..210e379cc265 100644 --- a/xds/internal/balancer/balancergroup/balancergroup_test.go +++ b/xds/internal/balancer/balancergroup/balancergroup_test.go @@ -44,7 +44,7 @@ import ( "google.golang.org/grpc/internal/balancer/stub" "google.golang.org/grpc/resolver" "google.golang.org/grpc/xds/internal/balancer/weightedtarget/weightedaggregator" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient/load" "google.golang.org/grpc/xds/internal/testutils" ) diff --git a/xds/internal/balancer/cdsbalancer/cdsbalancer.go b/xds/internal/balancer/cdsbalancer/cdsbalancer.go index 0b5f9bc08003..5d9f92a6de3b 100644 --- a/xds/internal/balancer/cdsbalancer/cdsbalancer.go +++ b/xds/internal/balancer/cdsbalancer/cdsbalancer.go @@ -35,8 +35,8 @@ import ( "google.golang.org/grpc/resolver" "google.golang.org/grpc/serviceconfig" "google.golang.org/grpc/xds/internal/balancer/edsbalancer" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" ) const ( @@ -59,7 +59,7 @@ var ( // not deal with subConns. return builder.Build(cc, opts), nil } - newXDSClient func() (xdsClientInterface, error) + newXDSClient func() (xdsClient, error) buildProvider = buildProviderFunc ) @@ -73,6 +73,8 @@ func init() { // JSON service config, to be passed to the cdsBalancer. type cdsBB struct{} +var _ balancer.ConfigParser = cdsBB{} + // Build creates a new CDS balancer with the ClientConn. func (cdsBB) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer { b := &cdsBalancer{ @@ -138,12 +140,11 @@ func (cdsBB) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancingConfig, return &cfg, nil } -// xdsClientInterface contains methods from xdsClient.Client which are used by -// the cdsBalancer. This will be faked out in unittests. -type xdsClientInterface interface { +// xdsClient contains methods from xdsclient.Client which are used by the +// cdsBalancer. This will be faked out in unittests. +type xdsClient interface { WatchCluster(string, func(xdsclient.ClusterUpdate, error)) func() BootstrapConfig() *bootstrap.Config - Close() } // ccUpdate wraps a clientConn update received from gRPC (pushed from the @@ -185,7 +186,7 @@ type cdsBalancer struct { ccw *ccWrapper // ClientConn interface passed to child LB. bOpts balancer.BuildOptions // BuildOptions passed to child LB. updateCh *buffer.Unbounded // Channel for gRPC and xdsClient updates. - xdsClient xdsClientInterface // xDS client to watch Cluster resource. + xdsClient xdsClient // xDS client to watch Cluster resource. cancelWatch func() // Cluster watch cancel func. edsLB balancer.Balancer // EDS child policy. clusterToWatch string @@ -405,9 +406,6 @@ func (b *cdsBalancer) run() { b.edsLB.Close() b.edsLB = nil } - if newXDSClient != nil { - b.xdsClient.Close() - } if b.cachedRoot != nil { b.cachedRoot.Close() } diff --git a/xds/internal/balancer/cdsbalancer/cdsbalancer_security_test.go b/xds/internal/balancer/cdsbalancer/cdsbalancer_security_test.go index 52b1a05f1362..9964b9de925c 100644 --- a/xds/internal/balancer/cdsbalancer/cdsbalancer_security_test.go +++ b/xds/internal/balancer/cdsbalancer/cdsbalancer_security_test.go @@ -36,10 +36,10 @@ import ( "google.golang.org/grpc/internal/testutils" "google.golang.org/grpc/internal/xds/matcher" "google.golang.org/grpc/resolver" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" xdstestutils "google.golang.org/grpc/xds/internal/testutils" "google.golang.org/grpc/xds/internal/testutils/fakeclient" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" ) const ( @@ -136,7 +136,7 @@ func setupWithXDSCreds(t *testing.T) (*fakeclient.Client, *cdsBalancer, *testEDS xdsC := fakeclient.NewClient() oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { return xdsC, nil } + newXDSClient = func() (xdsClient, error) { return xdsC, nil } builder := balancer.Get(cdsName) if builder == nil { diff --git a/xds/internal/balancer/cdsbalancer/cdsbalancer_test.go b/xds/internal/balancer/cdsbalancer/cdsbalancer_test.go index fba3ee1531e9..5c5161807be3 100644 --- a/xds/internal/balancer/cdsbalancer/cdsbalancer_test.go +++ b/xds/internal/balancer/cdsbalancer/cdsbalancer_test.go @@ -37,10 +37,9 @@ import ( "google.golang.org/grpc/resolver" "google.golang.org/grpc/serviceconfig" "google.golang.org/grpc/xds/internal/balancer/edsbalancer" - "google.golang.org/grpc/xds/internal/client" - xdsclient "google.golang.org/grpc/xds/internal/client" xdstestutils "google.golang.org/grpc/xds/internal/testutils" "google.golang.org/grpc/xds/internal/testutils/fakeclient" + "google.golang.org/grpc/xds/internal/xdsclient" ) const ( @@ -215,7 +214,7 @@ func setup(t *testing.T) (*fakeclient.Client, *cdsBalancer, *testEDSBalancer, *x xdsC := fakeclient.NewClient() oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { return xdsC, nil } + newXDSClient = func() (xdsClient, error) { return xdsC, nil } builder := balancer.Get(cdsName) if builder == nil { @@ -606,7 +605,7 @@ func (s) TestCircuitBreaking(t *testing.T) { // Since the counter's max requests was set to 1, the first request should // succeed and the second should fail. - counter := client.GetServiceRequestsCounter(serviceName) + counter := xdsclient.GetServiceRequestsCounter(serviceName) if err := counter.StartRequest(maxRequests); err != nil { t.Fatal(err) } diff --git a/xds/internal/balancer/cdsbalancer/cluster_handler.go b/xds/internal/balancer/cdsbalancer/cluster_handler.go index 4c13b55594da..c38d1a6c31a6 100644 --- a/xds/internal/balancer/cdsbalancer/cluster_handler.go +++ b/xds/internal/balancer/cdsbalancer/cluster_handler.go @@ -20,7 +20,7 @@ import ( "errors" "sync" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" ) var errNotReceivedUpdate = errors.New("tried to construct a cluster update on a cluster that has not received an update") @@ -40,7 +40,7 @@ type clusterHandler struct { // CDS Balancer cares about is the most recent update. updateChannel chan clusterHandlerUpdate - xdsClient xdsClientInterface + xdsClient xdsClient } func (ch *clusterHandler) updateRootCluster(rootClusterName string) { @@ -112,7 +112,7 @@ type clusterNode struct { // CreateClusterNode creates a cluster node from a given clusterName. This will // also start the watch for that cluster. -func createClusterNode(clusterName string, xdsClient xdsClientInterface, topLevelHandler *clusterHandler) *clusterNode { +func createClusterNode(clusterName string, xdsClient xdsClient, topLevelHandler *clusterHandler) *clusterNode { c := &clusterNode{ clusterHandler: topLevelHandler, } diff --git a/xds/internal/balancer/cdsbalancer/cluster_handler_test.go b/xds/internal/balancer/cdsbalancer/cluster_handler_test.go index 049cdf55ee6a..5209cce742ec 100644 --- a/xds/internal/balancer/cdsbalancer/cluster_handler_test.go +++ b/xds/internal/balancer/cdsbalancer/cluster_handler_test.go @@ -24,7 +24,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/testutils/fakeclient" ) diff --git a/xds/internal/balancer/clusterimpl/balancer_test.go b/xds/internal/balancer/clusterimpl/balancer_test.go index cfce6f673913..75c16f071673 100644 --- a/xds/internal/balancer/clusterimpl/balancer_test.go +++ b/xds/internal/balancer/clusterimpl/balancer_test.go @@ -34,10 +34,10 @@ import ( "google.golang.org/grpc/internal" internalserviceconfig "google.golang.org/grpc/internal/serviceconfig" "google.golang.org/grpc/resolver" - "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/load" "google.golang.org/grpc/xds/internal/testutils" "google.golang.org/grpc/xds/internal/testutils/fakeclient" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/load" ) const ( @@ -72,10 +72,10 @@ func init() { // TestDropByCategory verifies that the balancer correctly drops the picks, and // that the drops are reported. func TestDropByCategory(t *testing.T) { - defer client.ClearCounterForTesting(testClusterName) + defer xdsclient.ClearCounterForTesting(testClusterName) xdsC := fakeclient.NewClient() oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { return xdsC, nil } + newXDSClient = func() (xdsClient, error) { return xdsC, nil } defer func() { newXDSClient = oldNewXDSClient }() builder := balancer.Get(Name) @@ -113,10 +113,10 @@ func TestDropByCategory(t *testing.T) { got, err := xdsC.WaitForReportLoad(ctx) if err != nil { - t.Fatalf("xdsClient.ReportLoad failed with error: %v", err) + t.Fatalf("client.ReportLoad failed with error: %v", err) } if got.Server != testLRSServerName { - t.Fatalf("xdsClient.ReportLoad called with {%q}: want {%q}", got.Server, testLRSServerName) + t.Fatalf("client.ReportLoad called with {%q}: want {%q}", got.Server, testLRSServerName) } sc1 := <-cc.NewSubConnCh @@ -230,10 +230,10 @@ func TestDropByCategory(t *testing.T) { // TestDropCircuitBreaking verifies that the balancer correctly drops the picks // due to circuit breaking, and that the drops are reported. func TestDropCircuitBreaking(t *testing.T) { - defer client.ClearCounterForTesting(testClusterName) + defer xdsclient.ClearCounterForTesting(testClusterName) xdsC := fakeclient.NewClient() oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { return xdsC, nil } + newXDSClient = func() (xdsClient, error) { return xdsC, nil } defer func() { newXDSClient = oldNewXDSClient }() builder := balancer.Get(Name) @@ -264,10 +264,10 @@ func TestDropCircuitBreaking(t *testing.T) { got, err := xdsC.WaitForReportLoad(ctx) if err != nil { - t.Fatalf("xdsClient.ReportLoad failed with error: %v", err) + t.Fatalf("client.ReportLoad failed with error: %v", err) } if got.Server != testLRSServerName { - t.Fatalf("xdsClient.ReportLoad called with {%q}: want {%q}", got.Server, testLRSServerName) + t.Fatalf("client.ReportLoad called with {%q}: want {%q}", got.Server, testLRSServerName) } sc1 := <-cc.NewSubConnCh @@ -342,10 +342,10 @@ func TestDropCircuitBreaking(t *testing.T) { // picker after it's closed. Because picker updates are sent in the run() // goroutine. func TestPickerUpdateAfterClose(t *testing.T) { - defer client.ClearCounterForTesting(testClusterName) + defer xdsclient.ClearCounterForTesting(testClusterName) xdsC := fakeclient.NewClient() oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { return xdsC, nil } + newXDSClient = func() (xdsClient, error) { return xdsC, nil } defer func() { newXDSClient = oldNewXDSClient }() builder := balancer.Get(Name) @@ -387,10 +387,10 @@ func TestPickerUpdateAfterClose(t *testing.T) { // TestClusterNameInAddressAttributes covers the case that cluster name is // attached to the subconn address attributes. func TestClusterNameInAddressAttributes(t *testing.T) { - defer client.ClearCounterForTesting(testClusterName) + defer xdsclient.ClearCounterForTesting(testClusterName) xdsC := fakeclient.NewClient() oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { return xdsC, nil } + newXDSClient = func() (xdsClient, error) { return xdsC, nil } defer func() { newXDSClient = oldNewXDSClient }() builder := balancer.Get(Name) @@ -478,10 +478,10 @@ func TestClusterNameInAddressAttributes(t *testing.T) { // TestReResolution verifies that when a SubConn turns transient failure, // re-resolution is triggered. func TestReResolution(t *testing.T) { - defer client.ClearCounterForTesting(testClusterName) + defer xdsclient.ClearCounterForTesting(testClusterName) xdsC := fakeclient.NewClient() oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { return xdsC, nil } + newXDSClient = func() (xdsClient, error) { return xdsC, nil } defer func() { newXDSClient = oldNewXDSClient }() builder := balancer.Get(Name) diff --git a/xds/internal/balancer/clusterimpl/clusterimpl.go b/xds/internal/balancer/clusterimpl/clusterimpl.go index 4fca0f387e47..b443d29c6d5f 100644 --- a/xds/internal/balancer/clusterimpl/clusterimpl.go +++ b/xds/internal/balancer/clusterimpl/clusterimpl.go @@ -38,8 +38,8 @@ import ( "google.golang.org/grpc/resolver" "google.golang.org/grpc/serviceconfig" "google.golang.org/grpc/xds/internal/balancer/loadstore" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/load" ) const ( @@ -52,14 +52,14 @@ func init() { balancer.Register(clusterImplBB{}) } -var newXDSClient func() (xdsClientInterface, error) +var newXDSClient func() (xdsClient, error) type clusterImplBB struct{} func (clusterImplBB) Build(cc balancer.ClientConn, bOpts balancer.BuildOptions) balancer.Balancer { b := &clusterImplBalancer{ ClientConn: cc, - bOpts: bOpts, + buildOpts: bOpts, closed: grpcsync.NewEvent(), loadWrapper: loadstore.NewWrapper(), pickerUpdateCh: buffer.NewUnbounded(), @@ -74,7 +74,7 @@ func (clusterImplBB) Build(cc balancer.ClientConn, bOpts balancer.BuildOptions) b.logger.Errorf("failed to create xds-client: %v", err) return nil } - b.xdsC = client + b.xdsClient = client } go b.run() @@ -90,11 +90,10 @@ func (clusterImplBB) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancing return parseConfig(c) } -// xdsClientInterface contains only the xds_client methods needed by LRS -// balancer. It's defined so we can override xdsclient in tests. -type xdsClientInterface interface { +// xdsClient contains only the xds_client methods needed by LRS balancer. It's +// defined so we can override xdsclient in tests. +type xdsClient interface { ReportLoad(server string) (*load.Store, func()) - Close() } type clusterImplBalancer struct { @@ -111,9 +110,9 @@ type clusterImplBalancer struct { mu sync.Mutex closed *grpcsync.Event - bOpts balancer.BuildOptions - logger *grpclog.PrefixLogger - xdsC xdsClientInterface + buildOpts balancer.BuildOptions + logger *grpclog.PrefixLogger + xdsClient xdsClient config *LBConfig childLB balancer.Balancer @@ -137,20 +136,20 @@ type clusterImplBalancer struct { // updateLoadStore checks the config for load store, and decides whether it // needs to restart the load reporting stream. -func (cib *clusterImplBalancer) updateLoadStore(newConfig *LBConfig) error { +func (b *clusterImplBalancer) updateLoadStore(newConfig *LBConfig) error { var updateLoadClusterAndService bool // ClusterName is different, restart. ClusterName is from ClusterName and // EDSServiceName. - clusterName := cib.getClusterName() + clusterName := b.getClusterName() if clusterName != newConfig.Cluster { updateLoadClusterAndService = true - cib.setClusterName(newConfig.Cluster) + b.setClusterName(newConfig.Cluster) clusterName = newConfig.Cluster } - if cib.edsServiceName != newConfig.EDSServiceName { + if b.edsServiceName != newConfig.EDSServiceName { updateLoadClusterAndService = true - cib.edsServiceName = newConfig.EDSServiceName + b.edsServiceName = newConfig.EDSServiceName } if updateLoadClusterAndService { // This updates the clusterName and serviceName that will be reported @@ -161,7 +160,7 @@ func (cib *clusterImplBalancer) updateLoadStore(newConfig *LBConfig) error { // On the other hand, this will almost never happen. Each LRS policy // shouldn't get updated config. The parent should do a graceful switch // when the clusterName or serviceName is changed. - cib.loadWrapper.UpdateClusterAndService(clusterName, cib.edsServiceName) + b.loadWrapper.UpdateClusterAndService(clusterName, b.edsServiceName) } // Check if it's necessary to restart load report. @@ -169,31 +168,31 @@ func (cib *clusterImplBalancer) updateLoadStore(newConfig *LBConfig) error { if newConfig.LoadReportingServerName != nil { newLRSServerName = *newConfig.LoadReportingServerName } - if cib.lrsServerName != newLRSServerName { + if b.lrsServerName != newLRSServerName { // LoadReportingServerName is different, load should be report to a // different server, restart. - cib.lrsServerName = newLRSServerName - if cib.cancelLoadReport != nil { - cib.cancelLoadReport() - cib.cancelLoadReport = nil + b.lrsServerName = newLRSServerName + if b.cancelLoadReport != nil { + b.cancelLoadReport() + b.cancelLoadReport = nil } var loadStore *load.Store - if cib.xdsC != nil { - loadStore, cib.cancelLoadReport = cib.xdsC.ReportLoad(cib.lrsServerName) + if b.xdsClient != nil { + loadStore, b.cancelLoadReport = b.xdsClient.ReportLoad(b.lrsServerName) } - cib.loadWrapper.UpdateLoadStore(loadStore) + b.loadWrapper.UpdateLoadStore(loadStore) } return nil } -func (cib *clusterImplBalancer) UpdateClientConnState(s balancer.ClientConnState) error { - if cib.closed.HasFired() { - cib.logger.Warningf("xds: received ClientConnState {%+v} after clusterImplBalancer was closed", s) +func (b *clusterImplBalancer) UpdateClientConnState(s balancer.ClientConnState) error { + if b.closed.HasFired() { + b.logger.Warningf("xds: received ClientConnState {%+v} after clusterImplBalancer was closed", s) return nil } - cib.logger.Infof("Received update from resolver, balancer config: %+v", pretty.ToJSON(s.BalancerConfig)) + b.logger.Infof("Received update from resolver, balancer config: %+v", pretty.ToJSON(s.BalancerConfig)) newConfig, ok := s.BalancerConfig.(*LBConfig) if !ok { return fmt.Errorf("unexpected balancer config with type: %T", s.BalancerConfig) @@ -207,36 +206,36 @@ func (cib *clusterImplBalancer) UpdateClientConnState(s balancer.ClientConnState return fmt.Errorf("balancer %q not registered", newConfig.ChildPolicy.Name) } - if cib.xdsC == nil { + if b.xdsClient == nil { c := xdsclient.FromResolverState(s.ResolverState) if c == nil { return balancer.ErrBadResolverState } - cib.xdsC = c + b.xdsClient = c } // Update load reporting config. This needs to be done before updating the // child policy because we need the loadStore from the updated client to be // passed to the ccWrapper, so that the next picker from the child policy // will pick up the new loadStore. - if err := cib.updateLoadStore(newConfig); err != nil { + if err := b.updateLoadStore(newConfig); err != nil { return err } // Compare new drop config. And update picker if it's changed. var updatePicker bool - if cib.config == nil || !equalDropCategories(cib.config.DropCategories, newConfig.DropCategories) { - cib.drops = make([]*dropper, 0, len(newConfig.DropCategories)) + if b.config == nil || !equalDropCategories(b.config.DropCategories, newConfig.DropCategories) { + b.drops = make([]*dropper, 0, len(newConfig.DropCategories)) for _, c := range newConfig.DropCategories { - cib.drops = append(cib.drops, newDropper(c)) + b.drops = append(b.drops, newDropper(c)) } updatePicker = true } // Compare cluster name. And update picker if it's changed, because circuit // breaking's stream counter will be different. - if cib.config == nil || cib.config.Cluster != newConfig.Cluster { - cib.requestCounter = xdsclient.GetServiceRequestsCounter(newConfig.Cluster) + if b.config == nil || b.config.Cluster != newConfig.Cluster { + b.requestCounter = xdsclient.GetServiceRequestsCounter(newConfig.Cluster) updatePicker = true } // Compare upper bound of stream count. And update picker if it's changed. @@ -245,29 +244,29 @@ func (cib *clusterImplBalancer) UpdateClientConnState(s balancer.ClientConnState if newConfig.MaxConcurrentRequests != nil { newRequestCountMax = *newConfig.MaxConcurrentRequests } - if cib.requestCountMax != newRequestCountMax { - cib.requestCountMax = newRequestCountMax + if b.requestCountMax != newRequestCountMax { + b.requestCountMax = newRequestCountMax updatePicker = true } if updatePicker { - cib.pickerUpdateCh.Put(&dropConfigs{ - drops: cib.drops, - requestCounter: cib.requestCounter, - requestCountMax: cib.requestCountMax, + b.pickerUpdateCh.Put(&dropConfigs{ + drops: b.drops, + requestCounter: b.requestCounter, + requestCountMax: b.requestCountMax, }) } // If child policy is a different type, recreate the sub-balancer. - if cib.config == nil || cib.config.ChildPolicy.Name != newConfig.ChildPolicy.Name { - if cib.childLB != nil { - cib.childLB.Close() + if b.config == nil || b.config.ChildPolicy.Name != newConfig.ChildPolicy.Name { + if b.childLB != nil { + b.childLB.Close() } - cib.childLB = bb.Build(cib, cib.bOpts) + b.childLB = bb.Build(b, b.buildOpts) } - cib.config = newConfig + b.config = newConfig - if cib.childLB == nil { + if b.childLB == nil { // This is not an expected situation, and should be super rare in // practice. // @@ -278,26 +277,26 @@ func (cib *clusterImplBalancer) UpdateClientConnState(s balancer.ClientConnState } // Addresses and sub-balancer config are sent to sub-balancer. - return cib.childLB.UpdateClientConnState(balancer.ClientConnState{ + return b.childLB.UpdateClientConnState(balancer.ClientConnState{ ResolverState: s.ResolverState, - BalancerConfig: cib.config.ChildPolicy.Config, + BalancerConfig: b.config.ChildPolicy.Config, }) } -func (cib *clusterImplBalancer) ResolverError(err error) { - if cib.closed.HasFired() { - cib.logger.Warningf("xds: received resolver error {%+v} after clusterImplBalancer was closed", err) +func (b *clusterImplBalancer) ResolverError(err error) { + if b.closed.HasFired() { + b.logger.Warningf("xds: received resolver error {%+v} after clusterImplBalancer was closed", err) return } - if cib.childLB != nil { - cib.childLB.ResolverError(err) + if b.childLB != nil { + b.childLB.ResolverError(err) } } -func (cib *clusterImplBalancer) UpdateSubConnState(sc balancer.SubConn, s balancer.SubConnState) { - if cib.closed.HasFired() { - cib.logger.Warningf("xds: received subconn state change {%+v, %+v} after clusterImplBalancer was closed", sc, s) +func (b *clusterImplBalancer) UpdateSubConnState(sc balancer.SubConn, s balancer.SubConnState) { + if b.closed.HasFired() { + b.logger.Warningf("xds: received subconn state change {%+v, %+v} after clusterImplBalancer was closed", sc, s) return } @@ -309,64 +308,61 @@ func (cib *clusterImplBalancer) UpdateSubConnState(sc balancer.SubConn, s balanc // knows). The parent priority policy is configured to ignore re-resolution // signal from the EDS children. if s.ConnectivityState == connectivity.TransientFailure { - cib.ClientConn.ResolveNow(resolver.ResolveNowOptions{}) + b.ClientConn.ResolveNow(resolver.ResolveNowOptions{}) } - if cib.childLB != nil { - cib.childLB.UpdateSubConnState(sc, s) + if b.childLB != nil { + b.childLB.UpdateSubConnState(sc, s) } } -func (cib *clusterImplBalancer) Close() { - cib.mu.Lock() - cib.closed.Fire() - cib.mu.Unlock() +func (b *clusterImplBalancer) Close() { + b.mu.Lock() + b.closed.Fire() + b.mu.Unlock() - if cib.childLB != nil { - cib.childLB.Close() - cib.childLB = nil + if b.childLB != nil { + b.childLB.Close() + b.childLB = nil } - if newXDSClient != nil { - cib.xdsC.Close() - } - cib.logger.Infof("Shutdown") + b.logger.Infof("Shutdown") } // Override methods to accept updates from the child LB. -func (cib *clusterImplBalancer) UpdateState(state balancer.State) { +func (b *clusterImplBalancer) UpdateState(state balancer.State) { // Instead of updating parent ClientConn inline, send state to run(). - cib.pickerUpdateCh.Put(state) + b.pickerUpdateCh.Put(state) } -func (cib *clusterImplBalancer) setClusterName(n string) { - cib.clusterNameMu.Lock() - defer cib.clusterNameMu.Unlock() - cib.clusterName = n +func (b *clusterImplBalancer) setClusterName(n string) { + b.clusterNameMu.Lock() + defer b.clusterNameMu.Unlock() + b.clusterName = n } -func (cib *clusterImplBalancer) getClusterName() string { - cib.clusterNameMu.Lock() - defer cib.clusterNameMu.Unlock() - return cib.clusterName +func (b *clusterImplBalancer) getClusterName() string { + b.clusterNameMu.Lock() + defer b.clusterNameMu.Unlock() + return b.clusterName } -func (cib *clusterImplBalancer) NewSubConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (balancer.SubConn, error) { - clusterName := cib.getClusterName() +func (b *clusterImplBalancer) NewSubConn(addrs []resolver.Address, opts balancer.NewSubConnOptions) (balancer.SubConn, error) { + clusterName := b.getClusterName() newAddrs := make([]resolver.Address, len(addrs)) for i, addr := range addrs { newAddrs[i] = internal.SetXDSHandshakeClusterName(addr, clusterName) } - return cib.ClientConn.NewSubConn(newAddrs, opts) + return b.ClientConn.NewSubConn(newAddrs, opts) } -func (cib *clusterImplBalancer) UpdateAddresses(sc balancer.SubConn, addrs []resolver.Address) { - clusterName := cib.getClusterName() +func (b *clusterImplBalancer) UpdateAddresses(sc balancer.SubConn, addrs []resolver.Address) { + clusterName := b.getClusterName() newAddrs := make([]resolver.Address, len(addrs)) for i, addr := range addrs { newAddrs[i] = internal.SetXDSHandshakeClusterName(addr, clusterName) } - cib.ClientConn.UpdateAddresses(sc, newAddrs) + b.ClientConn.UpdateAddresses(sc, newAddrs) } type dropConfigs struct { @@ -375,39 +371,39 @@ type dropConfigs struct { requestCountMax uint32 } -func (cib *clusterImplBalancer) run() { +func (b *clusterImplBalancer) run() { for { select { - case update := <-cib.pickerUpdateCh.Get(): - cib.pickerUpdateCh.Load() - cib.mu.Lock() - if cib.closed.HasFired() { - cib.mu.Unlock() + case update := <-b.pickerUpdateCh.Get(): + b.pickerUpdateCh.Load() + b.mu.Lock() + if b.closed.HasFired() { + b.mu.Unlock() return } switch u := update.(type) { case balancer.State: - cib.childState = u - cib.ClientConn.UpdateState(balancer.State{ - ConnectivityState: cib.childState.ConnectivityState, - Picker: newDropPicker(cib.childState, &dropConfigs{ - drops: cib.drops, - requestCounter: cib.requestCounter, - requestCountMax: cib.requestCountMax, - }, cib.loadWrapper), + b.childState = u + b.ClientConn.UpdateState(balancer.State{ + ConnectivityState: b.childState.ConnectivityState, + Picker: newDropPicker(b.childState, &dropConfigs{ + drops: b.drops, + requestCounter: b.requestCounter, + requestCountMax: b.requestCountMax, + }, b.loadWrapper), }) case *dropConfigs: - cib.drops = u.drops - cib.requestCounter = u.requestCounter - if cib.childState.Picker != nil { - cib.ClientConn.UpdateState(balancer.State{ - ConnectivityState: cib.childState.ConnectivityState, - Picker: newDropPicker(cib.childState, u, cib.loadWrapper), + b.drops = u.drops + b.requestCounter = u.requestCounter + if b.childState.Picker != nil { + b.ClientConn.UpdateState(balancer.State{ + ConnectivityState: b.childState.ConnectivityState, + Picker: newDropPicker(b.childState, u, b.loadWrapper), }) } } - cib.mu.Unlock() - case <-cib.closed.Done(): + b.mu.Unlock() + case <-b.closed.Done(): return } } diff --git a/xds/internal/balancer/clusterimpl/picker.go b/xds/internal/balancer/clusterimpl/picker.go index 7a31615510d3..a03b89179ee4 100644 --- a/xds/internal/balancer/clusterimpl/picker.go +++ b/xds/internal/balancer/clusterimpl/picker.go @@ -24,8 +24,8 @@ import ( "google.golang.org/grpc/connectivity" "google.golang.org/grpc/internal/wrr" "google.golang.org/grpc/status" - "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/load" ) // NewRandomWRR is used when calculating drops. It's exported so that tests can @@ -75,7 +75,7 @@ type dropPicker struct { drops []*dropper s balancer.State loadStore loadReporter - counter *client.ServiceRequestsCounter + counter *xdsclient.ServiceRequestsCounter countMax uint32 } diff --git a/xds/internal/balancer/edsbalancer/eds.go b/xds/internal/balancer/edsbalancer/eds.go index 21e3f43be74e..376d19168911 100644 --- a/xds/internal/balancer/edsbalancer/eds.go +++ b/xds/internal/balancer/edsbalancer/eds.go @@ -35,36 +35,37 @@ import ( "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/internal/grpcsync" "google.golang.org/grpc/serviceconfig" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/load" ) const edsName = "eds_experimental" -// xdsClientInterface contains only the xds_client methods needed by EDS -// balancer. It's defined so we can override xdsclient.New function in tests. -type xdsClientInterface interface { +// xdsClient contains only the xds_client methods needed by EDS balancer. It's +// defined so we can override xdsclient.New function in tests. +type xdsClient interface { WatchEndpoints(clusterName string, edsCb func(xdsclient.EndpointsUpdate, error)) (cancel func()) ReportLoad(server string) (loadStore *load.Store, cancel func()) - Close() } var ( newEDSBalancer = func(cc balancer.ClientConn, opts balancer.BuildOptions, enqueueState func(priorityType, balancer.State), lw load.PerClusterReporter, logger *grpclog.PrefixLogger) edsBalancerImplInterface { return newEDSBalancerImpl(cc, opts, enqueueState, lw, logger) } - newXDSClient func() (xdsClientInterface, error) + newXDSClient func() (xdsClient, error) ) func init() { - balancer.Register(&edsBalancerBuilder{}) + balancer.Register(edsBB{}) } -type edsBalancerBuilder struct{} +type edsBB struct{} + +var _ balancer.ConfigParser = edsBB{} // Build helps implement the balancer.Builder interface. -func (b *edsBalancerBuilder) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer { - x := &edsBalancer{ +func (edsBB) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer { + b := &edsBalancer{ cc: cc, closed: grpcsync.NewEvent(), done: grpcsync.NewEvent(), @@ -74,29 +75,29 @@ func (b *edsBalancerBuilder) Build(cc balancer.ClientConn, opts balancer.BuildOp loadWrapper: loadstore.NewWrapper(), config: &EDSConfig{}, } - x.logger = prefixLogger(x) + b.logger = prefixLogger(b) if newXDSClient != nil { // For tests client, err := newXDSClient() if err != nil { - x.logger.Errorf("xds: failed to create xds-client: %v", err) + b.logger.Errorf("xds: failed to create xds-client: %v", err) return nil } - x.xdsClient = client + b.xdsClient = client } - x.edsImpl = newEDSBalancer(x.cc, opts, x.enqueueChildBalancerState, x.loadWrapper, x.logger) - x.logger.Infof("Created") - go x.run() - return x + b.edsImpl = newEDSBalancer(b.cc, opts, b.enqueueChildBalancerState, b.loadWrapper, b.logger) + b.logger.Infof("Created") + go b.run() + return b } -func (b *edsBalancerBuilder) Name() string { +func (edsBB) Name() string { return edsName } -func (b *edsBalancerBuilder) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancingConfig, error) { +func (edsBB) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancingConfig, error) { var cfg EDSConfig if err := json.Unmarshal(c, &cfg); err != nil { return nil, fmt.Errorf("unable to unmarshal balancer config %s into EDSConfig, error: %v", string(c), err) @@ -145,7 +146,7 @@ type edsBalancer struct { xdsClientUpdate chan *edsUpdate childPolicyUpdate *buffer.Unbounded - xdsClient xdsClientInterface + xdsClient xdsClient loadWrapper *loadstore.Wrapper config *EDSConfig // may change when passed a different service config edsImpl edsBalancerImplInterface @@ -162,25 +163,22 @@ type edsBalancer struct { // updates from grpc, xdsClient and load balancer. It synchronizes the // operations that happen inside edsBalancer. It exits when edsBalancer is // closed. -func (x *edsBalancer) run() { +func (b *edsBalancer) run() { for { select { - case update := <-x.grpcUpdate: - x.handleGRPCUpdate(update) - case update := <-x.xdsClientUpdate: - x.handleXDSClientUpdate(update) - case update := <-x.childPolicyUpdate.Get(): - x.childPolicyUpdate.Load() + case update := <-b.grpcUpdate: + b.handleGRPCUpdate(update) + case update := <-b.xdsClientUpdate: + b.handleXDSClientUpdate(update) + case update := <-b.childPolicyUpdate.Get(): + b.childPolicyUpdate.Load() u := update.(*balancerStateWithPriority) - x.edsImpl.updateState(u.priority, u.s) - case <-x.closed.Done(): - x.cancelWatch() - if newXDSClient != nil { - x.xdsClient.Close() - } - x.edsImpl.close() - x.logger.Infof("Shutdown") - x.done.Fire() + b.edsImpl.updateState(u.priority, u.s) + case <-b.closed.Done(): + b.cancelWatch() + b.edsImpl.close() + b.logger.Infof("Shutdown") + b.done.Fire() return } } @@ -199,68 +197,68 @@ func (x *edsBalancer) run() { // watcher should keep watching. // In both cases, the sub-balancers will be closed, and the future picks will // fail. -func (x *edsBalancer) handleErrorFromUpdate(err error, fromParent bool) { - x.logger.Warningf("Received error: %v", err) +func (b *edsBalancer) handleErrorFromUpdate(err error, fromParent bool) { + b.logger.Warningf("Received error: %v", err) if xdsclient.ErrType(err) == xdsclient.ErrorTypeResourceNotFound { if fromParent { // This is an error from the parent ClientConn (can be the parent // CDS balancer), and is a resource-not-found error. This means the // resource (can be either LDS or CDS) was removed. Stop the EDS // watch. - x.cancelWatch() + b.cancelWatch() } - x.edsImpl.handleEDSResponse(xdsclient.EndpointsUpdate{}) + b.edsImpl.handleEDSResponse(xdsclient.EndpointsUpdate{}) } } -func (x *edsBalancer) handleGRPCUpdate(update interface{}) { +func (b *edsBalancer) handleGRPCUpdate(update interface{}) { switch u := update.(type) { case *subConnStateUpdate: - x.edsImpl.handleSubConnStateChange(u.sc, u.state.ConnectivityState) + b.edsImpl.handleSubConnStateChange(u.sc, u.state.ConnectivityState) case *balancer.ClientConnState: - x.logger.Infof("Received update from resolver, balancer config: %+v", pretty.ToJSON(u.BalancerConfig)) + b.logger.Infof("Received update from resolver, balancer config: %+v", pretty.ToJSON(u.BalancerConfig)) cfg, _ := u.BalancerConfig.(*EDSConfig) if cfg == nil { // service config parsing failed. should never happen. return } - if err := x.handleServiceConfigUpdate(cfg); err != nil { - x.logger.Warningf("failed to update xDS client: %v", err) + if err := b.handleServiceConfigUpdate(cfg); err != nil { + b.logger.Warningf("failed to update xDS client: %v", err) } - x.edsImpl.updateServiceRequestsConfig(cfg.ClusterName, cfg.MaxConcurrentRequests) + b.edsImpl.updateServiceRequestsConfig(cfg.ClusterName, cfg.MaxConcurrentRequests) // We will update the edsImpl with the new child policy, if we got a // different one. - if !cmp.Equal(cfg.ChildPolicy, x.config.ChildPolicy, cmpopts.EquateEmpty()) { + if !cmp.Equal(cfg.ChildPolicy, b.config.ChildPolicy, cmpopts.EquateEmpty()) { if cfg.ChildPolicy != nil { - x.edsImpl.handleChildPolicy(cfg.ChildPolicy.Name, cfg.ChildPolicy.Config) + b.edsImpl.handleChildPolicy(cfg.ChildPolicy.Name, cfg.ChildPolicy.Config) } else { - x.edsImpl.handleChildPolicy(roundrobin.Name, nil) + b.edsImpl.handleChildPolicy(roundrobin.Name, nil) } } - x.config = cfg + b.config = cfg case error: - x.handleErrorFromUpdate(u, true) + b.handleErrorFromUpdate(u, true) default: // unreachable path - x.logger.Errorf("wrong update type: %T", update) + b.logger.Errorf("wrong update type: %T", update) } } // handleServiceConfigUpdate applies the service config update, watching a new // EDS service name and restarting LRS stream, as required. -func (x *edsBalancer) handleServiceConfigUpdate(config *EDSConfig) error { +func (b *edsBalancer) handleServiceConfigUpdate(config *EDSConfig) error { var updateLoadClusterAndService bool - if x.clusterName != config.ClusterName { + if b.clusterName != config.ClusterName { updateLoadClusterAndService = true - x.clusterName = config.ClusterName - x.edsImpl.updateClusterName(x.clusterName) + b.clusterName = config.ClusterName + b.edsImpl.updateClusterName(b.clusterName) } - if x.edsServiceName != config.EDSServiceName { + if b.edsServiceName != config.EDSServiceName { updateLoadClusterAndService = true - x.edsServiceName = config.EDSServiceName + b.edsServiceName = config.EDSServiceName } // If EDSServiceName is set, use it to watch EDS. Otherwise, use the cluster @@ -270,14 +268,14 @@ func (x *edsBalancer) handleServiceConfigUpdate(config *EDSConfig) error { newEDSToWatch = config.ClusterName } var restartEDSWatch bool - if x.edsToWatch != newEDSToWatch { + if b.edsToWatch != newEDSToWatch { restartEDSWatch = true - x.edsToWatch = newEDSToWatch + b.edsToWatch = newEDSToWatch } // Restart EDS watch when the eds name has changed. if restartEDSWatch { - x.startEndpointsWatch() + b.startEndpointsWatch() } if updateLoadClusterAndService { @@ -288,13 +286,13 @@ func (x *edsBalancer) handleServiceConfigUpdate(config *EDSConfig) error { // // This is OK for now, because we don't actually expect edsServiceName // to change. Fix this (a bigger change) will happen later. - x.loadWrapper.UpdateClusterAndService(x.clusterName, x.edsServiceName) + b.loadWrapper.UpdateClusterAndService(b.clusterName, b.edsServiceName) } // Restart load reporting when the loadReportServer name has changed. - if !equalStringPointers(x.loadReportServer, config.LrsLoadReportingServerName) { - loadStore := x.startLoadReport(config.LrsLoadReportingServerName) - x.loadWrapper.UpdateLoadStore(loadStore) + if !equalStringPointers(b.loadReportServer, config.LrsLoadReportingServerName) { + loadStore := b.startLoadReport(config.LrsLoadReportingServerName) + b.loadWrapper.UpdateLoadStore(loadStore) } return nil @@ -304,32 +302,32 @@ func (x *edsBalancer) handleServiceConfigUpdate(config *EDSConfig) error { // // This usually means load report needs to be restarted, but this function does // NOT do that. Caller needs to call startLoadReport separately. -func (x *edsBalancer) startEndpointsWatch() { - if x.cancelEndpointsWatch != nil { - x.cancelEndpointsWatch() +func (b *edsBalancer) startEndpointsWatch() { + if b.cancelEndpointsWatch != nil { + b.cancelEndpointsWatch() } - edsToWatch := x.edsToWatch - cancelEDSWatch := x.xdsClient.WatchEndpoints(edsToWatch, func(update xdsclient.EndpointsUpdate, err error) { - x.logger.Infof("Watch update from xds-client %p, content: %+v", x.xdsClient, pretty.ToJSON(update)) - x.handleEDSUpdate(update, err) + edsToWatch := b.edsToWatch + cancelEDSWatch := b.xdsClient.WatchEndpoints(edsToWatch, func(update xdsclient.EndpointsUpdate, err error) { + b.logger.Infof("Watch update from xds-client %p, content: %+v", b.xdsClient, pretty.ToJSON(update)) + b.handleEDSUpdate(update, err) }) - x.logger.Infof("Watch started on resource name %v with xds-client %p", edsToWatch, x.xdsClient) - x.cancelEndpointsWatch = func() { + b.logger.Infof("Watch started on resource name %v with xds-client %p", edsToWatch, b.xdsClient) + b.cancelEndpointsWatch = func() { cancelEDSWatch() - x.logger.Infof("Watch cancelled on resource name %v with xds-client %p", edsToWatch, x.xdsClient) + b.logger.Infof("Watch cancelled on resource name %v with xds-client %p", edsToWatch, b.xdsClient) } } -func (x *edsBalancer) cancelWatch() { - x.loadReportServer = nil - if x.cancelLoadReport != nil { - x.cancelLoadReport() - x.cancelLoadReport = nil +func (b *edsBalancer) cancelWatch() { + b.loadReportServer = nil + if b.cancelLoadReport != nil { + b.cancelLoadReport() + b.cancelLoadReport = nil } - if x.cancelEndpointsWatch != nil { - x.edsToWatch = "" - x.cancelEndpointsWatch() - x.cancelEndpointsWatch = nil + if b.cancelEndpointsWatch != nil { + b.edsToWatch = "" + b.cancelEndpointsWatch() + b.cancelEndpointsWatch = nil } } @@ -339,26 +337,26 @@ func (x *edsBalancer) cancelWatch() { // Caller can cal this when the loadReportServer name changes, but // edsServiceName doesn't (so we only need to restart load reporting, not EDS // watch). -func (x *edsBalancer) startLoadReport(loadReportServer *string) *load.Store { - x.loadReportServer = loadReportServer - if x.cancelLoadReport != nil { - x.cancelLoadReport() - x.cancelLoadReport = nil +func (b *edsBalancer) startLoadReport(loadReportServer *string) *load.Store { + b.loadReportServer = loadReportServer + if b.cancelLoadReport != nil { + b.cancelLoadReport() + b.cancelLoadReport = nil } if loadReportServer == nil { return nil } - ls, cancel := x.xdsClient.ReportLoad(*loadReportServer) - x.cancelLoadReport = cancel + ls, cancel := b.xdsClient.ReportLoad(*loadReportServer) + b.cancelLoadReport = cancel return ls } -func (x *edsBalancer) handleXDSClientUpdate(update *edsUpdate) { +func (b *edsBalancer) handleXDSClientUpdate(update *edsUpdate) { if err := update.err; err != nil { - x.handleErrorFromUpdate(err, false) + b.handleErrorFromUpdate(err, false) return } - x.edsImpl.handleEDSResponse(update.resp) + b.edsImpl.handleEDSResponse(update.resp) } type subConnStateUpdate struct { @@ -366,36 +364,36 @@ type subConnStateUpdate struct { state balancer.SubConnState } -func (x *edsBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) { +func (b *edsBalancer) UpdateSubConnState(sc balancer.SubConn, state balancer.SubConnState) { update := &subConnStateUpdate{ sc: sc, state: state, } select { - case x.grpcUpdate <- update: - case <-x.closed.Done(): + case b.grpcUpdate <- update: + case <-b.closed.Done(): } } -func (x *edsBalancer) ResolverError(err error) { +func (b *edsBalancer) ResolverError(err error) { select { - case x.grpcUpdate <- err: - case <-x.closed.Done(): + case b.grpcUpdate <- err: + case <-b.closed.Done(): } } -func (x *edsBalancer) UpdateClientConnState(s balancer.ClientConnState) error { - if x.xdsClient == nil { +func (b *edsBalancer) UpdateClientConnState(s balancer.ClientConnState) error { + if b.xdsClient == nil { c := xdsclient.FromResolverState(s.ResolverState) if c == nil { return balancer.ErrBadResolverState } - x.xdsClient = c + b.xdsClient = c } select { - case x.grpcUpdate <- &s: - case <-x.closed.Done(): + case b.grpcUpdate <- &s: + case <-b.closed.Done(): } return nil } @@ -405,10 +403,10 @@ type edsUpdate struct { err error } -func (x *edsBalancer) handleEDSUpdate(resp xdsclient.EndpointsUpdate, err error) { +func (b *edsBalancer) handleEDSUpdate(resp xdsclient.EndpointsUpdate, err error) { select { - case x.xdsClientUpdate <- &edsUpdate{resp: resp, err: err}: - case <-x.closed.Done(): + case b.xdsClientUpdate <- &edsUpdate{resp: resp, err: err}: + case <-b.closed.Done(): } } @@ -417,16 +415,16 @@ type balancerStateWithPriority struct { s balancer.State } -func (x *edsBalancer) enqueueChildBalancerState(p priorityType, s balancer.State) { - x.childPolicyUpdate.Put(&balancerStateWithPriority{ +func (b *edsBalancer) enqueueChildBalancerState(p priorityType, s balancer.State) { + b.childPolicyUpdate.Put(&balancerStateWithPriority{ priority: p, s: s, }) } -func (x *edsBalancer) Close() { - x.closed.Fire() - <-x.done.Done() +func (b *edsBalancer) Close() { + b.closed.Fire() + <-b.done.Done() } // equalStringPointers returns true if diff --git a/xds/internal/balancer/edsbalancer/eds_impl.go b/xds/internal/balancer/edsbalancer/eds_impl.go index 63b75caae8f9..db11dec6f2f8 100644 --- a/xds/internal/balancer/edsbalancer/eds_impl.go +++ b/xds/internal/balancer/edsbalancer/eds_impl.go @@ -37,9 +37,8 @@ import ( xdsi "google.golang.org/grpc/xds/internal" "google.golang.org/grpc/xds/internal/balancer/balancergroup" "google.golang.org/grpc/xds/internal/balancer/weightedtarget/weightedaggregator" - "google.golang.org/grpc/xds/internal/client" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/load" ) // TODO: make this a environment variable? @@ -102,7 +101,7 @@ type edsBalancerImpl struct { dropConfig []xdsclient.OverloadDropConfig drops []*dropper innerState balancer.State // The state of the picker without drop support. - serviceRequestsCounter *client.ServiceRequestsCounter + serviceRequestsCounter *xdsclient.ServiceRequestsCounter serviceRequestCountMax uint32 clusterNameMu sync.Mutex @@ -425,7 +424,7 @@ func (edsImpl *edsBalancerImpl) updateServiceRequestsConfig(serviceName string, edsImpl.pickerMu.Lock() var updatePicker bool if edsImpl.serviceRequestsCounter == nil || edsImpl.serviceRequestsCounter.ServiceName != serviceName { - edsImpl.serviceRequestsCounter = client.GetServiceRequestsCounter(serviceName) + edsImpl.serviceRequestsCounter = xdsclient.GetServiceRequestsCounter(serviceName) updatePicker = true } @@ -540,11 +539,11 @@ type dropPicker struct { drops []*dropper p balancer.Picker loadStore load.PerClusterReporter - counter *client.ServiceRequestsCounter + counter *xdsclient.ServiceRequestsCounter countMax uint32 } -func newDropPicker(p balancer.Picker, drops []*dropper, loadStore load.PerClusterReporter, counter *client.ServiceRequestsCounter, countMax uint32) *dropPicker { +func newDropPicker(p balancer.Picker, drops []*dropper, loadStore load.PerClusterReporter, counter *xdsclient.ServiceRequestsCounter, countMax uint32) *dropPicker { return &dropPicker{ drops: drops, p: p, diff --git a/xds/internal/balancer/edsbalancer/eds_impl_test.go b/xds/internal/balancer/edsbalancer/eds_impl_test.go index 3cfc620a2400..ec60dc1b1e60 100644 --- a/xds/internal/balancer/edsbalancer/eds_impl_test.go +++ b/xds/internal/balancer/edsbalancer/eds_impl_test.go @@ -38,10 +38,9 @@ import ( "google.golang.org/grpc/internal/xds/env" xdsinternal "google.golang.org/grpc/xds/internal" "google.golang.org/grpc/xds/internal/balancer/balancergroup" - "google.golang.org/grpc/xds/internal/client" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/load" "google.golang.org/grpc/xds/internal/testutils" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/load" ) var ( @@ -835,7 +834,7 @@ func (s) TestEDS_LoadReport(t *testing.T) { ) var maxRequestsTemp uint32 = cbMaxRequests edsb.updateServiceRequestsConfig(testServiceName, &maxRequestsTemp) - defer client.ClearCounterForTesting(testServiceName) + defer xdsclient.ClearCounterForTesting(testServiceName) backendToBalancerID := make(map[balancer.SubConn]xdsinternal.LocalityID) diff --git a/xds/internal/balancer/edsbalancer/eds_test.go b/xds/internal/balancer/edsbalancer/eds_test.go index 3fe66098973c..679fa321bd10 100644 --- a/xds/internal/balancer/edsbalancer/eds_test.go +++ b/xds/internal/balancer/edsbalancer/eds_test.go @@ -41,11 +41,11 @@ import ( "google.golang.org/grpc/resolver" "google.golang.org/grpc/serviceconfig" "google.golang.org/grpc/xds/internal" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/load" "google.golang.org/grpc/xds/internal/testutils/fakeclient" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/load" - _ "google.golang.org/grpc/xds/internal/client/v2" // V2 client registration. + _ "google.golang.org/grpc/xds/internal/xdsclient/v2" // V2 client registration. ) const ( @@ -70,10 +70,6 @@ var ( } ) -func init() { - balancer.Register(&edsBalancerBuilder{}) -} - func subConnFromPicker(p balancer.Picker) func() balancer.SubConn { return func() balancer.SubConn { scst, _ := p.Pick(balancer.PickInfo{}) @@ -260,7 +256,7 @@ func waitForNewEDSLB(ctx context.Context, ch *testutils.Channel) (*fakeEDSBalanc func setup(edsLBCh *testutils.Channel) (*fakeclient.Client, func()) { xdsC := fakeclient.NewClientWithName(testBalancerNameFooBar) oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { return xdsC, nil } + newXDSClient = func() (xdsClient, error) { return xdsC, nil } origNewEDSBalancer := newEDSBalancer newEDSBalancer = func(cc balancer.ClientConn, _ balancer.BuildOptions, _ func(priorityType, balancer.State), _ load.PerClusterReporter, _ *grpclog.PrefixLogger) edsBalancerImplInterface { @@ -890,8 +886,7 @@ func (s) TestBalancerConfigParsing(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - b := &edsBalancerBuilder{} - got, err := b.ParseConfig(tt.js) + got, err := edsBB{}.ParseConfig(tt.js) if (err != nil) != tt.wantErr { t.Fatalf("edsBalancerBuilder.ParseConfig() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/xds/internal/balancer/edsbalancer/eds_testutil.go b/xds/internal/balancer/edsbalancer/eds_testutil.go index 5e37cdcb47c7..f6d86e950d9a 100644 --- a/xds/internal/balancer/edsbalancer/eds_testutil.go +++ b/xds/internal/balancer/edsbalancer/eds_testutil.go @@ -26,7 +26,7 @@ import ( endpointpb "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint" typepb "github.com/envoyproxy/go-control-plane/envoy/type" "google.golang.org/grpc/xds/internal" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" ) // parseEDSRespProtoForTesting parses EDS response, and panic if parsing fails. diff --git a/xds/internal/balancer/edsbalancer/util.go b/xds/internal/balancer/edsbalancer/util.go index 132950426466..fa9ada6c9dd6 100644 --- a/xds/internal/balancer/edsbalancer/util.go +++ b/xds/internal/balancer/edsbalancer/util.go @@ -18,7 +18,7 @@ package edsbalancer import ( "google.golang.org/grpc/internal/wrr" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" ) var newRandomWRR = wrr.NewRandom diff --git a/xds/internal/balancer/edsbalancer/util_test.go b/xds/internal/balancer/edsbalancer/util_test.go index b94905d49889..406131fecc9b 100644 --- a/xds/internal/balancer/edsbalancer/util_test.go +++ b/xds/internal/balancer/edsbalancer/util_test.go @@ -21,7 +21,7 @@ package edsbalancer import ( "testing" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/testutils" ) diff --git a/xds/internal/balancer/edsbalancer/xds_lrs_test.go b/xds/internal/balancer/edsbalancer/xds_lrs_test.go index 8b7aab657667..d5b40dd98d32 100644 --- a/xds/internal/balancer/edsbalancer/xds_lrs_test.go +++ b/xds/internal/balancer/edsbalancer/xds_lrs_test.go @@ -34,7 +34,7 @@ import ( func (s) TestXDSLoadReporting(t *testing.T) { xdsC := fakeclient.NewClient() oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { return xdsC, nil } + newXDSClient = func() (xdsClient, error) { return xdsC, nil } defer func() { newXDSClient = oldNewXDSClient }() builder := balancer.Get(edsName) diff --git a/xds/internal/balancer/edsbalancer/xds_old.go b/xds/internal/balancer/edsbalancer/xds_old.go index 6729e6801f15..99621facf1f0 100644 --- a/xds/internal/balancer/edsbalancer/xds_old.go +++ b/xds/internal/balancer/edsbalancer/xds_old.go @@ -32,15 +32,15 @@ import "google.golang.org/grpc/balancer" const xdsName = "xds_experimental" func init() { - balancer.Register(&xdsBalancerBuilder{}) + balancer.Register(xdsBB{}) } -// xdsBalancerBuilder register edsBalancerBuilder (now with name -// "eds_experimental") under the old name "xds_experimental". -type xdsBalancerBuilder struct { - edsBalancerBuilder +// xdsBB registers edsBB (now with name "eds_experimental") under the old name +// "xds_experimental". +type xdsBB struct { + edsBB } -func (b *xdsBalancerBuilder) Name() string { +func (xdsBB) Name() string { return xdsName } diff --git a/xds/internal/balancer/loadstore/load_store_wrapper.go b/xds/internal/balancer/loadstore/load_store_wrapper.go index 88fa344118cc..8ce958d71ca8 100644 --- a/xds/internal/balancer/loadstore/load_store_wrapper.go +++ b/xds/internal/balancer/loadstore/load_store_wrapper.go @@ -22,7 +22,7 @@ package loadstore import ( "sync" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient/load" ) // NewWrapper creates a Wrapper. diff --git a/xds/internal/balancer/lrs/balancer.go b/xds/internal/balancer/lrs/balancer.go index 5b044f480345..9590cc3b59e2 100644 --- a/xds/internal/balancer/lrs/balancer.go +++ b/xds/internal/balancer/lrs/balancer.go @@ -28,22 +28,22 @@ import ( "google.golang.org/grpc/internal/pretty" "google.golang.org/grpc/serviceconfig" "google.golang.org/grpc/xds/internal/balancer/loadstore" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/load" ) func init() { - balancer.Register(&lrsBB{}) + balancer.Register(lrsBB{}) } -var newXDSClient func() (xdsClientInterface, error) +var newXDSClient func() (xdsClient, error) // Name is the name of the LRS balancer. const Name = "lrs_experimental" type lrsBB struct{} -func (l *lrsBB) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer { +func (lrsBB) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer { b := &lrsBalancer{ cc: cc, buildOpts: opts, @@ -58,17 +58,17 @@ func (l *lrsBB) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balanc b.logger.Errorf("failed to create xds-client: %v", err) return nil } - b.client = newXDSClientWrapper(client) + b.xdsClient = newXDSClientWrapper(client) } return b } -func (l *lrsBB) Name() string { +func (lrsBB) Name() string { return Name } -func (l *lrsBB) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancingConfig, error) { +func (lrsBB) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancingConfig, error) { return parseConfig(c) } @@ -76,8 +76,8 @@ type lrsBalancer struct { cc balancer.ClientConn buildOpts balancer.BuildOptions - logger *grpclog.PrefixLogger - client *xdsClientWrapper + logger *grpclog.PrefixLogger + xdsClient *xdsClientWrapper config *LBConfig lb balancer.Balancer // The sub balancer. @@ -90,18 +90,18 @@ func (b *lrsBalancer) UpdateClientConnState(s balancer.ClientConnState) error { return fmt.Errorf("unexpected balancer config with type: %T", s.BalancerConfig) } - if b.client == nil { + if b.xdsClient == nil { c := xdsclient.FromResolverState(s.ResolverState) if c == nil { return balancer.ErrBadResolverState } - b.client = newXDSClientWrapper(c) + b.xdsClient = newXDSClientWrapper(c) } // Update load reporting config or xds client. This needs to be done before // updating the child policy because we need the loadStore from the updated // client to be passed to the ccWrapper. - if err := b.client.update(newConfig); err != nil { + if err := b.xdsClient.update(newConfig); err != nil { return err } @@ -118,7 +118,7 @@ func (b *lrsBalancer) UpdateClientConnState(s balancer.ClientConnState) error { if err != nil { return fmt.Errorf("failed to marshal LocalityID: %#v", newConfig.Locality) } - ccWrapper := newCCWrapper(b.cc, b.client.loadStore(), lidJSON) + ccWrapper := newCCWrapper(b.cc, b.xdsClient.loadStore(), lidJSON) b.lb = bb.Build(ccWrapper, b.buildOpts) } b.config = newConfig @@ -147,7 +147,7 @@ func (b *lrsBalancer) Close() { b.lb.Close() b.lb = nil } - b.client.close() + b.xdsClient.close() } type ccWrapper struct { @@ -169,15 +169,14 @@ func (ccw *ccWrapper) UpdateState(s balancer.State) { ccw.ClientConn.UpdateState(s) } -// xdsClientInterface contains only the xds_client methods needed by LRS +// xdsClient contains only the xds_client methods needed by LRS // balancer. It's defined so we can override xdsclient in tests. -type xdsClientInterface interface { +type xdsClient interface { ReportLoad(server string) (*load.Store, func()) - Close() } type xdsClientWrapper struct { - c xdsClientInterface + c xdsClient cancelLoadReport func() clusterName string edsServiceName string @@ -187,7 +186,7 @@ type xdsClientWrapper struct { loadWrapper *loadstore.Wrapper } -func newXDSClientWrapper(c xdsClientInterface) *xdsClientWrapper { +func newXDSClientWrapper(c xdsClient) *xdsClientWrapper { return &xdsClientWrapper{ c: c, loadWrapper: loadstore.NewWrapper(), @@ -256,7 +255,4 @@ func (w *xdsClientWrapper) close() { w.cancelLoadReport() w.cancelLoadReport = nil } - if newXDSClient != nil { - w.c.Close() - } } diff --git a/xds/internal/balancer/lrs/balancer_test.go b/xds/internal/balancer/lrs/balancer_test.go index f91937385a92..9ffa2894dad8 100644 --- a/xds/internal/balancer/lrs/balancer_test.go +++ b/xds/internal/balancer/lrs/balancer_test.go @@ -56,7 +56,7 @@ var ( func TestLoadReporting(t *testing.T) { xdsC := fakeclient.NewClient() oldNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { return xdsC, nil } + newXDSClient = func() (xdsClient, error) { return xdsC, nil } defer func() { newXDSClient = oldNewXDSClient }() builder := balancer.Get(Name) diff --git a/xds/internal/httpfilter/fault/fault_test.go b/xds/internal/httpfilter/fault/fault_test.go index c132e912f92a..35d4ae75ff59 100644 --- a/xds/internal/httpfilter/fault/fault_test.go +++ b/xds/internal/httpfilter/fault/fault_test.go @@ -56,7 +56,7 @@ import ( testpb "google.golang.org/grpc/test/grpc_testing" _ "google.golang.org/grpc/xds/internal/balancer" // Register the balancers. - _ "google.golang.org/grpc/xds/internal/client/v3" // Register the v3 xDS API client. + _ "google.golang.org/grpc/xds/internal/xdsclient/v3" // Register the v3 xDS API client. _ "google.golang.org/grpc/xds/internal/resolver" // Register the xds_resolver. ) diff --git a/xds/internal/resolver/matcher.go b/xds/internal/resolver/matcher.go index e329944e1db1..42a843deecaa 100644 --- a/xds/internal/resolver/matcher.go +++ b/xds/internal/resolver/matcher.go @@ -27,7 +27,7 @@ import ( iresolver "google.golang.org/grpc/internal/resolver" "google.golang.org/grpc/internal/xds/matcher" "google.golang.org/grpc/metadata" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" ) func routeToMatcher(r *xdsclient.Route) (*compositeMatcher, error) { diff --git a/xds/internal/resolver/serviceconfig.go b/xds/internal/resolver/serviceconfig.go index 49ee8970d7d8..8dcaa4620f29 100644 --- a/xds/internal/resolver/serviceconfig.go +++ b/xds/internal/resolver/serviceconfig.go @@ -31,7 +31,7 @@ import ( "google.golang.org/grpc/internal/xds/env" "google.golang.org/grpc/status" "google.golang.org/grpc/xds/internal/balancer/clustermanager" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/httpfilter" "google.golang.org/grpc/xds/internal/httpfilter/router" ) diff --git a/xds/internal/resolver/watch_service.go b/xds/internal/resolver/watch_service.go index f29fb32832e0..591cc3833937 100644 --- a/xds/internal/resolver/watch_service.go +++ b/xds/internal/resolver/watch_service.go @@ -26,7 +26,7 @@ import ( "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/internal/pretty" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" ) // serviceUpdate contains information received from the LDS/RDS responses which @@ -54,7 +54,7 @@ type ldsConfig struct { // Note that during race (e.g. an xDS response is received while the user is // calling cancel()), there's a small window where the callback can be called // after the watcher is canceled. The caller needs to handle this case. -func watchService(c xdsClientInterface, serviceName string, cb func(serviceUpdate, error), logger *grpclog.PrefixLogger) (cancel func()) { +func watchService(c xdsClient, serviceName string, cb func(serviceUpdate, error), logger *grpclog.PrefixLogger) (cancel func()) { w := &serviceUpdateWatcher{ logger: logger, c: c, @@ -70,7 +70,7 @@ func watchService(c xdsClientInterface, serviceName string, cb func(serviceUpdat // callback at the right time. type serviceUpdateWatcher struct { logger *grpclog.PrefixLogger - c xdsClientInterface + c xdsClient serviceName string ldsCancel func() serviceCb func(serviceUpdate, error) diff --git a/xds/internal/resolver/watch_service_test.go b/xds/internal/resolver/watch_service_test.go index 421e5345a9d2..5748d75a1f7c 100644 --- a/xds/internal/resolver/watch_service_test.go +++ b/xds/internal/resolver/watch_service_test.go @@ -29,7 +29,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "google.golang.org/grpc/internal/testutils" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/testutils/fakeclient" "google.golang.org/protobuf/proto" ) diff --git a/xds/internal/resolver/xds_resolver.go b/xds/internal/resolver/xds_resolver.go index 41e3899c285e..a6c2dd2e438a 100644 --- a/xds/internal/resolver/xds_resolver.go +++ b/xds/internal/resolver/xds_resolver.go @@ -28,10 +28,10 @@ import ( "google.golang.org/grpc/internal/grpcsync" "google.golang.org/grpc/internal/pretty" "google.golang.org/grpc/resolver" - "google.golang.org/grpc/xds/internal/client/bootstrap" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" iresolver "google.golang.org/grpc/internal/resolver" - xdsclient "google.golang.org/grpc/xds/internal/client" ) const xdsScheme = "xds" @@ -41,26 +41,26 @@ const xdsScheme = "xds" // the same time. func NewBuilder(config []byte) (resolver.Builder, error) { return &xdsResolverBuilder{ - newXDSClient: func() (xdsClientInterface, error) { + newXDSClient: func() (xdsClient, error) { return xdsclient.NewClientWithBootstrapContents(config) }, }, nil } // For overriding in unittests. -var newXDSClient = func() (xdsClientInterface, error) { return xdsclient.New() } +var newXDSClient = func() (xdsClient, error) { return xdsclient.New() } func init() { resolver.Register(&xdsResolverBuilder{}) } type xdsResolverBuilder struct { - newXDSClient func() (xdsClientInterface, error) + newXDSClient func() (xdsClient, error) } // Build helps implement the resolver.Builder interface. // -// The xds bootstrap process is performed (and a new xds client is built) every +// The xds bootstrap process is performed (and a new xds xdsClient is built) every // time an xds resolver is built. func (b *xdsResolverBuilder) Build(t resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) { r := &xdsResolver{ @@ -78,11 +78,11 @@ func (b *xdsResolverBuilder) Build(t resolver.Target, cc resolver.ClientConn, op newXDSClient = b.newXDSClient } - client, err := newXDSClient() + xdsClient, err := newXDSClient() if err != nil { return nil, fmt.Errorf("xds: failed to create xds-client: %v", err) } - r.client = client + r.xdsClient = xdsClient // If xds credentials were specified by the user, but bootstrap configs do // not contain any certificate provider configuration, it is better to fail @@ -96,18 +96,18 @@ func (b *xdsResolverBuilder) Build(t resolver.Target, cc resolver.ClientConn, op creds = opts.CredsBundle.TransportCredentials() } if xc, ok := creds.(interface{ UsesXDS() bool }); ok && xc.UsesXDS() { - bc := client.BootstrapConfig() + bc := xdsClient.BootstrapConfig() if len(bc.CertProviderConfigs) == 0 { return nil, errors.New("xds: xdsCreds specified but certificate_providers config missing in bootstrap file") } } // Register a watch on the xdsClient for the user's dial target. - cancelWatch := watchService(r.client, r.target.Endpoint, r.handleServiceUpdate, r.logger) - r.logger.Infof("Watch started on resource name %v with xds-client %p", r.target.Endpoint, r.client) + cancelWatch := watchService(r.xdsClient, r.target.Endpoint, r.handleServiceUpdate, r.logger) + r.logger.Infof("Watch started on resource name %v with xds-client %p", r.target.Endpoint, r.xdsClient) r.cancelWatch = func() { cancelWatch() - r.logger.Infof("Watch cancel on resource name %v with xds-client %p", r.target.Endpoint, r.client) + r.logger.Infof("Watch cancel on resource name %v with xds-client %p", r.target.Endpoint, r.xdsClient) } go r.run() @@ -119,9 +119,9 @@ func (*xdsResolverBuilder) Scheme() string { return xdsScheme } -// xdsClientInterface contains methods from xdsClient.Client which are used by +// xdsClient contains methods from xdsClient.XdsClient which are used by // the resolver. This will be faked out in unittests. -type xdsClientInterface interface { +type xdsClient interface { WatchListener(serviceName string, cb func(xdsclient.ListenerUpdate, error)) func() WatchRouteConfig(routeName string, cb func(xdsclient.RouteConfigUpdate, error)) func() BootstrapConfig() *bootstrap.Config @@ -149,7 +149,7 @@ type xdsResolver struct { logger *grpclog.PrefixLogger // The underlying xdsClient which performs all xDS requests and responses. - client xdsClientInterface + xdsClient xdsClient // A channel for the watch API callback to write service updates on to. The // updates are read by the run goroutine and passed on to the ClientConn. updateCh chan suWithError @@ -190,7 +190,7 @@ func (r *xdsResolver) sendNewServiceConfig(cs *configSelector) bool { r.cc.ReportError(err) return false } - r.logger.Infof("Received update on resource %v from xds-client %p, generated service config: %v", r.target.Endpoint, r.client, pretty.FormatJSON(sc)) + r.logger.Infof("Received update on resource %v from xds-client %p, generated service config: %v", r.target.Endpoint, r.xdsClient, pretty.FormatJSON(sc)) // Send the update to the ClientConn. state := iresolver.SetConfigSelector(resolver.State{ @@ -198,9 +198,9 @@ func (r *xdsResolver) sendNewServiceConfig(cs *configSelector) bool { }, cs) // Include the xds client for the LB policies to use. For unit tests, - // r.client may not be a full *xdsclient.Client, but it will always be in - // production. - if c, ok := r.client.(*xdsclient.Client); ok { + // r.xdsClient may not be a full *xdsclient.Client, but it will always be + // in production. + if c, ok := r.xdsClient.(*xdsclient.Client); ok { state = xdsclient.SetClient(state, c) } r.cc.UpdateState(state) @@ -216,7 +216,7 @@ func (r *xdsResolver) run() { return case update := <-r.updateCh: if update.err != nil { - r.logger.Warningf("Watch error on resource %v from xds-client %p, %v", r.target.Endpoint, r.client, update.err) + r.logger.Warningf("Watch error on resource %v from xds-client %p, %v", r.target.Endpoint, r.xdsClient, update.err) if xdsclient.ErrType(update.err) == xdsclient.ErrorTypeResourceNotFound { // If error is resource-not-found, it means the LDS // resource was removed. Ultimately send an empty service @@ -244,7 +244,7 @@ func (r *xdsResolver) run() { // Create the config selector for this update. cs, err := r.newConfigSelector(update.su) if err != nil { - r.logger.Warningf("Error parsing update on resource %v from xds-client %p: %v", r.target.Endpoint, r.client, err) + r.logger.Warningf("Error parsing update on resource %v from xds-client %p: %v", r.target.Endpoint, r.xdsClient, err) r.cc.ReportError(err) continue } @@ -287,7 +287,7 @@ func (*xdsResolver) ResolveNow(o resolver.ResolveNowOptions) {} // Close closes the resolver, and also closes the underlying xdsClient. func (r *xdsResolver) Close() { r.cancelWatch() - r.client.Close() + r.xdsClient.Close() r.closed.Fire() r.logger.Infof("Shutdown") } diff --git a/xds/internal/resolver/xds_resolver_test.go b/xds/internal/resolver/xds_resolver_test.go index eca561f369c5..d3a66595a358 100644 --- a/xds/internal/resolver/xds_resolver_test.go +++ b/xds/internal/resolver/xds_resolver_test.go @@ -44,13 +44,12 @@ import ( "google.golang.org/grpc/status" _ "google.golang.org/grpc/xds/internal/balancer/cdsbalancer" // To parse LB config "google.golang.org/grpc/xds/internal/balancer/clustermanager" - "google.golang.org/grpc/xds/internal/client" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" "google.golang.org/grpc/xds/internal/httpfilter" "google.golang.org/grpc/xds/internal/httpfilter/router" xdstestutils "google.golang.org/grpc/xds/internal/testutils" "google.golang.org/grpc/xds/internal/testutils/fakeclient" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" ) const ( @@ -115,19 +114,19 @@ func newTestClientConn() *testClientConn { func (s) TestResolverBuilder(t *testing.T) { tests := []struct { name string - xdsClientFunc func() (xdsClientInterface, error) + xdsClientFunc func() (xdsClient, error) wantErr bool }{ { name: "simple-good", - xdsClientFunc: func() (xdsClientInterface, error) { + xdsClientFunc: func() (xdsClient, error) { return fakeclient.NewClient(), nil }, wantErr: false, }, { name: "newXDSClient-throws-error", - xdsClientFunc: func() (xdsClientInterface, error) { + xdsClientFunc: func() (xdsClient, error) { return nil, errors.New("newXDSClient-throws-error") }, wantErr: true, @@ -168,7 +167,7 @@ func (s) TestResolverBuilder_xdsCredsBootstrapMismatch(t *testing.T) { // Fake out the xdsClient creation process by providing a fake, which does // not have any certificate provider configuration. oldClientMaker := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { + newXDSClient = func() (xdsClient, error) { fc := fakeclient.NewClient() fc.SetBootstrapConfig(&bootstrap.Config{}) return fc, nil @@ -195,7 +194,7 @@ func (s) TestResolverBuilder_xdsCredsBootstrapMismatch(t *testing.T) { } type setupOpts struct { - xdsClientFunc func() (xdsClientInterface, error) + xdsClientFunc func() (xdsClient, error) } func testSetup(t *testing.T, opts setupOpts) (*xdsResolver, *testClientConn, func()) { @@ -255,7 +254,7 @@ func waitForWatchRouteConfig(ctx context.Context, t *testing.T, xdsC *fakeclient func (s) TestXDSResolverWatchCallbackAfterClose(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer cancel() @@ -272,7 +271,7 @@ func (s) TestXDSResolverWatchCallbackAfterClose(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{cluster: {Weight: 1}}}}, + Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{cluster: {Weight: 1}}}}, }, }, }, nil) @@ -287,7 +286,7 @@ func (s) TestXDSResolverWatchCallbackAfterClose(t *testing.T) { func (s) TestXDSResolverBadServiceUpdate(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer xdsR.Close() defer cancel() @@ -313,7 +312,7 @@ func (s) TestXDSResolverBadServiceUpdate(t *testing.T) { func (s) TestXDSResolverGoodServiceUpdate(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer xdsR.Close() defer cancel() @@ -331,7 +330,7 @@ func (s) TestXDSResolverGoodServiceUpdate(t *testing.T) { wantClusters map[string]bool }{ { - routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"test-cluster-1": {Weight: 1}}}}, + routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"test-cluster-1": {Weight: 1}}}}, wantJSON: `{"loadBalancingConfig":[{ "xds_cluster_manager_experimental":{ "children":{ @@ -343,7 +342,7 @@ func (s) TestXDSResolverGoodServiceUpdate(t *testing.T) { wantClusters: map[string]bool{"test-cluster-1": true}, }, { - routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{ + routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{ "cluster_1": {Weight: 75}, "cluster_2": {Weight: 25}, }}}, @@ -367,7 +366,7 @@ func (s) TestXDSResolverGoodServiceUpdate(t *testing.T) { wantClusters: map[string]bool{"cluster_1": true, "cluster_2": true}, }, { - routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{ + routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{ "cluster_1": {Weight: 75}, "cluster_2": {Weight: 25}, }}}, @@ -447,7 +446,7 @@ func (s) TestXDSResolverGoodServiceUpdate(t *testing.T) { func (s) TestXDSResolverRemovedWithRPCs(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer cancel() defer xdsR.Close() @@ -464,7 +463,7 @@ func (s) TestXDSResolverRemovedWithRPCs(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"test-cluster-1": {Weight: 1}}}}, + Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"test-cluster-1": {Weight: 1}}}}, }, }, }, nil) @@ -507,7 +506,7 @@ func (s) TestXDSResolverRemovedWithRPCs(t *testing.T) { func (s) TestXDSResolverRemovedResource(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer cancel() defer xdsR.Close() @@ -524,7 +523,7 @@ func (s) TestXDSResolverRemovedResource(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"test-cluster-1": {Weight: 1}}}}, + Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"test-cluster-1": {Weight: 1}}}}, }, }, }, nil) @@ -615,7 +614,7 @@ func (s) TestXDSResolverRemovedResource(t *testing.T) { func (s) TestXDSResolverWRR(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer xdsR.Close() defer cancel() @@ -635,7 +634,7 @@ func (s) TestXDSResolverWRR(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{ + Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{ "A": {Weight: 5}, "B": {Weight: 10}, }}}, @@ -676,7 +675,7 @@ func (s) TestXDSResolverMaxStreamDuration(t *testing.T) { defer func(old bool) { env.TimeoutSupport = old }(env.TimeoutSupport) xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer xdsR.Close() defer cancel() @@ -696,7 +695,7 @@ func (s) TestXDSResolverMaxStreamDuration(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{ + Routes: []*xdsclient.Route{{ Prefix: newStringP("/foo"), WeightedClusters: map[string]xdsclient.WeightedCluster{"A": {Weight: 1}}, MaxStreamDuration: newDurationP(5 * time.Second), @@ -779,7 +778,7 @@ func (s) TestXDSResolverMaxStreamDuration(t *testing.T) { func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer xdsR.Close() defer cancel() @@ -796,7 +795,7 @@ func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"test-cluster-1": {Weight: 1}}}}, + Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"test-cluster-1": {Weight: 1}}}}, }, }, }, nil) @@ -846,7 +845,7 @@ func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"NEW": {Weight: 1}}}}, + Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"NEW": {Weight: 1}}}}, }, }, }, nil) @@ -856,7 +855,7 @@ func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"NEW": {Weight: 1}}}}, + Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"NEW": {Weight: 1}}}}, }, }, }, nil) @@ -895,7 +894,7 @@ func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"NEW": {Weight: 1}}}}, + Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{"NEW": {Weight: 1}}}}, }, }, }, nil) @@ -928,7 +927,7 @@ func (s) TestXDSResolverDelayedOnCommitted(t *testing.T) { func (s) TestXDSResolverGoodUpdateAfterError(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer xdsR.Close() defer cancel() @@ -954,7 +953,7 @@ func (s) TestXDSResolverGoodUpdateAfterError(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{cluster: {Weight: 1}}}}, + Routes: []*xdsclient.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsclient.WeightedCluster{cluster: {Weight: 1}}}}, }, }, }, nil) @@ -982,7 +981,7 @@ func (s) TestXDSResolverGoodUpdateAfterError(t *testing.T) { func (s) TestXDSResolverResourceNotFoundError(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer xdsR.Close() defer cancel() @@ -1028,7 +1027,7 @@ func (s) TestXDSResolverResourceNotFoundError(t *testing.T) { func (s) TestXDSResolverMultipleLDSUpdates(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer xdsR.Close() defer cancel() @@ -1203,7 +1202,7 @@ func (s) TestXDSResolverHTTPFilters(t *testing.T) { t.Run(tc.name, func(t *testing.T) { xdsC := fakeclient.NewClient() xdsR, tcc, cancel := testSetup(t, setupOpts{ - xdsClientFunc: func() (xdsClientInterface, error) { return xdsC, nil }, + xdsClientFunc: func() (xdsClient, error) { return xdsC, nil }, }) defer xdsR.Close() defer cancel() @@ -1229,7 +1228,7 @@ func (s) TestXDSResolverHTTPFilters(t *testing.T) { VirtualHosts: []*xdsclient.VirtualHost{ { Domains: []string{targetStr}, - Routes: []*client.Route{{ + Routes: []*xdsclient.Route{{ Prefix: newStringP("1"), WeightedClusters: map[string]xdsclient.WeightedCluster{ "A": {Weight: 1}, "B": {Weight: 1}, diff --git a/xds/internal/server/conn_wrapper.go b/xds/internal/server/conn_wrapper.go index a02d75b21445..0618a6cd4a4c 100644 --- a/xds/internal/server/conn_wrapper.go +++ b/xds/internal/server/conn_wrapper.go @@ -27,7 +27,7 @@ import ( "google.golang.org/grpc/credentials/tls/certprovider" xdsinternal "google.golang.org/grpc/internal/credentials/xds" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" ) // connWrapper is a thin wrapper around a net.Conn returned by Accept(). It diff --git a/xds/internal/server/listener_wrapper.go b/xds/internal/server/listener_wrapper.go index 17f31f28f576..7e5f7071a808 100644 --- a/xds/internal/server/listener_wrapper.go +++ b/xds/internal/server/listener_wrapper.go @@ -31,8 +31,8 @@ import ( internalbackoff "google.golang.org/grpc/internal/backoff" internalgrpclog "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/internal/grpcsync" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" ) var ( diff --git a/xds/internal/server/listener_wrapper_test.go b/xds/internal/server/listener_wrapper_test.go index b22f647a93ca..1dc53bdde5c4 100644 --- a/xds/internal/server/listener_wrapper_test.go +++ b/xds/internal/server/listener_wrapper_test.go @@ -34,7 +34,7 @@ import ( wrapperspb "github.com/golang/protobuf/ptypes/wrappers" "google.golang.org/grpc/internal/grpctest" "google.golang.org/grpc/internal/testutils" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/testutils/fakeclient" ) diff --git a/xds/internal/testutils/fakeclient/client.go b/xds/internal/testutils/fakeclient/client.go index f85f0ecbf3f3..ab791d77206d 100644 --- a/xds/internal/testutils/fakeclient/client.go +++ b/xds/internal/testutils/fakeclient/client.go @@ -23,9 +23,9 @@ import ( "context" "google.golang.org/grpc/internal/testutils" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" + "google.golang.org/grpc/xds/internal/xdsclient/load" ) // Client is a fake implementation of an xds client. It exposes a bunch of @@ -41,7 +41,6 @@ type Client struct { cdsCancelCh *testutils.Channel edsCancelCh *testutils.Channel loadReportCh *testutils.Channel - closeCh *testutils.Channel loadStore *load.Store bootstrapCfg *bootstrap.Config @@ -52,18 +51,18 @@ type Client struct { } // WatchListener registers a LDS watch. -func (xdsC *Client) WatchListener(serviceName string, callback func(xdsclient.ListenerUpdate, error)) func() { - xdsC.ldsCb = callback - xdsC.ldsWatchCh.Send(serviceName) +func (c *Client) WatchListener(serviceName string, callback func(xdsclient.ListenerUpdate, error)) func() { + c.ldsCb = callback + c.ldsWatchCh.Send(serviceName) return func() { - xdsC.ldsCancelCh.Send(nil) + c.ldsCancelCh.Send(nil) } } // WaitForWatchListener waits for WatchCluster to be invoked on this client and // returns the serviceName being watched. -func (xdsC *Client) WaitForWatchListener(ctx context.Context) (string, error) { - val, err := xdsC.ldsWatchCh.Receive(ctx) +func (c *Client) WaitForWatchListener(ctx context.Context) (string, error) { + val, err := c.ldsWatchCh.Receive(ctx) if err != nil { return "", err } @@ -74,30 +73,30 @@ func (xdsC *Client) WaitForWatchListener(ctx context.Context) (string, error) { // // Not thread safe with WatchListener. Only call this after // WaitForWatchListener. -func (xdsC *Client) InvokeWatchListenerCallback(update xdsclient.ListenerUpdate, err error) { - xdsC.ldsCb(update, err) +func (c *Client) InvokeWatchListenerCallback(update xdsclient.ListenerUpdate, err error) { + c.ldsCb(update, err) } // WaitForCancelListenerWatch waits for a LDS watch to be cancelled and returns // context.DeadlineExceeded otherwise. -func (xdsC *Client) WaitForCancelListenerWatch(ctx context.Context) error { - _, err := xdsC.ldsCancelCh.Receive(ctx) +func (c *Client) WaitForCancelListenerWatch(ctx context.Context) error { + _, err := c.ldsCancelCh.Receive(ctx) return err } // WatchRouteConfig registers a RDS watch. -func (xdsC *Client) WatchRouteConfig(routeName string, callback func(xdsclient.RouteConfigUpdate, error)) func() { - xdsC.rdsCb = callback - xdsC.rdsWatchCh.Send(routeName) +func (c *Client) WatchRouteConfig(routeName string, callback func(xdsclient.RouteConfigUpdate, error)) func() { + c.rdsCb = callback + c.rdsWatchCh.Send(routeName) return func() { - xdsC.rdsCancelCh.Send(nil) + c.rdsCancelCh.Send(nil) } } // WaitForWatchRouteConfig waits for WatchCluster to be invoked on this client and // returns the routeName being watched. -func (xdsC *Client) WaitForWatchRouteConfig(ctx context.Context) (string, error) { - val, err := xdsC.rdsWatchCh.Receive(ctx) +func (c *Client) WaitForWatchRouteConfig(ctx context.Context) (string, error) { + val, err := c.rdsWatchCh.Receive(ctx) if err != nil { return "", err } @@ -108,33 +107,33 @@ func (xdsC *Client) WaitForWatchRouteConfig(ctx context.Context) (string, error) // // Not thread safe with WatchRouteConfig. Only call this after // WaitForWatchRouteConfig. -func (xdsC *Client) InvokeWatchRouteConfigCallback(update xdsclient.RouteConfigUpdate, err error) { - xdsC.rdsCb(update, err) +func (c *Client) InvokeWatchRouteConfigCallback(update xdsclient.RouteConfigUpdate, err error) { + c.rdsCb(update, err) } // WaitForCancelRouteConfigWatch waits for a RDS watch to be cancelled and returns // context.DeadlineExceeded otherwise. -func (xdsC *Client) WaitForCancelRouteConfigWatch(ctx context.Context) error { - _, err := xdsC.rdsCancelCh.Receive(ctx) +func (c *Client) WaitForCancelRouteConfigWatch(ctx context.Context) error { + _, err := c.rdsCancelCh.Receive(ctx) return err } // WatchCluster registers a CDS watch. -func (xdsC *Client) WatchCluster(clusterName string, callback func(xdsclient.ClusterUpdate, error)) func() { +func (c *Client) WatchCluster(clusterName string, callback func(xdsclient.ClusterUpdate, error)) func() { // Due to the tree like structure of aggregate clusters, there can be multiple callbacks persisted for each cluster // node. However, the client doesn't care about the parent child relationship between the nodes, only that it invokes // the right callback for a particular cluster. - xdsC.cdsCbs[clusterName] = callback - xdsC.cdsWatchCh.Send(clusterName) + c.cdsCbs[clusterName] = callback + c.cdsWatchCh.Send(clusterName) return func() { - xdsC.cdsCancelCh.Send(clusterName) + c.cdsCancelCh.Send(clusterName) } } // WaitForWatchCluster waits for WatchCluster to be invoked on this client and // returns the clusterName being watched. -func (xdsC *Client) WaitForWatchCluster(ctx context.Context) (string, error) { - val, err := xdsC.cdsWatchCh.Receive(ctx) +func (c *Client) WaitForWatchCluster(ctx context.Context) (string, error) { + val, err := c.cdsWatchCh.Receive(ctx) if err != nil { return "", err } @@ -145,25 +144,25 @@ func (xdsC *Client) WaitForWatchCluster(ctx context.Context) (string, error) { // // Not thread safe with WatchCluster. Only call this after // WaitForWatchCluster. -func (xdsC *Client) InvokeWatchClusterCallback(update xdsclient.ClusterUpdate, err error) { +func (c *Client) InvokeWatchClusterCallback(update xdsclient.ClusterUpdate, err error) { // Keeps functionality with previous usage of this, if single callback call that callback. - if len(xdsC.cdsCbs) == 1 { + if len(c.cdsCbs) == 1 { var clusterName string - for cluster := range xdsC.cdsCbs { + for cluster := range c.cdsCbs { clusterName = cluster } - xdsC.cdsCbs[clusterName](update, err) + c.cdsCbs[clusterName](update, err) } else { // Have what callback you call with the update determined by the service name in the ClusterUpdate. Left up to the // caller to make sure the cluster update matches with a persisted callback. - xdsC.cdsCbs[update.ClusterName](update, err) + c.cdsCbs[update.ClusterName](update, err) } } // WaitForCancelClusterWatch waits for a CDS watch to be cancelled and returns // context.DeadlineExceeded otherwise. -func (xdsC *Client) WaitForCancelClusterWatch(ctx context.Context) (string, error) { - clusterNameReceived, err := xdsC.cdsCancelCh.Receive(ctx) +func (c *Client) WaitForCancelClusterWatch(ctx context.Context) (string, error) { + clusterNameReceived, err := c.cdsCancelCh.Receive(ctx) if err != nil { return "", err } @@ -171,18 +170,18 @@ func (xdsC *Client) WaitForCancelClusterWatch(ctx context.Context) (string, erro } // WatchEndpoints registers an EDS watch for provided clusterName. -func (xdsC *Client) WatchEndpoints(clusterName string, callback func(xdsclient.EndpointsUpdate, error)) (cancel func()) { - xdsC.edsCb = callback - xdsC.edsWatchCh.Send(clusterName) +func (c *Client) WatchEndpoints(clusterName string, callback func(xdsclient.EndpointsUpdate, error)) (cancel func()) { + c.edsCb = callback + c.edsWatchCh.Send(clusterName) return func() { - xdsC.edsCancelCh.Send(nil) + c.edsCancelCh.Send(nil) } } // WaitForWatchEDS waits for WatchEndpoints to be invoked on this client and // returns the clusterName being watched. -func (xdsC *Client) WaitForWatchEDS(ctx context.Context) (string, error) { - val, err := xdsC.edsWatchCh.Receive(ctx) +func (c *Client) WaitForWatchEDS(ctx context.Context) (string, error) { + val, err := c.edsWatchCh.Receive(ctx) if err != nil { return "", err } @@ -193,14 +192,14 @@ func (xdsC *Client) WaitForWatchEDS(ctx context.Context) (string, error) { // // Not thread safe with WatchEndpoints. Only call this after // WaitForWatchEDS. -func (xdsC *Client) InvokeWatchEDSCallback(update xdsclient.EndpointsUpdate, err error) { - xdsC.edsCb(update, err) +func (c *Client) InvokeWatchEDSCallback(update xdsclient.EndpointsUpdate, err error) { + c.edsCb(update, err) } // WaitForCancelEDSWatch waits for a EDS watch to be cancelled and returns // context.DeadlineExceeded otherwise. -func (xdsC *Client) WaitForCancelEDSWatch(ctx context.Context) error { - _, err := xdsC.edsCancelCh.Receive(ctx) +func (c *Client) WaitForCancelEDSWatch(ctx context.Context) error { + _, err := c.edsCancelCh.Receive(ctx) return err } @@ -211,48 +210,39 @@ type ReportLoadArgs struct { } // ReportLoad starts reporting load about clusterName to server. -func (xdsC *Client) ReportLoad(server string) (loadStore *load.Store, cancel func()) { - xdsC.loadReportCh.Send(ReportLoadArgs{Server: server}) - return xdsC.loadStore, func() {} +func (c *Client) ReportLoad(server string) (loadStore *load.Store, cancel func()) { + c.loadReportCh.Send(ReportLoadArgs{Server: server}) + return c.loadStore, func() {} } // LoadStore returns the underlying load data store. -func (xdsC *Client) LoadStore() *load.Store { - return xdsC.loadStore +func (c *Client) LoadStore() *load.Store { + return c.loadStore } // WaitForReportLoad waits for ReportLoad to be invoked on this client and // returns the arguments passed to it. -func (xdsC *Client) WaitForReportLoad(ctx context.Context) (ReportLoadArgs, error) { - val, err := xdsC.loadReportCh.Receive(ctx) +func (c *Client) WaitForReportLoad(ctx context.Context) (ReportLoadArgs, error) { + val, err := c.loadReportCh.Receive(ctx) return val.(ReportLoadArgs), err } -// Close closes the xds client. -func (xdsC *Client) Close() { - xdsC.closeCh.Send(nil) -} - -// WaitForClose waits for Close to be invoked on this client and returns -// context.DeadlineExceeded otherwise. -func (xdsC *Client) WaitForClose(ctx context.Context) error { - _, err := xdsC.closeCh.Receive(ctx) - return err -} +// Close is a nop. +func (c *Client) Close() {} // BootstrapConfig returns the bootstrap config. -func (xdsC *Client) BootstrapConfig() *bootstrap.Config { - return xdsC.bootstrapCfg +func (c *Client) BootstrapConfig() *bootstrap.Config { + return c.bootstrapCfg } // SetBootstrapConfig updates the bootstrap config. -func (xdsC *Client) SetBootstrapConfig(cfg *bootstrap.Config) { - xdsC.bootstrapCfg = cfg +func (c *Client) SetBootstrapConfig(cfg *bootstrap.Config) { + c.bootstrapCfg = cfg } // Name returns the name of the xds client. -func (xdsC *Client) Name() string { - return xdsC.name +func (c *Client) Name() string { + return c.name } // NewClient returns a new fake xds client. @@ -275,7 +265,6 @@ func NewClientWithName(name string) *Client { cdsCancelCh: testutils.NewChannelWithSize(10), edsCancelCh: testutils.NewChannel(), loadReportCh: testutils.NewChannel(), - closeCh: testutils.NewChannel(), loadStore: load.NewStore(), cdsCbs: make(map[string]func(xdsclient.ClusterUpdate, error)), } diff --git a/xds/internal/client/attributes.go b/xds/internal/xdsclient/attributes.go similarity index 98% rename from xds/internal/client/attributes.go rename to xds/internal/xdsclient/attributes.go index 50b988245291..99060177e1e3 100644 --- a/xds/internal/client/attributes.go +++ b/xds/internal/xdsclient/attributes.go @@ -15,7 +15,7 @@ * */ -package client +package xdsclient import "google.golang.org/grpc/resolver" diff --git a/xds/internal/client/bootstrap/bootstrap.go b/xds/internal/xdsclient/bootstrap/bootstrap.go similarity index 100% rename from xds/internal/client/bootstrap/bootstrap.go rename to xds/internal/xdsclient/bootstrap/bootstrap.go diff --git a/xds/internal/client/bootstrap/bootstrap_test.go b/xds/internal/xdsclient/bootstrap/bootstrap_test.go similarity index 100% rename from xds/internal/client/bootstrap/bootstrap_test.go rename to xds/internal/xdsclient/bootstrap/bootstrap_test.go diff --git a/xds/internal/client/bootstrap/logging.go b/xds/internal/xdsclient/bootstrap/logging.go similarity index 100% rename from xds/internal/client/bootstrap/logging.go rename to xds/internal/xdsclient/bootstrap/logging.go diff --git a/xds/internal/client/callback.go b/xds/internal/xdsclient/callback.go similarity index 99% rename from xds/internal/client/callback.go rename to xds/internal/xdsclient/callback.go index ac6f0151a5f9..64b7d6794c40 100644 --- a/xds/internal/client/callback.go +++ b/xds/internal/xdsclient/callback.go @@ -16,7 +16,7 @@ * */ -package client +package xdsclient import "google.golang.org/grpc/internal/pretty" diff --git a/xds/internal/client/cds_test.go b/xds/internal/xdsclient/cds_test.go similarity index 99% rename from xds/internal/client/cds_test.go rename to xds/internal/xdsclient/cds_test.go index 82b92372afc3..83b9071ad134 100644 --- a/xds/internal/client/cds_test.go +++ b/xds/internal/xdsclient/cds_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "regexp" diff --git a/xds/internal/client/client.go b/xds/internal/xdsclient/client.go similarity index 98% rename from xds/internal/client/client.go rename to xds/internal/xdsclient/client.go index 4ed1c3a5833c..4323c5678c2c 100644 --- a/xds/internal/client/client.go +++ b/xds/internal/xdsclient/client.go @@ -16,9 +16,9 @@ * */ -// Package client implements a full fledged gRPC client for the xDS API used by -// the xds resolver and balancer implementations. -package client +// Package xdsclient implements a full fledged gRPC client for the xDS API used +// by the xds resolver and balancer implementations. +package xdsclient import ( "context" @@ -34,7 +34,7 @@ import ( "google.golang.org/protobuf/types/known/anypb" "google.golang.org/grpc/internal/xds/matcher" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient/load" "google.golang.org/grpc/xds/internal/httpfilter" "google.golang.org/grpc" @@ -44,7 +44,7 @@ import ( "google.golang.org/grpc/internal/grpcsync" "google.golang.org/grpc/keepalive" "google.golang.org/grpc/xds/internal" - "google.golang.org/grpc/xds/internal/client/bootstrap" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" "google.golang.org/grpc/xds/internal/version" ) diff --git a/xds/internal/client/client_test.go b/xds/internal/xdsclient/client_test.go similarity index 99% rename from xds/internal/client/client_test.go rename to xds/internal/xdsclient/client_test.go index d57bc20e2c2c..a16a3661e01d 100644 --- a/xds/internal/client/client_test.go +++ b/xds/internal/xdsclient/client_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "context" @@ -34,7 +34,7 @@ import ( "google.golang.org/grpc/internal/grpcsync" "google.golang.org/grpc/internal/grpctest" "google.golang.org/grpc/internal/testutils" - "google.golang.org/grpc/xds/internal/client/bootstrap" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" xdstestutils "google.golang.org/grpc/xds/internal/testutils" "google.golang.org/grpc/xds/internal/version" "google.golang.org/protobuf/testing/protocmp" diff --git a/xds/internal/client/dump.go b/xds/internal/xdsclient/dump.go similarity index 99% rename from xds/internal/client/dump.go rename to xds/internal/xdsclient/dump.go index 3fd18f6103b3..db9b474f370d 100644 --- a/xds/internal/client/dump.go +++ b/xds/internal/xdsclient/dump.go @@ -16,7 +16,7 @@ * */ -package client +package xdsclient import anypb "github.com/golang/protobuf/ptypes/any" diff --git a/xds/internal/client/eds_test.go b/xds/internal/xdsclient/eds_test.go similarity index 99% rename from xds/internal/client/eds_test.go rename to xds/internal/xdsclient/eds_test.go index 467f25269cdf..ebd26a40f957 100644 --- a/xds/internal/client/eds_test.go +++ b/xds/internal/xdsclient/eds_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "fmt" diff --git a/xds/internal/client/errors.go b/xds/internal/xdsclient/errors.go similarity index 98% rename from xds/internal/client/errors.go rename to xds/internal/xdsclient/errors.go index 34ae2738db00..4d6cdaaf9b4a 100644 --- a/xds/internal/client/errors.go +++ b/xds/internal/xdsclient/errors.go @@ -16,7 +16,7 @@ * */ -package client +package xdsclient import "fmt" diff --git a/xds/internal/client/filter_chain.go b/xds/internal/xdsclient/filter_chain.go similarity index 99% rename from xds/internal/client/filter_chain.go rename to xds/internal/xdsclient/filter_chain.go index 66d26d03b634..7303ebd3ce70 100644 --- a/xds/internal/client/filter_chain.go +++ b/xds/internal/xdsclient/filter_chain.go @@ -16,7 +16,7 @@ * */ -package client +package xdsclient import ( "errors" diff --git a/xds/internal/client/filter_chain_test.go b/xds/internal/xdsclient/filter_chain_test.go similarity index 99% rename from xds/internal/client/filter_chain_test.go rename to xds/internal/xdsclient/filter_chain_test.go index c68e22286763..25390b7f9248 100644 --- a/xds/internal/client/filter_chain_test.go +++ b/xds/internal/xdsclient/filter_chain_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "fmt" diff --git a/xds/internal/client/lds_test.go b/xds/internal/xdsclient/lds_test.go similarity index 99% rename from xds/internal/client/lds_test.go rename to xds/internal/xdsclient/lds_test.go index ad9af4c885a2..1667698bd578 100644 --- a/xds/internal/client/lds_test.go +++ b/xds/internal/xdsclient/lds_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "fmt" diff --git a/xds/internal/client/load/reporter.go b/xds/internal/xdsclient/load/reporter.go similarity index 100% rename from xds/internal/client/load/reporter.go rename to xds/internal/xdsclient/load/reporter.go diff --git a/xds/internal/client/load/store.go b/xds/internal/xdsclient/load/store.go similarity index 100% rename from xds/internal/client/load/store.go rename to xds/internal/xdsclient/load/store.go diff --git a/xds/internal/client/load/store_test.go b/xds/internal/xdsclient/load/store_test.go similarity index 100% rename from xds/internal/client/load/store_test.go rename to xds/internal/xdsclient/load/store_test.go diff --git a/xds/internal/client/loadreport.go b/xds/internal/xdsclient/loadreport.go similarity index 98% rename from xds/internal/client/loadreport.go rename to xds/internal/xdsclient/loadreport.go index be42a6e0c383..32a71dada7fb 100644 --- a/xds/internal/client/loadreport.go +++ b/xds/internal/xdsclient/loadreport.go @@ -15,13 +15,13 @@ * limitations under the License. */ -package client +package xdsclient import ( "context" "google.golang.org/grpc" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient/load" ) // ReportLoad starts an load reporting stream to the given server. If the server diff --git a/xds/internal/client/logging.go b/xds/internal/xdsclient/logging.go similarity index 98% rename from xds/internal/client/logging.go rename to xds/internal/xdsclient/logging.go index bff3fb1d3df3..e28ea0d04103 100644 --- a/xds/internal/client/logging.go +++ b/xds/internal/xdsclient/logging.go @@ -16,7 +16,7 @@ * */ -package client +package xdsclient import ( "fmt" diff --git a/xds/internal/client/rds_test.go b/xds/internal/xdsclient/rds_test.go similarity index 99% rename from xds/internal/client/rds_test.go rename to xds/internal/xdsclient/rds_test.go index 33bcc2ad13f8..660a2f29d21a 100644 --- a/xds/internal/client/rds_test.go +++ b/xds/internal/xdsclient/rds_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "fmt" diff --git a/xds/internal/client/requests_counter.go b/xds/internal/xdsclient/requests_counter.go similarity index 99% rename from xds/internal/client/requests_counter.go rename to xds/internal/xdsclient/requests_counter.go index f033e1920991..dacbc8fadb60 100644 --- a/xds/internal/client/requests_counter.go +++ b/xds/internal/xdsclient/requests_counter.go @@ -16,7 +16,7 @@ * */ -package client +package xdsclient import ( "fmt" diff --git a/xds/internal/client/requests_counter_test.go b/xds/internal/xdsclient/requests_counter_test.go similarity index 99% rename from xds/internal/client/requests_counter_test.go rename to xds/internal/xdsclient/requests_counter_test.go index 30892fc747a0..f444e8f163e6 100644 --- a/xds/internal/client/requests_counter_test.go +++ b/xds/internal/xdsclient/requests_counter_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "sync" diff --git a/xds/internal/client/singleton.go b/xds/internal/xdsclient/singleton.go similarity index 98% rename from xds/internal/client/singleton.go rename to xds/internal/xdsclient/singleton.go index 41dd16e26afe..8d0e10f2c31a 100644 --- a/xds/internal/client/singleton.go +++ b/xds/internal/xdsclient/singleton.go @@ -16,7 +16,7 @@ * */ -package client +package xdsclient import ( "bytes" @@ -25,7 +25,7 @@ import ( "sync" "time" - "google.golang.org/grpc/xds/internal/client/bootstrap" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" ) const defaultWatchExpiryTimeout = 15 * time.Second diff --git a/xds/internal/client/tests/README.md b/xds/internal/xdsclient/tests/README.md similarity index 100% rename from xds/internal/client/tests/README.md rename to xds/internal/xdsclient/tests/README.md diff --git a/xds/internal/client/tests/client_test.go b/xds/internal/xdsclient/tests/client_test.go similarity index 93% rename from xds/internal/client/tests/client_test.go rename to xds/internal/xdsclient/tests/client_test.go index 755f0e05ea45..0ee80ba55b9d 100644 --- a/xds/internal/client/tests/client_test.go +++ b/xds/internal/xdsclient/tests/client_test.go @@ -27,9 +27,9 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/internal/grpctest" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" - _ "google.golang.org/grpc/xds/internal/client/v2" // Register the v2 API client. + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" + _ "google.golang.org/grpc/xds/internal/xdsclient/v2" // Register the v2 API client. "google.golang.org/grpc/xds/internal/testutils" "google.golang.org/grpc/xds/internal/version" ) diff --git a/xds/internal/client/tests/dump_test.go b/xds/internal/xdsclient/tests/dump_test.go similarity index 99% rename from xds/internal/client/tests/dump_test.go rename to xds/internal/xdsclient/tests/dump_test.go index 815850973e3d..01a491d3e927 100644 --- a/xds/internal/client/tests/dump_test.go +++ b/xds/internal/xdsclient/tests/dump_test.go @@ -39,8 +39,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/internal/testutils" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" xdstestutils "google.golang.org/grpc/xds/internal/testutils" ) diff --git a/xds/internal/client/tests/loadreport_test.go b/xds/internal/xdsclient/tests/loadreport_test.go similarity index 94% rename from xds/internal/client/tests/loadreport_test.go rename to xds/internal/xdsclient/tests/loadreport_test.go index b1ec37294771..1815f8a0ab43 100644 --- a/xds/internal/client/tests/loadreport_test.go +++ b/xds/internal/xdsclient/tests/loadreport_test.go @@ -34,13 +34,13 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/status" - "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" "google.golang.org/grpc/xds/internal/testutils/fakeserver" "google.golang.org/grpc/xds/internal/version" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" "google.golang.org/protobuf/testing/protocmp" - _ "google.golang.org/grpc/xds/internal/client/v2" // Register the v2 xDS API client. + _ "google.golang.org/grpc/xds/internal/xdsclient/v2" // Register the v2 xDS API client. ) const ( @@ -56,7 +56,7 @@ func (s) TestLRSClient(t *testing.T) { } defer sCleanup() - xdsC, err := client.NewWithConfigForTesting(&bootstrap.Config{ + xdsC, err := xdsclient.NewWithConfigForTesting(&bootstrap.Config{ BalancerName: fs.Address, Creds: grpc.WithTransportCredentials(insecure.NewCredentials()), NodeProto: &v2corepb.Node{}, diff --git a/xds/internal/client/transport_helper.go b/xds/internal/xdsclient/transport_helper.go similarity index 99% rename from xds/internal/client/transport_helper.go rename to xds/internal/xdsclient/transport_helper.go index 671e5b3220f1..1e3caa606d1d 100644 --- a/xds/internal/client/transport_helper.go +++ b/xds/internal/xdsclient/transport_helper.go @@ -16,7 +16,7 @@ * */ -package client +package xdsclient import ( "context" @@ -24,7 +24,7 @@ import ( "time" "github.com/golang/protobuf/proto" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient/load" "google.golang.org/grpc" "google.golang.org/grpc/internal/buffer" diff --git a/xds/internal/client/v2/ack_test.go b/xds/internal/xdsclient/v2/ack_test.go similarity index 99% rename from xds/internal/client/v2/ack_test.go rename to xds/internal/xdsclient/v2/ack_test.go index 53c8cef189d5..c5c5bfc31086 100644 --- a/xds/internal/client/v2/ack_test.go +++ b/xds/internal/xdsclient/v2/ack_test.go @@ -33,7 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/internal/testutils" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/testutils/fakeserver" "google.golang.org/grpc/xds/internal/version" ) diff --git a/xds/internal/client/v2/cds_test.go b/xds/internal/xdsclient/v2/cds_test.go similarity index 99% rename from xds/internal/client/v2/cds_test.go rename to xds/internal/xdsclient/v2/cds_test.go index ba7f627b25ff..fe3c732c9af0 100644 --- a/xds/internal/client/v2/cds_test.go +++ b/xds/internal/xdsclient/v2/cds_test.go @@ -28,7 +28,7 @@ import ( corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" anypb "github.com/golang/protobuf/ptypes/any" "google.golang.org/grpc/internal/testutils" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/version" ) diff --git a/xds/internal/client/v2/client.go b/xds/internal/xdsclient/v2/client.go similarity index 99% rename from xds/internal/client/v2/client.go rename to xds/internal/xdsclient/v2/client.go index b91482d13cf9..8ef9829e434d 100644 --- a/xds/internal/client/v2/client.go +++ b/xds/internal/xdsclient/v2/client.go @@ -28,7 +28,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/internal/pretty" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/version" v2xdspb "github.com/envoyproxy/go-control-plane/envoy/api/v2" diff --git a/xds/internal/client/v2/client_test.go b/xds/internal/xdsclient/v2/client_test.go similarity index 99% rename from xds/internal/client/v2/client_test.go rename to xds/internal/xdsclient/v2/client_test.go index 371375f3ee5c..eadad05a9eea 100644 --- a/xds/internal/client/v2/client_test.go +++ b/xds/internal/xdsclient/v2/client_test.go @@ -37,7 +37,7 @@ import ( "google.golang.org/grpc/internal/testutils" "google.golang.org/grpc/resolver" "google.golang.org/grpc/resolver/manual" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/testutils/fakeserver" "google.golang.org/grpc/xds/internal/version" "google.golang.org/protobuf/testing/protocmp" diff --git a/xds/internal/client/v2/eds_test.go b/xds/internal/xdsclient/v2/eds_test.go similarity index 99% rename from xds/internal/client/v2/eds_test.go rename to xds/internal/xdsclient/v2/eds_test.go index 08e75d373017..d23ae7027416 100644 --- a/xds/internal/client/v2/eds_test.go +++ b/xds/internal/xdsclient/v2/eds_test.go @@ -28,7 +28,7 @@ import ( anypb "github.com/golang/protobuf/ptypes/any" "google.golang.org/grpc/internal/testutils" "google.golang.org/grpc/xds/internal" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" xtestutils "google.golang.org/grpc/xds/internal/testutils" "google.golang.org/grpc/xds/internal/version" ) diff --git a/xds/internal/client/v2/lds_test.go b/xds/internal/xdsclient/v2/lds_test.go similarity index 99% rename from xds/internal/client/v2/lds_test.go rename to xds/internal/xdsclient/v2/lds_test.go index 22fa35d5e51e..e6f1d8f1cf02 100644 --- a/xds/internal/client/v2/lds_test.go +++ b/xds/internal/xdsclient/v2/lds_test.go @@ -26,7 +26,7 @@ import ( v2xdspb "github.com/envoyproxy/go-control-plane/envoy/api/v2" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" ) // TestLDSHandleResponse starts a fake xDS server, makes a ClientConn to it, diff --git a/xds/internal/client/v2/loadreport.go b/xds/internal/xdsclient/v2/loadreport.go similarity index 98% rename from xds/internal/client/v2/loadreport.go rename to xds/internal/xdsclient/v2/loadreport.go index 17ea8c8d4c43..77db5eb9d8d6 100644 --- a/xds/internal/client/v2/loadreport.go +++ b/xds/internal/xdsclient/v2/loadreport.go @@ -27,7 +27,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes" "google.golang.org/grpc/internal/pretty" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient/load" v2corepb "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" v2endpointpb "github.com/envoyproxy/go-control-plane/envoy/api/v2/endpoint" diff --git a/xds/internal/client/v2/rds_test.go b/xds/internal/xdsclient/v2/rds_test.go similarity index 99% rename from xds/internal/client/v2/rds_test.go rename to xds/internal/xdsclient/v2/rds_test.go index 12495428bf95..22a1fd997d57 100644 --- a/xds/internal/client/v2/rds_test.go +++ b/xds/internal/xdsclient/v2/rds_test.go @@ -27,7 +27,7 @@ import ( xdspb "github.com/envoyproxy/go-control-plane/envoy/api/v2" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/testutils/fakeserver" ) diff --git a/xds/internal/client/v3/client.go b/xds/internal/xdsclient/v3/client.go similarity index 99% rename from xds/internal/client/v3/client.go rename to xds/internal/xdsclient/v3/client.go index 200da2ac7d73..06fe28b31c94 100644 --- a/xds/internal/client/v3/client.go +++ b/xds/internal/xdsclient/v3/client.go @@ -29,7 +29,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/internal/pretty" - xdsclient "google.golang.org/grpc/xds/internal/client" + "google.golang.org/grpc/xds/internal/xdsclient" "google.golang.org/grpc/xds/internal/version" v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" diff --git a/xds/internal/client/v3/loadreport.go b/xds/internal/xdsclient/v3/loadreport.go similarity index 98% rename from xds/internal/client/v3/loadreport.go rename to xds/internal/xdsclient/v3/loadreport.go index 1de0ccf57503..147751baab03 100644 --- a/xds/internal/client/v3/loadreport.go +++ b/xds/internal/xdsclient/v3/loadreport.go @@ -27,7 +27,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/golang/protobuf/ptypes" "google.golang.org/grpc/internal/pretty" - "google.golang.org/grpc/xds/internal/client/load" + "google.golang.org/grpc/xds/internal/xdsclient/load" v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" v3endpointpb "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3" diff --git a/xds/internal/client/watchers.go b/xds/internal/xdsclient/watchers.go similarity index 99% rename from xds/internal/client/watchers.go rename to xds/internal/xdsclient/watchers.go index 446f5cca9973..249db4de91e4 100644 --- a/xds/internal/client/watchers.go +++ b/xds/internal/xdsclient/watchers.go @@ -16,7 +16,7 @@ * */ -package client +package xdsclient import ( "fmt" diff --git a/xds/internal/client/watchers_cluster_test.go b/xds/internal/xdsclient/watchers_cluster_test.go similarity index 99% rename from xds/internal/client/watchers_cluster_test.go rename to xds/internal/xdsclient/watchers_cluster_test.go index c9837cd51978..8c33486fa017 100644 --- a/xds/internal/client/watchers_cluster_test.go +++ b/xds/internal/xdsclient/watchers_cluster_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "context" diff --git a/xds/internal/client/watchers_endpoints_test.go b/xds/internal/xdsclient/watchers_endpoints_test.go similarity index 99% rename from xds/internal/client/watchers_endpoints_test.go rename to xds/internal/xdsclient/watchers_endpoints_test.go index bff4544d2679..70f06514d9f6 100644 --- a/xds/internal/client/watchers_endpoints_test.go +++ b/xds/internal/xdsclient/watchers_endpoints_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "context" diff --git a/xds/internal/client/watchers_listener_test.go b/xds/internal/xdsclient/watchers_listener_test.go similarity index 99% rename from xds/internal/client/watchers_listener_test.go rename to xds/internal/xdsclient/watchers_listener_test.go index fdd4ebd163fa..79ef997a72df 100644 --- a/xds/internal/client/watchers_listener_test.go +++ b/xds/internal/xdsclient/watchers_listener_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "context" diff --git a/xds/internal/client/watchers_route_test.go b/xds/internal/xdsclient/watchers_route_test.go similarity index 99% rename from xds/internal/client/watchers_route_test.go rename to xds/internal/xdsclient/watchers_route_test.go index 41640b85b574..08b035a0b0a3 100644 --- a/xds/internal/client/watchers_route_test.go +++ b/xds/internal/xdsclient/watchers_route_test.go @@ -18,7 +18,7 @@ * */ -package client +package xdsclient import ( "context" diff --git a/xds/internal/client/xds.go b/xds/internal/xdsclient/xds.go similarity index 99% rename from xds/internal/client/xds.go rename to xds/internal/xdsclient/xds.go index b95224113237..44fd883e3f36 100644 --- a/xds/internal/client/xds.go +++ b/xds/internal/xdsclient/xds.go @@ -16,7 +16,7 @@ * */ -package client +package xdsclient import ( "errors" diff --git a/xds/server.go b/xds/server.go index b83a073ac1c5..61e22cee8ff4 100644 --- a/xds/server.go +++ b/xds/server.go @@ -33,16 +33,16 @@ import ( "google.golang.org/grpc/internal/buffer" internalgrpclog "google.golang.org/grpc/internal/grpclog" "google.golang.org/grpc/internal/grpcsync" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" "google.golang.org/grpc/xds/internal/server" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" ) const serverPrefix = "[xds-server %p] " var ( // These new functions will be overridden in unit tests. - newXDSClient = func() (xdsClientInterface, error) { + newXDSClient = func() (xdsClient, error) { return xdsclient.New() } newGRPCServer = func(opts ...grpc.ServerOption) grpcServerInterface { @@ -58,9 +58,9 @@ func prefixLogger(p *GRPCServer) *internalgrpclog.PrefixLogger { return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(serverPrefix, p)) } -// xdsClientInterface contains methods from xdsClient.Client which are used by +// xdsClient contains methods from xdsClient.Client which are used by // the server. This is useful for overriding in unit tests. -type xdsClientInterface interface { +type xdsClient interface { WatchListener(string, func(xdsclient.ListenerUpdate, error)) func() BootstrapConfig() *bootstrap.Config Close() @@ -89,8 +89,8 @@ type GRPCServer struct { // clientMu is used only in initXDSClient(), which is called at the // beginning of Serve(), where we have to decide if we have to create a // client or use an existing one. - clientMu sync.Mutex - xdsC xdsClientInterface + clientMu sync.Mutex + xdsClient xdsClient } // NewGRPCServer creates an xDS-enabled gRPC server using the passed in opts. @@ -150,13 +150,13 @@ func (s *GRPCServer) initXDSClient() error { s.clientMu.Lock() defer s.clientMu.Unlock() - if s.xdsC != nil { + if s.xdsClient != nil { return nil } newXDSClient := newXDSClient if s.opts.bootstrapContents != nil { - newXDSClient = func() (xdsClientInterface, error) { + newXDSClient = func() (xdsClient, error) { return xdsclient.NewClientWithBootstrapContents(s.opts.bootstrapContents) } } @@ -164,7 +164,7 @@ func (s *GRPCServer) initXDSClient() error { if err != nil { return fmt.Errorf("xds: failed to create xds-client: %v", err) } - s.xdsC = client + s.xdsClient = client s.logger.Infof("Created an xdsClient") return nil } @@ -187,7 +187,7 @@ func (s *GRPCServer) Serve(lis net.Listener) error { if err := s.initXDSClient(); err != nil { return err } - cfg := s.xdsC.BootstrapConfig() + cfg := s.xdsClient.BootstrapConfig() if cfg == nil { return errors.New("bootstrap configuration is empty") } @@ -227,7 +227,7 @@ func (s *GRPCServer) Serve(lis net.Listener) error { Listener: lis, ListenerResourceName: name, XDSCredsInUse: s.xdsCredsInUse, - XDSClient: s.xdsC, + XDSClient: s.xdsClient, ModeCallback: func(addr net.Addr, mode server.ServingMode, err error) { modeUpdateCh.Put(&modeChangeArgs{ addr: addr, @@ -298,8 +298,8 @@ func (s *GRPCServer) handleServingModeChanges(updateCh *buffer.Unbounded) { func (s *GRPCServer) Stop() { s.quit.Fire() s.gs.Stop() - if s.xdsC != nil { - s.xdsC.Close() + if s.xdsClient != nil { + s.xdsClient.Close() } } @@ -309,8 +309,8 @@ func (s *GRPCServer) Stop() { func (s *GRPCServer) GracefulStop() { s.quit.Fire() s.gs.GracefulStop() - if s.xdsC != nil { - s.xdsC.Close() + if s.xdsClient != nil { + s.xdsClient.Close() } } diff --git a/xds/server_test.go b/xds/server_test.go index e16ac36b01f2..858116762f22 100644 --- a/xds/server_test.go +++ b/xds/server_test.go @@ -39,10 +39,10 @@ import ( "google.golang.org/grpc/credentials/xds" "google.golang.org/grpc/internal/grpctest" "google.golang.org/grpc/internal/testutils" - xdsclient "google.golang.org/grpc/xds/internal/client" - "google.golang.org/grpc/xds/internal/client/bootstrap" xdstestutils "google.golang.org/grpc/xds/internal/testutils" "google.golang.org/grpc/xds/internal/testutils/fakeclient" + "google.golang.org/grpc/xds/internal/xdsclient" + "google.golang.org/grpc/xds/internal/xdsclient/bootstrap" ) const ( @@ -247,7 +247,7 @@ func (p *fakeProvider) Close() { func setupOverrides() (*fakeGRPCServer, *testutils.Channel, func()) { clientCh := testutils.NewChannel() origNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { + newXDSClient = func() (xdsClient, error) { c := fakeclient.NewClient() c.SetBootstrapConfig(&bootstrap.Config{ BalancerName: "dummyBalancer", @@ -277,7 +277,7 @@ func setupOverrides() (*fakeGRPCServer, *testutils.Channel, func()) { func setupOverridesForXDSCreds(includeCertProviderCfg bool) (*testutils.Channel, func()) { clientCh := testutils.NewChannel() origNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { + newXDSClient = func() (xdsClient, error) { c := fakeclient.NewClient() bc := &bootstrap.Config{ BalancerName: "dummyBalancer", @@ -544,7 +544,7 @@ func (s) TestServeBootstrapConfigInvalid(t *testing.T) { // xdsClient with the specified bootstrap configuration. clientCh := testutils.NewChannel() origNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { + newXDSClient = func() (xdsClient, error) { c := fakeclient.NewClient() c.SetBootstrapConfig(test.bootstrapConfig) clientCh.Send(c) @@ -587,7 +587,7 @@ func (s) TestServeBootstrapConfigInvalid(t *testing.T) { // verifies that Server() exits with a non-nil error. func (s) TestServeNewClientFailure(t *testing.T) { origNewXDSClient := newXDSClient - newXDSClient = func() (xdsClientInterface, error) { + newXDSClient = func() (xdsClient, error) { return nil, errors.New("xdsClient creation failed") } defer func() { newXDSClient = origNewXDSClient }() diff --git a/xds/xds.go b/xds/xds.go index bbd3fe543212..2a934c51ddcb 100644 --- a/xds/xds.go +++ b/xds/xds.go @@ -43,8 +43,8 @@ import ( _ "google.golang.org/grpc/credentials/tls/certprovider/pemfile" // Register the file watcher certificate provider plugin. _ "google.golang.org/grpc/xds/internal/balancer" // Register the balancers. - _ "google.golang.org/grpc/xds/internal/client/v2" // Register the v2 xDS API client. - _ "google.golang.org/grpc/xds/internal/client/v3" // Register the v3 xDS API client. + _ "google.golang.org/grpc/xds/internal/xdsclient/v2" // Register the v2 xDS API client. + _ "google.golang.org/grpc/xds/internal/xdsclient/v3" // Register the v3 xDS API client. _ "google.golang.org/grpc/xds/internal/httpfilter/fault" // Register the fault injection filter. xdsresolver "google.golang.org/grpc/xds/internal/resolver" // Register the xds_resolver. )