-
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
service config: default service config #2686
Conversation
// 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 { |
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.
As mentioned over GVC, could we add a link or some documentation describing what this string should look like?
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.
WIP to export a doc about canonical service config json string.
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.
Ack
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.
LGTM but I'll leave approval to someone more knowledgeable.
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) |
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 will be called every time handleServiceConfig
is called
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
clientconn.go
Outdated
if err != nil { | ||
return err | ||
} | ||
sc = &scfg |
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.
return pointer from parseServiceConfig
?
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
dialoptions.go
Outdated
disableHealthCheck bool | ||
healthCheckFunc internal.HealthChecker | ||
defaultServiceConfig *ServiceConfig | ||
defaultServiceConfigRaw string |
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.
Add a field to ServiceConfig
for the raw js string.
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
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) |
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.
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.
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.
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.
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.
Per offline discussion, we will check the validity of the default service config in DialContext
. If it is not valid, the Dial will fail.
b44a9c0
to
9fab3e0
Compare
No description provided.