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

service config: default service config #2686

Merged
merged 5 commits into from
Apr 3, 2019
Merged

service config: default service config #2686

merged 5 commits into from
Apr 3, 2019

Conversation

lyuxuan
Copy link
Contributor

@lyuxuan lyuxuan commented Mar 13, 2019

No description provided.

// will be used in cases where:
// 1. WithDisableServiceConfig is called.
// 2. Resolver does not return service config or if the resolver gets and invalid config.
func WithDefaultServiceConfig(s string) DialOption {
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned over GVC, could we add a link or some documentation describing what this string should look like?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WIP to export a doc about canonical service config json string.

Copy link
Member

Choose a reason for hiding this comment

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

Ack

dialoptions.go Outdated Show resolved Hide resolved
Copy link
Member

@jeanbza jeanbza left a comment

Choose a reason for hiding this comment

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

LGTM but I'll leave approval to someone more knowledgeable.

jeanbza
jeanbza previously approved these changes Mar 19, 2019
clientconn.go Outdated
return nil
}
// apply default service config when there's resolver service config is disabled.
return cc.applyServiceConfig(cc.dopts.defaultServiceConfig, cc.dopts.defaultServiceConfigRaw)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be called every time handleServiceConfig is called

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

clientconn.go Outdated
if err != nil {
return err
}
sc = &scfg
Copy link
Contributor

Choose a reason for hiding this comment

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

return pointer from parseServiceConfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

dialoptions.go Outdated
disableHealthCheck bool
healthCheckFunc internal.HealthChecker
defaultServiceConfig *ServiceConfig
defaultServiceConfigRaw string
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a field to ServiceConfig for the raw js string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

dialoptions.go Outdated
// 2. Resolver does not return service config or if the resolver gets and invalid config.
func WithDefaultServiceConfig(s string) DialOption {
return newFuncDialOption(func(o *dialOptions) {
sc, err := parseServiceConfig(s)
Copy link
Contributor

Choose a reason for hiding this comment

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

We still give users a chance to pass invalid string here.

How about returning a dial option and an error from ValidateServiceConfig(), so the only way to create a default service config dial option is to validate it first?

The name ValidateServiceConfig would be inappropriate, time to bikeshed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we have something like

func WithDefaultServiceConfig(s string) (DialOption, error) {
	sc, err := parseServiceConfig(s)
	if err != nil {
		return nil, fmt.Errorf("the provided service config is invalid, err: %v", err)
	}
	return newFuncDialOption(func(o *dialOptions) {
		o.defaultServiceConfig = sc
	}), nil
}

Then it breaks the idiomatic way of doing grpc.Dial(target, grpc.WithXXX(), grpc.WithYYY()). I think separating the validation is ok. I can add a comment saying that it's strongly recommended to verify the validity of the json string with the ValidateServiceConfig function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per offline discussion, we will check the validity of the default service config in DialContext. If it is not valid, the Dial will fail.

@lyuxuan lyuxuan force-pushed the defsc branch 6 times, most recently from b44a9c0 to 9fab3e0 Compare March 25, 2019 22:05
clientconn.go Outdated Show resolved Hide resolved
clientconn.go Show resolved Hide resolved
clientconn.go Outdated Show resolved Hide resolved
clientconn.go Show resolved Hide resolved
clientconn.go Outdated Show resolved Hide resolved
service_config.go Outdated Show resolved Hide resolved
@lyuxuan lyuxuan merged commit ea5e6da into grpc:master Apr 3, 2019
@dfawley dfawley added the Type: Feature New features or improvements in behavior label Apr 4, 2019
@dfawley dfawley added this to the 1.20 Release milestone Apr 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 1, 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.

4 participants