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

balancer/resolver: add loadBalancingConfig and pre-parsing support #2732

Merged
merged 5 commits into from
May 30, 2019

Conversation

dfawley
Copy link
Member

@dfawley dfawley commented Mar 29, 2019

This is still subject to change; pushing now to get initial round of feedback.


This change is Reviewable

@dfawley dfawley added the Type: Feature New features or improvements in behavior label Mar 29, 2019
@dfawley dfawley requested a review from menghanl March 29, 2019 22:44
@@ -166,6 +170,14 @@ type Builder interface {
Name() string
}

// Parser parses service configs.
type Parser interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

ConfigParser?

(Or even, JsonConfigParser?)

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

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); {
Copy link
Contributor

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.

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 (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 {
Copy link
Contributor

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?)

Copy link
Member Author

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?

}

type loadBalancingConfig map[string]json.RawMessage
Copy link
Contributor

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?

Copy link
Member Author

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.

continue
}
sc.lbConfig = &lbConfig{name: name}
if parser, ok := builder.(balancer.Parser); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning if not OK

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


// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ParseJson?

Copy link
Member Author

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.

Copy link
Member Author

@dfawley dfawley left a 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!

@@ -166,6 +170,14 @@ type Builder interface {
Name() string
}

// Parser parses service configs.
type Parser interface {
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

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); {
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 (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).

}

type loadBalancingConfig map[string]json.RawMessage
Copy link
Member Author

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.

continue
}
sc.lbConfig = &lbConfig{name: name}
if parser, ok := builder.(balancer.Parser); ok {
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


// 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) {
Copy link
Member Author

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 {
Copy link
Member Author

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?

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
Copy link
Member Author

@dfawley dfawley May 24, 2019

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"?

@dfawley dfawley assigned menghanl and unassigned dfawley May 28, 2019
Copy link
Contributor

@menghanl menghanl left a 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?

Copy link
Member Author

@dfawley dfawley left a 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.

@dfawley dfawley merged commit d40a995 into grpc:master May 30, 2019
@dfawley dfawley deleted the lbconfig branch May 30, 2019 16:13
@dfawley dfawley added this to the 1.22 Release milestone May 30, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants