Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpclb, dns: pass balancer addresses via resolver.State #3614

Merged
merged 2 commits into from
May 26, 2020

Conversation

dfawley
Copy link
Member

@dfawley dfawley commented May 12, 2020

This change implements gRFC A26: gRPCLB Selection:
https://github.com/grpc/proposal/blob/master/A26-grpclb-selection.md

Note that addresses passed to gRPCLB through resolver.State.Attributes will not
automatically select the "grpclb" load balancing policy. This will result in a
behavior change for users currently using the DNS name resolver and relying
upon that behavior. Instead, a service config specifying grpclb must be used.
For example:

{
  "loadBalancingConfig": [
    {"grpclb": {}}
  ]
}

While this is a behavior change for gRPC-Go, it brings gRPC in line with the
intended implementation for gRPCLB support, and the behavior of the C and Java
gRPC implementations, and is considered a bug fix for that reason.

For now, and until support for the resolver.GRPCLB value is deleted, the
"grpclb" load balancing policy will still be selected automatically when
addresses with those types are produced by a name resolver. This will prevent
custom resolvers from being impacted by this behavior change until they need to
be modified due to the deletion of this deprecated value.

This change implements gRFC A26: gRPCLB Selection:
https://github.com/grpc/proposal/blob/master/A26-grpclb-selection.md

Note that addresses passed to gRPCLB through resolver.State.Attributes will not
automatically select the "grpclb" load balancing policy.  This will result in a
behavior change for users currently using the DNS name resolver and relying
upon that behavior.  Instead, a service config specifying grpclb must be used.
For example:

{
  "loadBalancingConfig": [
    {"grpclb": {}}
  ]
}

While this is a behavior change for gRPC-Go, it brings gRPC in line with the
intended implementation for gRPCLB support, and the behavior of the C and Java
gRPC implementations, and is considered a bug fix.

For now, and until support for the resolver.GRPCLB value is deleted, the
"grpclb" load balancing policy will still be selected automatically when
addresses with those types are produced by a name resolver.  This will prevent
custom resolvers from being impacted by this behavior change until they need to
be modified due to the deletion of this deprecated value.
@dfawley dfawley added the Type: Behavior Change Behavior changes not categorized as bugs label May 12, 2020
@dfawley dfawley added this to the 1.30 Release milestone May 12, 2020
@dfawley dfawley requested a review from menghanl May 12, 2020 21:11
// stateDataAttributesKey is the key to use for storing StateData in Attributes.
type sdKeyType string

const sdKey = sdKeyType("grpc.grpclb.state_data")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshedding: grpc.grpclb.state?

And package/struct name to state?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Maybe there are too many "states" now, though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other states? Those are types, not variables?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolver.State, balancer.State, now a state package. With import renaming this one isn't really a problem in practice, but it could be confusing to have so many things called "state".

newAddrs = append(newAddrs, resolver.Address{Addr: addr, Type: resolver.GRPCLB, ServerName: s.Target})
// Use Type: Backend instead of GRPCLB since we will be returning
// these addresses through attributes instead of Addresses.
newAddrs = append(newAddrs, resolver.Address{Addr: addr, Type: resolver.Backend, ServerName: s.Target})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't set Type? Is Backend the default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


state := &resolver.State{Addresses: addrs}
if len(srv) > 0 {
*state = statedata.Set(*state, &statedata.StateData{BalancerAddresses: srv})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many copies of state does this line make?
Is it better to change the line above to not take the pointer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

generateSC("foo.bar.com"),
},
{
"srv.ipv4.single.fake",
[]resolver.Address{{Addr: "2.4.6.8" + colonDefaultPort}, {Addr: "1.2.3.4:1234", Type: resolver.GRPCLB, ServerName: "ipv4.single.fake"}},
[]resolver.Address{{Addr: "2.4.6.8" + colonDefaultPort}},
[]resolver.Address{{Addr: "1.2.3.4:1234", Type: resolver.Backend, ServerName: "ipv4.single.fake"}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change the resolver to not explicitly set Backend, change the the tests, too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

sd := statedata.Get(state)
if (sd == nil && len(a.grpclbAddrs) > 0) ||
(sd != nil && !reflect.DeepEqual(a.grpclbAddrs, sd.BalancerAddresses)) {
t.Errorf("Resolved state of target: %q = %+v (StateData=%+v), want state.Attributes.StateData=%+v\n", a.target, state, sd, a.grpclbAddrs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove \n in errorf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (x100)

@menghanl menghanl assigned dfawley and unassigned menghanl May 14, 2020
@dfawley dfawley assigned menghanl and unassigned dfawley May 26, 2020
@dfawley dfawley merged commit eb827fb into grpc:master May 26, 2020
@dfawley dfawley deleted the grpclb_via_attrs branch May 26, 2020 22:24
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Behavior Change Behavior changes not categorized as bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants