-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
balancer/resolver: add loadBalancingConfig and pre-parsing support #2732
Conversation
balancer/balancer.go
Outdated
@@ -166,6 +170,14 @@ type Builder interface { | |||
Name() string | |||
} | |||
|
|||
// Parser parses service configs. | |||
type Parser interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConfigParser
?
(Or even, JsonConfigParser
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
balancer_conn_wrappers.go
Outdated
if s.Addresses[i].Type == resolver.GRPCLB { | ||
copy(s.Addresses[i:], s.Addresses[i+1:]) | ||
s.Addresses = s.Addresses[:len(s.Addresses)-1] | ||
for i := 0; i < len(s.ResolverState.Addresses); { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: make a local variable? Is go smart enough to optimize out the dereference cost?
Or, rename the parameter to css
, and then s := css.ResolverState
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (second one) - I'm actually modifying the state to remove those addresses, so making a local holding the slice won't update the contents of the ClientConnState
properly (i.e. making it shorter).
clientconn.go
Outdated
if err != nil { | ||
fmt.Println("error parsing config: ", err) | ||
return err | ||
if sc, ok := s.ServiceConfig.(ServiceConfig); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compare service config?
(Compare raw json? This doesn't work because of balancer configs, right?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only place where checking it would matter is when we reset the retry throttling tokens, and that should probably be checked independently in case parts of the config change but the retry config doesn't.
Otherwise, it's just reassigning a pointer. WDYT?
service_config.go
Outdated
} | ||
|
||
type loadBalancingConfig map[string]json.RawMessage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is only used once. Inline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlining makes it really complex. *[]map[string]json.RawMessage
- I'd rather give it a name and then have it be easier to understand the field in the jsonSC.
service_config.go
Outdated
continue | ||
} | ||
sc.lbConfig = &lbConfig{name: name} | ||
if parser, ok := builder.(balancer.Parser); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning if not OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
// Parse parses the JSON service config provided into an internal form or | ||
// returns an error if the config is invalid. | ||
func Parse(ServiceConfigJSON string) (Config, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParseJson
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather leave this unqualified. If we ever decide to support parsing another format in grpc-go, then the other formats can be namespaced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything is updated and should be good to review again. Now with xds and grpclb adoption of the V2 interfaces!
balancer/balancer.go
Outdated
@@ -166,6 +170,14 @@ type Builder interface { | |||
Name() string | |||
} | |||
|
|||
// Parser parses service configs. | |||
type Parser interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
balancer_conn_wrappers.go
Outdated
if s.Addresses[i].Type == resolver.GRPCLB { | ||
copy(s.Addresses[i:], s.Addresses[i+1:]) | ||
s.Addresses = s.Addresses[:len(s.Addresses)-1] | ||
for i := 0; i < len(s.ResolverState.Addresses); { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (second one) - I'm actually modifying the state to remove those addresses, so making a local holding the slice won't update the contents of the ClientConnState
properly (i.e. making it shorter).
service_config.go
Outdated
} | ||
|
||
type loadBalancingConfig map[string]json.RawMessage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlining makes it really complex. *[]map[string]json.RawMessage
- I'd rather give it a name and then have it be easier to understand the field in the jsonSC.
service_config.go
Outdated
continue | ||
} | ||
sc.lbConfig = &lbConfig{name: name} | ||
if parser, ok := builder.(balancer.Parser); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
// Parse parses the JSON service config provided into an internal form or | ||
// returns an error if the config is invalid. | ||
func Parse(ServiceConfigJSON string) (Config, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather leave this unqualified. If we ever decide to support parsing another format in grpc-go, then the other formats can be namespaced.
clientconn.go
Outdated
if err != nil { | ||
fmt.Println("error parsing config: ", err) | ||
return err | ||
if sc, ok := s.ServiceConfig.(ServiceConfig); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only place where checking it would matter is when we reset the retry throttling tokens, and that should probably be checked independently in case parts of the config change but the retry config doesn't.
Otherwise, it's just reassigning a pointer. WDYT?
balancer/xds/xds.go
Outdated
case *resolver.State: | ||
cfg := getBalancerConfig(u.ServiceConfig) | ||
case *balancer.ClientConnState: | ||
cfg, _ := u.BalancerConfig.(*xdsConfig) | ||
if cfg == nil { | ||
// service config parsing failed. should never happen. And this parsing will be removed, once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should we do here? I think we need to leave this code for defensive programming, to avoid nil panics, but the comment could be updated, e.g. only say "should never happen"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 7 of 16 files at r1, 16 of 16 files at r2.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @dfawley)
balancer/xds/xds.go, line 247 at r2 (raw file):
What should we do here? I think we need to leave this code for defensive programming, to avoid nil panics, but the comment could be updated, e.g. only say "should never happen"?
Yes, this needs to be done anyway in all balancers.
balancer/xds/xds.go, line 603 at r2 (raw file):
} for _, lbcfg := range lbcfgs { if balancer.Get(lbcfg.Name) != nil {
Are you still planning to move this out from unmarshal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 22 of 23 files reviewed, 2 unresolved discussions (waiting on @menghanl)
balancer/xds/xds.go, line 247 at r2 (raw file):
Previously, menghanl (Menghan Li) wrote…
What should we do here? I think we need to leave this code for defensive programming, to avoid nil panics, but the comment could be updated, e.g. only say "should never happen"?
Yes, this needs to be done anyway in all balancers.
Done.
balancer/xds/xds.go, line 603 at r2 (raw file):
Previously, menghanl (Menghan Li) wrote…
Are you still planning to move this out from unmarshal?
Not in this PR. I want to avoid making unrelated changes for now to reduce risk on an otherwise-significant PR.
This is still subject to change; pushing now to get initial round of feedback.
This change is