Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley committed Oct 15, 2021
1 parent ece5aed commit c9044e3
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 49 deletions.
4 changes: 2 additions & 2 deletions internal/credentials/xds/handshake_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ type handshakeAttrKey struct{}
// Equal reports whether the handshake info structs are identical (have the
// same pointer). This is sufficient as all subconns from one CDS balancer use
// the same one.
func (h *HandshakeInfo) Equal(o interface{}) bool {
func (hi *HandshakeInfo) Equal(o interface{}) bool {
oh, ok := o.(*HandshakeInfo)
return ok && oh == h
return ok && oh == hi
}

// SetHandshakeInfo returns a copy of addr in which the Attributes field is
Expand Down
2 changes: 1 addition & 1 deletion internal/hierarchy/hierarchy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func Get(addr resolver.Address) []string {

// Set overrides the hierarchical path in addr with path.
func Set(addr resolver.Address, path []string) resolver.Address {
addr.Attributes = addr.BalancerAttributes.WithValue(pathKey, pathValue(path))
addr.BalancerAttributes = addr.BalancerAttributes.WithValue(pathKey, pathValue(path))
return addr
}

Expand Down
48 changes: 24 additions & 24 deletions internal/hierarchy/hierarchy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestGet(t *testing.T) {
{
name: "set",
addr: resolver.Address{
Attributes: attributes.New(pathKey, pathValue{"a", "b"}),
BalancerAttributes: attributes.New(pathKey, pathValue{"a", "b"}),
},
want: []string{"a", "b"},
},
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestSet(t *testing.T) {
{
name: "before is set",
addr: resolver.Address{
Attributes: attributes.New(pathKey, pathValue{"before", "a", "b"}),
BalancerAttributes: attributes.New(pathKey, pathValue{"before", "a", "b"}),
},
path: []string{"a", "b"},
},
Expand All @@ -93,35 +93,35 @@ func TestGroup(t *testing.T) {
{
name: "all with hierarchy",
addrs: []resolver.Address{
{Addr: "a0", Attributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "a1", Attributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "b0", Attributes: attributes.New(pathKey, pathValue{"b"})},
{Addr: "b1", Attributes: attributes.New(pathKey, pathValue{"b"})},
{Addr: "a0", BalancerAttributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "a1", BalancerAttributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "b0", BalancerAttributes: attributes.New(pathKey, pathValue{"b"})},
{Addr: "b1", BalancerAttributes: attributes.New(pathKey, pathValue{"b"})},
},
want: map[string][]resolver.Address{
"a": {
{Addr: "a0", Attributes: attributes.New(pathKey, pathValue{})},
{Addr: "a1", Attributes: attributes.New(pathKey, pathValue{})},
{Addr: "a0", BalancerAttributes: attributes.New(pathKey, pathValue{})},
{Addr: "a1", BalancerAttributes: attributes.New(pathKey, pathValue{})},
},
"b": {
{Addr: "b0", Attributes: attributes.New(pathKey, pathValue{})},
{Addr: "b1", Attributes: attributes.New(pathKey, pathValue{})},
{Addr: "b0", BalancerAttributes: attributes.New(pathKey, pathValue{})},
{Addr: "b1", BalancerAttributes: attributes.New(pathKey, pathValue{})},
},
},
},
{
// Addresses without hierarchy are ignored.
name: "without hierarchy",
addrs: []resolver.Address{
{Addr: "a0", Attributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "a1", Attributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "b0", Attributes: nil},
{Addr: "b1", Attributes: nil},
{Addr: "a0", BalancerAttributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "a1", BalancerAttributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "b0", BalancerAttributes: nil},
{Addr: "b1", BalancerAttributes: nil},
},
want: map[string][]resolver.Address{
"a": {
{Addr: "a0", Attributes: attributes.New(pathKey, pathValue{})},
{Addr: "a1", Attributes: attributes.New(pathKey, pathValue{})},
{Addr: "a0", BalancerAttributes: attributes.New(pathKey, pathValue{})},
{Addr: "a1", BalancerAttributes: attributes.New(pathKey, pathValue{})},
},
},
},
Expand All @@ -130,15 +130,15 @@ func TestGroup(t *testing.T) {
// the address is ignored.
name: "wrong type",
addrs: []resolver.Address{
{Addr: "a0", Attributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "a1", Attributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "b0", Attributes: attributes.New(pathKey, "b")},
{Addr: "b1", Attributes: attributes.New(pathKey, 314)},
{Addr: "a0", BalancerAttributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "a1", BalancerAttributes: attributes.New(pathKey, pathValue{"a"})},
{Addr: "b0", BalancerAttributes: attributes.New(pathKey, "b")},
{Addr: "b1", BalancerAttributes: attributes.New(pathKey, 314)},
},
want: map[string][]resolver.Address{
"a": {
{Addr: "a0", Attributes: attributes.New(pathKey, pathValue{})},
{Addr: "a1", Attributes: attributes.New(pathKey, pathValue{})},
{Addr: "a0", BalancerAttributes: attributes.New(pathKey, pathValue{})},
{Addr: "a1", BalancerAttributes: attributes.New(pathKey, pathValue{})},
},
},
},
Expand Down Expand Up @@ -173,8 +173,8 @@ func TestGroupE2E(t *testing.T) {
path2 = append(path2, wt)
for _, addr := range addrs {
a := resolver.Address{
Addr: addr,
Attributes: attributes.New(pathKey, path2),
Addr: addr,
BalancerAttributes: attributes.New(pathKey, path2),
}
addrsWithHierarchy = append(addrsWithHierarchy, a)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/resolver/config_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const csKey = csKeyType("grpc.internal.resolver.configSelector")
// SetConfigSelector sets the config selector in state and returns the new
// state.
func SetConfigSelector(state resolver.State, cs ConfigSelector) resolver.State {
state.Attributes = state.Attributes.WithValues(csKey, cs)
state.Attributes = state.Attributes.WithValue(csKey, cs)
return state
}

Expand Down
38 changes: 19 additions & 19 deletions xds/internal/balancer/clustermanager/clustermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type ignoreAttrsRRBalancer struct {
func (trrb *ignoreAttrsRRBalancer) UpdateClientConnState(s balancer.ClientConnState) error {
var newAddrs []resolver.Address
for _, a := range s.ResolverState.Addresses {
a.Attributes = nil
a.BalancerAttributes = nil
newAddrs = append(newAddrs, a)
}
s.ResolverState.Addresses = newAddrs
Expand Down Expand Up @@ -137,8 +137,8 @@ func TestClusterPicks(t *testing.T) {

// Send the config, and an address with hierarchy path ["cluster_1"].
wantAddrs := []resolver.Address{
{Addr: testBackendAddrStrs[0], Attributes: nil},
{Addr: testBackendAddrStrs[1], Attributes: nil},
{Addr: testBackendAddrStrs[0], BalancerAttributes: nil},
{Addr: testBackendAddrStrs[1], BalancerAttributes: nil},
}
if err := rtb.UpdateClientConnState(balancer.ClientConnState{
ResolverState: resolver.State{Addresses: []resolver.Address{
Expand All @@ -156,11 +156,11 @@ func TestClusterPicks(t *testing.T) {
for range wantAddrs {
addrs := <-cc.NewSubConnAddrsCh
if len(hierarchy.Get(addrs[0])) != 0 {
t.Fatalf("NewSubConn with address %+v, attrs %+v, want address with hierarchy cleared", addrs[0], addrs[0].Attributes)
t.Fatalf("NewSubConn with address %+v, attrs %+v, want address with hierarchy cleared", addrs[0], addrs[0].BalancerAttributes)
}
sc := <-cc.NewSubConnCh
// Clear the attributes before adding to map.
addrs[0].Attributes = nil
addrs[0].BalancerAttributes = nil
m1[addrs[0]] = sc
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Connecting})
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Ready})
Expand Down Expand Up @@ -215,8 +215,8 @@ func TestConfigUpdateAddCluster(t *testing.T) {

// Send the config, and an address with hierarchy path ["cluster_1"].
wantAddrs := []resolver.Address{
{Addr: testBackendAddrStrs[0], Attributes: nil},
{Addr: testBackendAddrStrs[1], Attributes: nil},
{Addr: testBackendAddrStrs[0], BalancerAttributes: nil},
{Addr: testBackendAddrStrs[1], BalancerAttributes: nil},
}
if err := rtb.UpdateClientConnState(balancer.ClientConnState{
ResolverState: resolver.State{Addresses: []resolver.Address{
Expand All @@ -234,11 +234,11 @@ func TestConfigUpdateAddCluster(t *testing.T) {
for range wantAddrs {
addrs := <-cc.NewSubConnAddrsCh
if len(hierarchy.Get(addrs[0])) != 0 {
t.Fatalf("NewSubConn with address %+v, attrs %+v, want address with hierarchy cleared", addrs[0], addrs[0].Attributes)
t.Fatalf("NewSubConn with address %+v, attrs %+v, want address with hierarchy cleared", addrs[0], addrs[0].BalancerAttributes)
}
sc := <-cc.NewSubConnCh
// Clear the attributes before adding to map.
addrs[0].Attributes = nil
addrs[0].BalancerAttributes = nil
m1[addrs[0]] = sc
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Connecting})
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Ready})
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestConfigUpdateAddCluster(t *testing.T) {
if err != nil {
t.Fatalf("failed to parse balancer config: %v", err)
}
wantAddrs = append(wantAddrs, resolver.Address{Addr: testBackendAddrStrs[2], Attributes: nil})
wantAddrs = append(wantAddrs, resolver.Address{Addr: testBackendAddrStrs[2], BalancerAttributes: nil})
if err := rtb.UpdateClientConnState(balancer.ClientConnState{
ResolverState: resolver.State{Addresses: []resolver.Address{
hierarchy.Set(wantAddrs[0], []string{"cds:cluster_1"}),
Expand All @@ -300,11 +300,11 @@ func TestConfigUpdateAddCluster(t *testing.T) {
// Expect exactly one new subconn.
addrs := <-cc.NewSubConnAddrsCh
if len(hierarchy.Get(addrs[0])) != 0 {
t.Fatalf("NewSubConn with address %+v, attrs %+v, want address with hierarchy cleared", addrs[0], addrs[0].Attributes)
t.Fatalf("NewSubConn with address %+v, attrs %+v, want address with hierarchy cleared", addrs[0], addrs[0].BalancerAttributes)
}
sc := <-cc.NewSubConnCh
// Clear the attributes before adding to map.
addrs[0].Attributes = nil
addrs[0].BalancerAttributes = nil
m1[addrs[0]] = sc
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Connecting})
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Ready})
Expand Down Expand Up @@ -372,8 +372,8 @@ func TestRoutingConfigUpdateDeleteAll(t *testing.T) {

// Send the config, and an address with hierarchy path ["cluster_1"].
wantAddrs := []resolver.Address{
{Addr: testBackendAddrStrs[0], Attributes: nil},
{Addr: testBackendAddrStrs[1], Attributes: nil},
{Addr: testBackendAddrStrs[0], BalancerAttributes: nil},
{Addr: testBackendAddrStrs[1], BalancerAttributes: nil},
}
if err := rtb.UpdateClientConnState(balancer.ClientConnState{
ResolverState: resolver.State{Addresses: []resolver.Address{
Expand All @@ -391,11 +391,11 @@ func TestRoutingConfigUpdateDeleteAll(t *testing.T) {
for range wantAddrs {
addrs := <-cc.NewSubConnAddrsCh
if len(hierarchy.Get(addrs[0])) != 0 {
t.Fatalf("NewSubConn with address %+v, attrs %+v, want address with hierarchy cleared", addrs[0], addrs[0].Attributes)
t.Fatalf("NewSubConn with address %+v, attrs %+v, want address with hierarchy cleared", addrs[0], addrs[0].BalancerAttributes)
}
sc := <-cc.NewSubConnCh
// Clear the attributes before adding to map.
addrs[0].Attributes = nil
addrs[0].BalancerAttributes = nil
m1[addrs[0]] = sc
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Connecting})
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Ready})
Expand Down Expand Up @@ -475,11 +475,11 @@ func TestRoutingConfigUpdateDeleteAll(t *testing.T) {
for range wantAddrs {
addrs := <-cc.NewSubConnAddrsCh
if len(hierarchy.Get(addrs[0])) != 0 {
t.Fatalf("NewSubConn with address %+v, attrs %+v, want address with hierarchy cleared", addrs[0], addrs[0].Attributes)
t.Fatalf("NewSubConn with address %+v, attrs %+v, want address with hierarchy cleared", addrs[0], addrs[0].BalancerAttributes)
}
sc := <-cc.NewSubConnCh
// Clear the attributes before adding to map.
addrs[0].Attributes = nil
addrs[0].BalancerAttributes = nil
m2[addrs[0]] = sc
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Connecting})
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Ready})
Expand Down Expand Up @@ -608,7 +608,7 @@ func TestInitialIdle(t *testing.T) {

// Send the config, and an address with hierarchy path ["cluster_1"].
wantAddrs := []resolver.Address{
{Addr: testBackendAddrStrs[0], Attributes: nil},
{Addr: testBackendAddrStrs[0], BalancerAttributes: nil},
}
if err := rtb.UpdateClientConnState(balancer.ClientConnState{
ResolverState: resolver.State{Addresses: []resolver.Address{
Expand Down
2 changes: 1 addition & 1 deletion xds/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ func GetLocalityID(addr resolver.Address) LocalityID {

// SetLocalityID sets locality ID in addr to l.
func SetLocalityID(addr resolver.Address, l LocalityID) resolver.Address {
addr.Attributes = addr.BalancerAttributes.WithValue(localityKey, l)
addr.BalancerAttributes = addr.BalancerAttributes.WithValue(localityKey, l)
return addr
}
2 changes: 1 addition & 1 deletion xds/internal/xdsclient/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ func FromResolverState(state resolver.State) XDSClient {

// SetClient sets c in state and returns the new state.
func SetClient(state resolver.State, c XDSClient) resolver.State {
state.Attributes = state.Attributes.WithValues(clientKey, c)
state.Attributes = state.Attributes.WithValue(clientKey, c)
return state
}

0 comments on commit c9044e3

Please sign in to comment.