From 02946a3f37b62b21101f071e7359c28883fbe431 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Mon, 17 Jul 2023 13:29:21 -0700 Subject: [PATCH] resolver: remove deprecated AddressType (#6451) --- balancer/grpclb/grpclb.go | 14 +-- balancer/grpclb/grpclb_test.go | 6 +- balancer_conn_wrappers.go | 14 --- clientconn.go | 24 ++--- pickfirst.go | 2 + resolver/resolver.go | 29 +----- test/balancer_switching_test.go | 160 ++++++-------------------------- test/balancer_test.go | 91 ------------------ test/channelz_test.go | 16 ++-- vet.sh | 2 - 10 files changed, 55 insertions(+), 303 deletions(-) diff --git a/balancer/grpclb/grpclb.go b/balancer/grpclb/grpclb.go index 6d698229a342..261ddb5c8b45 100644 --- a/balancer/grpclb/grpclb.go +++ b/balancer/grpclb/grpclb.go @@ -448,17 +448,9 @@ func (lb *lbBalancer) UpdateClientConnState(ccs balancer.ClientConnState) error gc, _ := ccs.BalancerConfig.(*grpclbServiceConfig) lb.handleServiceConfig(gc) - addrs := ccs.ResolverState.Addresses - - var remoteBalancerAddrs, backendAddrs []resolver.Address - for _, a := range addrs { - if a.Type == resolver.GRPCLB { - a.Type = resolver.Backend - remoteBalancerAddrs = append(remoteBalancerAddrs, a) - } else { - backendAddrs = append(backendAddrs, a) - } - } + backendAddrs := ccs.ResolverState.Addresses + + var remoteBalancerAddrs []resolver.Address if sd := grpclbstate.Get(ccs.ResolverState); sd != nil { // Override any balancer addresses provided via // ccs.ResolverState.Addresses. diff --git a/balancer/grpclb/grpclb_test.go b/balancer/grpclb/grpclb_test.go index 9dbfd3466401..69e842cb435d 100644 --- a/balancer/grpclb/grpclb_test.go +++ b/balancer/grpclb/grpclb_test.go @@ -1430,11 +1430,11 @@ func runAndCheckStats(t *testing.T, drop bool, statsChan chan *lbpb.ClientStats, } defer cc.Close() - r.UpdateState(resolver.State{Addresses: []resolver.Address{{ + rstate := resolver.State{ServiceConfig: r.CC.ParseServiceConfig(grpclbConfig)} + r.UpdateState(grpclbstate.Set(rstate, &grpclbstate.State{BalancerAddresses: []resolver.Address{{ Addr: tss.lbAddr, - Type: resolver.GRPCLB, ServerName: lbServerName, - }}}) + }}})) runRPCs(cc) end := time.Now().Add(time.Second) diff --git a/balancer_conn_wrappers.go b/balancer_conn_wrappers.go index 04b9ad411691..b48419a96190 100644 --- a/balancer_conn_wrappers.go +++ b/balancer_conn_wrappers.go @@ -99,20 +99,6 @@ func (ccb *ccBalancerWrapper) updateClientConnState(ccs *balancer.ClientConnStat // lock held. But the lock guards only the scheduling part. The actual // callback is called asynchronously without the lock being held. ok := ccb.serializer.Schedule(func(_ context.Context) { - // If the addresses specified in the update contain addresses of type - // "grpclb" and the selected LB policy is not "grpclb", these addresses - // will be filtered out and ccs will be modified with the updated - // address list. - if ccb.curBalancerName != grpclbName { - var addrs []resolver.Address - for _, addr := range ccs.ResolverState.Addresses { - if addr.Type == resolver.GRPCLB { - continue - } - addrs = append(addrs, addr) - } - ccs.ResolverState.Addresses = addrs - } errCh <- ccb.balancer.UpdateClientConnState(*ccs) }) if !ok { diff --git a/clientconn.go b/clientconn.go index bfd7555a8bf2..ef6c55aca619 100644 --- a/clientconn.go +++ b/clientconn.go @@ -54,8 +54,6 @@ import ( const ( // minimum time to give a connection to complete minConnectTimeout = 20 * time.Second - // must match grpclbName in grpclb/grpclb.go - grpclbName = "grpclb" ) var ( @@ -1153,23 +1151,13 @@ func (cc *ClientConn) applyServiceConfigAndBalancer(sc *ServiceConfig, configSel } var newBalancerName string - if cc.sc != nil && cc.sc.lbConfig != nil { + if cc.sc == nil || (cc.sc.lbConfig == nil && cc.sc.LB == nil) { + // No service config or no LB policy specified in config. + newBalancerName = PickFirstBalancerName + } else if cc.sc.lbConfig != nil { newBalancerName = cc.sc.lbConfig.name - } else { - var isGRPCLB bool - for _, a := range addrs { - if a.Type == resolver.GRPCLB { - isGRPCLB = true - break - } - } - if isGRPCLB { - newBalancerName = grpclbName - } else if cc.sc != nil && cc.sc.LB != nil { - newBalancerName = *cc.sc.LB - } else { - newBalancerName = PickFirstBalancerName - } + } else { // cc.sc.LB != nil + newBalancerName = *cc.sc.LB } cc.balancerWrapper.switchTo(newBalancerName) } diff --git a/pickfirst.go b/pickfirst.go index abe266b021d2..3a269e9ee9b5 100644 --- a/pickfirst.go +++ b/pickfirst.go @@ -27,6 +27,7 @@ import ( "google.golang.org/grpc/connectivity" "google.golang.org/grpc/internal/envconfig" "google.golang.org/grpc/internal/grpcrand" + "google.golang.org/grpc/resolver" "google.golang.org/grpc/serviceconfig" ) @@ -114,6 +115,7 @@ func (b *pickfirstBalancer) UpdateClientConnState(state balancer.ClientConnState } if envconfig.PickFirstLBConfig && b.cfg != nil && b.cfg.ShuffleAddressList { + addrs = append([]resolver.Address{}, addrs...) grpcrand.Shuffle(len(addrs), func(i, j int) { addrs[i], addrs[j] = addrs[j], addrs[i] }) } if b.subConn != nil { diff --git a/resolver/resolver.go b/resolver/resolver.go index d8db6f5d34eb..459dfec195e6 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -77,25 +77,6 @@ func GetDefaultScheme() string { return defaultScheme } -// AddressType indicates the address type returned by name resolution. -// -// Deprecated: use Attributes in Address instead. -type AddressType uint8 - -const ( - // Backend indicates the address is for a backend server. - // - // Deprecated: use Attributes in Address instead. - Backend AddressType = iota - // GRPCLB indicates the address is for a grpclb load balancer. - // - // Deprecated: to select the GRPCLB load balancing policy, use a service - // config with a corresponding loadBalancingConfig. To supply balancer - // addresses to the GRPCLB load balancing policy, set State.Attributes - // using balancer/grpclb/state.Set. - GRPCLB -) - // Address represents a server the client connects to. // // # Experimental @@ -111,9 +92,6 @@ type Address struct { // the address, instead of the hostname from the Dial target string. In most cases, // this should not be set. // - // If Type is GRPCLB, ServerName should be the name of the remote load - // balancer, not the name of the backend. - // // WARNING: ServerName must only be populated with trusted values. It // is insecure to populate it with data from untrusted inputs since untrusted // values could be used to bypass the authority checks performed by TLS. @@ -128,11 +106,6 @@ type Address struct { // creation, connection establishment, handshaking, etc. BalancerAttributes *attributes.Attributes - // Type is the type of this address. - // - // Deprecated: use Attributes instead. - Type AddressType - // Metadata is the information associated with Addr, which may be used // to make load balancing decision. // @@ -150,7 +123,7 @@ func (a Address) Equal(o Address) bool { return a.Addr == o.Addr && a.ServerName == o.ServerName && a.Attributes.Equal(o.Attributes) && a.BalancerAttributes.Equal(o.BalancerAttributes) && - a.Type == o.Type && a.Metadata == o.Metadata + a.Metadata == o.Metadata } // String returns JSON formatted string representation of the address. diff --git a/test/balancer_switching_test.go b/test/balancer_switching_test.go index 716625a63b3f..14dfa8ea7eff 100644 --- a/test/balancer_switching_test.go +++ b/test/balancer_switching_test.go @@ -25,6 +25,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/balancer" + grpclbstate "google.golang.org/grpc/balancer/grpclb/state" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/internal" "google.golang.org/grpc/internal/balancer/stub" @@ -168,10 +169,13 @@ func (s) TestBalancerSwitch_grpclbToPickFirst(t *testing.T) { } defer cc.Close() - // Push a resolver update with no service config and a single address pointing - // to the grpclb server we created above. This will cause the channel to - // switch to the "grpclb" balancer, which returns a single backend address. - r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: lbServer.Address(), Type: resolver.GRPCLB}}}) + // Push a resolver update with a GRPCLB service config and a single address + // pointing to the grpclb server we created above. This will cause the + // channel to switch to the "grpclb" balancer, which returns a single + // backend address. + grpclbConfig := parseServiceConfig(t, r, `{"loadBalancingPolicy": "grpclb"}`) + state := resolver.State{ServiceConfig: grpclbConfig} + r.UpdateState(grpclbstate.Set(state, &grpclbstate.State{BalancerAddresses: []resolver.Address{{Addr: lbServer.Address()}}})) ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) defer cancel() client := testgrpc.NewTestServiceClient(cc) @@ -182,7 +186,7 @@ func (s) TestBalancerSwitch_grpclbToPickFirst(t *testing.T) { // Push a resolver update containing a non-existent grpclb server address. // This should not lead to a balancer switch. const nonExistentServer = "non-existent-grpclb-server-address" - r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: nonExistentServer, Type: resolver.GRPCLB}}}) + r.UpdateState(grpclbstate.Set(state, &grpclbstate.State{BalancerAddresses: []resolver.Address{{Addr: nonExistentServer}}})) if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[:1]); err != nil { t.Fatal(err) } @@ -192,7 +196,8 @@ func (s) TestBalancerSwitch_grpclbToPickFirst(t *testing.T) { // list of addresses pushed as part of this update is different from the one // returned by the "grpclb" balancer. So, we should see RPCs going to the // newly configured backends, as part of the balancer switch. - r.UpdateState(resolver.State{Addresses: addrs[1:]}) + emptyConfig := parseServiceConfig(t, r, `{}`) + r.UpdateState(resolver.State{Addresses: addrs[1:], ServiceConfig: emptyConfig}) if err := pickfirst.CheckRPCsToBackend(ctx, cc, addrs[1]); err != nil { t.Fatal(err) } @@ -225,7 +230,9 @@ func (s) TestBalancerSwitch_pickFirstToGRPCLB(t *testing.T) { // Push a resolver update with no service config and a single address pointing // to the grpclb server we created above. This will cause the channel to // switch to the "grpclb" balancer, which returns a single backend address. - r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: lbServer.Address(), Type: resolver.GRPCLB}}}) + grpclbConfig := parseServiceConfig(t, r, `{"loadBalancingPolicy": "grpclb"}`) + state := resolver.State{ServiceConfig: grpclbConfig} + r.UpdateState(grpclbstate.Set(state, &grpclbstate.State{BalancerAddresses: []resolver.Address{{Addr: lbServer.Address()}}})) client := testgrpc.NewTestServiceClient(cc) if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[:1]); err != nil { t.Fatal(err) @@ -233,13 +240,14 @@ func (s) TestBalancerSwitch_pickFirstToGRPCLB(t *testing.T) { // Push a resolver update containing a non-existent grpclb server address. // This should not lead to a balancer switch. - r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: "nonExistentServer", Type: resolver.GRPCLB}}}) + r.UpdateState(grpclbstate.Set(state, &grpclbstate.State{BalancerAddresses: []resolver.Address{{Addr: "nonExistentServer"}}})) if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[:1]); err != nil { t.Fatal(err) } // Switch to "pick_first" again by sending no grpclb server addresses. - r.UpdateState(resolver.State{Addresses: addrs[1:]}) + emptyConfig := parseServiceConfig(t, r, `{}`) + r.UpdateState(resolver.State{Addresses: addrs[1:], ServiceConfig: emptyConfig}) if err := pickfirst.CheckRPCsToBackend(ctx, cc, addrs[1]); err != nil { t.Fatal(err) } @@ -284,13 +292,13 @@ func (s) TestBalancerSwitch_RoundRobinToGRPCLB(t *testing.T) { t.Fatal(err) } - // Push a resolver update with no service config and a single address pointing - // to the grpclb server we created above. This will cause the channel to - // switch to the "grpclb" balancer, which returns a single backend address. - r.UpdateState(resolver.State{ - Addresses: []resolver.Address{{Addr: lbServer.Address(), Type: resolver.GRPCLB}}, - ServiceConfig: scpr, - }) + // Push a resolver update with grpclb and a single balancer address + // pointing to the grpclb server we created above. This will cause the + // channel to switch to the "grpclb" balancer, which returns a single + // backend address. + grpclbConfig := parseServiceConfig(t, r, `{"loadBalancingPolicy": "grpclb"}`) + state := resolver.State{ServiceConfig: grpclbConfig} + r.UpdateState(grpclbstate.Set(state, &grpclbstate.State{BalancerAddresses: []resolver.Address{{Addr: lbServer.Address()}}})) if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[:1]); err != nil { t.Fatal(err) } @@ -329,12 +337,13 @@ func (s) TestBalancerSwitch_grpclbNotRegistered(t *testing.T) { // fallback to the default LB policy which is pick_first. The ClientConn is // also expected to filter out the grpclb address when sending the addresses // list fo pick_first. - grpclbAddr := []resolver.Address{{Addr: "non-existent-grpclb-server-address", Type: resolver.GRPCLB}} - addrs = append(grpclbAddr, addrs...) - r.UpdateState(resolver.State{Addresses: addrs}) + grpclbAddr := []resolver.Address{{Addr: "non-existent-grpclb-server-address"}} + grpclbConfig := parseServiceConfig(t, r, `{"loadBalancingPolicy": "grpclb"}`) + state := resolver.State{ServiceConfig: grpclbConfig, Addresses: addrs} + r.UpdateState(grpclbstate.Set(state, &grpclbstate.State{BalancerAddresses: grpclbAddr})) ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) defer cancel() - if err := pickfirst.CheckRPCsToBackend(ctx, cc, addrs[1]); err != nil { + if err := pickfirst.CheckRPCsToBackend(ctx, cc, addrs[0]); err != nil { t.Fatal(err) } @@ -346,116 +355,7 @@ func (s) TestBalancerSwitch_grpclbNotRegistered(t *testing.T) { ServiceConfig: parseServiceConfig(t, r, rrServiceConfig), }) client := testgrpc.NewTestServiceClient(cc) - if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[1:]); err != nil { - t.Fatal(err) - } -} - -// TestBalancerSwitch_grpclbAddressOverridesLoadBalancingPolicy verifies that -// if the resolver update contains any addresses of type "grpclb", it overrides -// the LB policy specifies in the deprecated `loadBalancingPolicy` field of the -// service config. -func (s) TestBalancerSwitch_grpclbAddressOverridesLoadBalancingPolicy(t *testing.T) { - backends, lbServer, cleanup := setupBackendsAndFakeGRPCLB(t) - defer cleanup() - - addrs := stubBackendsToResolverAddrs(backends) - r := manual.NewBuilderWithScheme("whatever") - target := fmt.Sprintf("%s:///%s", r.Scheme(), loadBalancedServiceName) - cc, err := grpc.Dial(target, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r)) - if err != nil { - t.Fatalf("grpc.Dial() failed: %v", err) - } - defer cc.Close() - - // Push a resolver update containing no grpclb server address. This should - // lead to the channel using the default LB policy which is pick_first. - r.UpdateState(resolver.State{Addresses: addrs[1:]}) - ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) - defer cancel() - if err := pickfirst.CheckRPCsToBackend(ctx, cc, addrs[1]); err != nil { - t.Fatal(err) - } - - // Push a resolver update with no service config. The addresses list contains - // the stub backend addresses and a single address pointing to the grpclb - // server we created above. This will cause the channel to switch to the - // "grpclb" balancer, which returns a single backend address. - r.UpdateState(resolver.State{ - Addresses: append(addrs[1:], resolver.Address{Addr: lbServer.Address(), Type: resolver.GRPCLB}), - }) - client := testgrpc.NewTestServiceClient(cc) - if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[:1]); err != nil { - t.Fatal(err) - } - - // Push a resolver update with a service config using the deprecated - // `loadBalancingPolicy` field pointing to round_robin. The addresses list - // contains an address of type "grpclb". This should be preferred and hence - // there should be no balancer switch. - scpr := parseServiceConfig(t, r, `{"loadBalancingPolicy": "round_robin"}`) - r.UpdateState(resolver.State{ - Addresses: append(addrs[1:], resolver.Address{Addr: lbServer.Address(), Type: resolver.GRPCLB}), - ServiceConfig: scpr, - }) - if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[:1]); err != nil { - t.Fatal(err) - } - - // Switch to "round_robin" by removing the address of type "grpclb". - r.UpdateState(resolver.State{Addresses: addrs[1:]}) - if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[1:]); err != nil { - t.Fatal(err) - } -} - -// TestBalancerSwitch_LoadBalancingConfigTrumps verifies that the -// `loadBalancingConfig` field in the service config trumps over addresses of -// type "grpclb" when it comes to deciding which LB policy is applied on the -// channel. -func (s) TestBalancerSwitch_LoadBalancingConfigTrumps(t *testing.T) { - backends, lbServer, cleanup := setupBackendsAndFakeGRPCLB(t) - defer cleanup() - - addrs := stubBackendsToResolverAddrs(backends) - r := manual.NewBuilderWithScheme("whatever") - target := fmt.Sprintf("%s:///%s", r.Scheme(), loadBalancedServiceName) - cc, err := grpc.Dial(target, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(r)) - if err != nil { - t.Fatalf("grpc.Dial() failed: %v", err) - } - defer cc.Close() - - // Push a resolver update with no service config and a single address pointing - // to the grpclb server we created above. This will cause the channel to - // switch to the "grpclb" balancer, which returns a single backend address. - r.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: lbServer.Address(), Type: resolver.GRPCLB}}}) - ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) - defer cancel() - client := testgrpc.NewTestServiceClient(cc) - if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[:1]); err != nil { - t.Fatal(err) - } - - // Push a resolver update with the service config specifying "round_robin" - // through the recommended `loadBalancingConfig` field. - r.UpdateState(resolver.State{ - Addresses: addrs[1:], - ServiceConfig: parseServiceConfig(t, r, rrServiceConfig), - }) - if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[1:]); err != nil { - t.Fatal(err) - } - - // Push a resolver update with no service config and an address of type - // "grpclb". The ClientConn should continue to use the service config received - // earlier, which specified the use of "round_robin" through the - // `loadBalancingConfig` field, and therefore the balancer should not be - // switched. And because the `loadBalancingConfig` field trumps everything - // else, the address of type "grpclb" should be ignored. - grpclbAddr := resolver.Address{Addr: "non-existent-grpclb-server-address", Type: resolver.GRPCLB} - r.UpdateState(resolver.State{Addresses: append(addrs[1:], grpclbAddr)}) - if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs[1:]); err != nil { + if err := rrutil.CheckRoundRobinRPCs(ctx, client, addrs); err != nil { t.Fatal(err) } } diff --git a/test/balancer_test.go b/test/balancer_test.go index 4026c75b46e3..6bbaed280973 100644 --- a/test/balancer_test.go +++ b/test/balancer_test.go @@ -346,97 +346,6 @@ func testDoneLoads(t *testing.T) { } } -const testBalancerKeepAddressesName = "testbalancer-keepingaddresses" - -// testBalancerKeepAddresses keeps the addresses in the builder instead of -// creating SubConns. -// -// It's used to test the addresses balancer gets are correct. -type testBalancerKeepAddresses struct { - addrsChan chan []resolver.Address -} - -func newTestBalancerKeepAddresses() *testBalancerKeepAddresses { - return &testBalancerKeepAddresses{ - addrsChan: make(chan []resolver.Address, 10), - } -} - -func (testBalancerKeepAddresses) ResolverError(err error) { - panic("not implemented") -} - -func (b *testBalancerKeepAddresses) Build(cc balancer.ClientConn, opt balancer.BuildOptions) balancer.Balancer { - return b -} - -func (*testBalancerKeepAddresses) Name() string { - return testBalancerKeepAddressesName -} - -func (b *testBalancerKeepAddresses) UpdateClientConnState(state balancer.ClientConnState) error { - b.addrsChan <- state.ResolverState.Addresses - return nil -} - -func (testBalancerKeepAddresses) UpdateSubConnState(sc balancer.SubConn, s balancer.SubConnState) { - panic("not used") -} - -func (testBalancerKeepAddresses) Close() {} - -func (testBalancerKeepAddresses) ExitIdle() {} - -// Make sure that non-grpclb balancers don't get grpclb addresses even if name -// resolver sends them -func (s) TestNonGRPCLBBalancerGetsNoGRPCLBAddress(t *testing.T) { - r := manual.NewBuilderWithScheme("whatever") - - b := newTestBalancerKeepAddresses() - balancer.Register(b) - - cc, err := grpc.Dial(r.Scheme()+":///test.server", - grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithResolvers(r), - grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, b.Name()))) - if err != nil { - t.Fatalf("failed to dial: %v", err) - } - defer cc.Close() - - grpclbAddresses := []resolver.Address{{ - Addr: "grpc.lb.com", - Type: resolver.GRPCLB, - ServerName: "grpc.lb.com", - }} - - nonGRPCLBAddresses := []resolver.Address{{ - Addr: "localhost", - Type: resolver.Backend, - }} - - r.UpdateState(resolver.State{ - Addresses: nonGRPCLBAddresses, - }) - if got := <-b.addrsChan; !reflect.DeepEqual(got, nonGRPCLBAddresses) { - t.Fatalf("With only backend addresses, balancer got addresses %v, want %v", got, nonGRPCLBAddresses) - } - - r.UpdateState(resolver.State{ - Addresses: grpclbAddresses, - }) - if got := <-b.addrsChan; len(got) != 0 { - t.Fatalf("With only grpclb addresses, balancer got addresses %v, want empty", got) - } - - r.UpdateState(resolver.State{ - Addresses: append(grpclbAddresses, nonGRPCLBAddresses...), - }) - if got := <-b.addrsChan; !reflect.DeepEqual(got, nonGRPCLBAddresses) { - t.Fatalf("With both backend and grpclb addresses, balancer got addresses %v, want %v", got, nonGRPCLBAddresses) - } -} - type aiPicker struct { result balancer.PickResult err error diff --git a/test/channelz_test.go b/test/channelz_test.go index d43c155a15df..62143fcde6fe 100644 --- a/test/channelz_test.go +++ b/test/channelz_test.go @@ -33,6 +33,7 @@ import ( "golang.org/x/net/http2" "google.golang.org/grpc" _ "google.golang.org/grpc/balancer/grpclb" + grpclbstate "google.golang.org/grpc/balancer/grpclb/state" "google.golang.org/grpc/balancer/roundrobin" "google.golang.org/grpc/codes" "google.golang.org/grpc/connectivity" @@ -214,10 +215,11 @@ func (s) TestCZNestedChannelRegistrationAndDeletion(t *testing.T) { e.balancer = "" te := newTest(t, e) r := manual.NewBuilderWithScheme("whatever") - resolvedAddrs := []resolver.Address{{Addr: "127.0.0.1:0", Type: resolver.GRPCLB, ServerName: "grpclb.server"}} - r.InitialState(resolver.State{Addresses: resolvedAddrs}) te.resolverScheme = r.Scheme() te.clientConn(grpc.WithResolvers(r)) + resolvedAddrs := []resolver.Address{{Addr: "127.0.0.1:0", ServerName: "grpclb.server"}} + grpclbConfig := parseServiceConfig(t, r, `{"loadBalancingPolicy": "grpclb"}`) + r.UpdateState(grpclbstate.Set(resolver.State{ServiceConfig: grpclbConfig}, &grpclbstate.State{BalancerAddresses: resolvedAddrs})) defer te.tearDown() if err := verifyResultWithDelay(func() (bool, error) { @@ -1409,10 +1411,11 @@ func (s) TestCZChannelTraceCreationDeletion(t *testing.T) { e.balancer = "" te := newTest(t, e) r := manual.NewBuilderWithScheme("whatever") - resolvedAddrs := []resolver.Address{{Addr: "127.0.0.1:0", Type: resolver.GRPCLB, ServerName: "grpclb.server"}} - r.InitialState(resolver.State{Addresses: resolvedAddrs}) te.resolverScheme = r.Scheme() te.clientConn(grpc.WithResolvers(r)) + resolvedAddrs := []resolver.Address{{Addr: "127.0.0.1:0", ServerName: "grpclb.server"}} + grpclbConfig := parseServiceConfig(t, r, `{"loadBalancingPolicy": "grpclb"}`) + r.UpdateState(grpclbstate.Set(resolver.State{ServiceConfig: grpclbConfig}, &grpclbstate.State{BalancerAddresses: resolvedAddrs})) defer te.tearDown() var nestedConn int64 @@ -1914,10 +1917,11 @@ func (s) TestCZTraceOverwriteChannelDeletion(t *testing.T) { channelz.SetMaxTraceEntry(1) defer channelz.ResetMaxTraceEntryToDefault() r := manual.NewBuilderWithScheme("whatever") - resolvedAddrs := []resolver.Address{{Addr: "127.0.0.1:0", Type: resolver.GRPCLB, ServerName: "grpclb.server"}} - r.InitialState(resolver.State{Addresses: resolvedAddrs}) te.resolverScheme = r.Scheme() te.clientConn(grpc.WithResolvers(r)) + resolvedAddrs := []resolver.Address{{Addr: "127.0.0.1:0", ServerName: "grpclb.server"}} + grpclbConfig := parseServiceConfig(t, r, `{"loadBalancingPolicy": "grpclb"}`) + r.UpdateState(grpclbstate.Set(resolver.State{ServiceConfig: grpclbConfig}, &grpclbstate.State{BalancerAddresses: resolvedAddrs})) defer te.tearDown() var nestedConn int64 if err := verifyResultWithDelay(func() (bool, error) { diff --git a/vet.sh b/vet.sh index a8e4732b3d20..0919ae6a5a52 100755 --- a/vet.sh +++ b/vet.sh @@ -168,8 +168,6 @@ proto.RegisteredExtension is deprecated proto.RegisteredExtensions is deprecated proto.RegisterMapType is deprecated proto.Unmarshaler is deprecated -resolver.Backend -resolver.GRPCLB Target is deprecated: Use the Target field in the BuildOptions instead. xxx_messageInfo_ ' "${SC_OUT}"