-
Notifications
You must be signed in to change notification settings - Fork 1.1k
grpc: change the LB policy config parsing API to accept JSON values instead of String #2294
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
Conversation
/// JSON. Hides internal storage details and includes a method to deserialize | ||
/// the JSON into a concrete policy struct. | ||
#[derive(Debug)] | ||
pub struct ParsedJsonLbConfig(pub serde_json::Value); |
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.
pub struct ParsedJsonLbConfig(pub serde_json::Value); | |
pub struct ParsedJsonLbConfig(serde_json::Value); |
The idea is to encapsulate serde_json
and not expose it outside our crate.
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.
Currently the channel (in the gracefulswitch LB policy) specifies a default service config (with pick_first
as the LB policy). So, we have a few options:
- Make this field
pub(super)
so that the channel has access to this field. Also, maybe the channel would want this when it implements the service config parsing from the resolver? - Make this field
pub(crate)
if other tests end wanting to set a service config. - Have an associated function
new
that takes the input JSON as a string, and returnsResult<Self, String>
.- we could use the
serde_json::from_str
function to convert the input string into aserde_json::Value
- we could use the
What do you think?
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.
New function makes the most sense or you can even implement FromStr
, exposing the internal type to modules outside of this file is generally a bad idea. (eg you want to add a field to this struct then you need to refactor all the locations that reference the internals.
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.
Moved the value to be a struct field instead of this being a tuple struct.
Also, added a new function.
Gentle ping on this PR: @LucioFranco @dfawley |
The existing
parse_config
method on theLbPolicyBuilder
trait accepts configuration as a&str
. Passing parsed JSON to this API is better for the following reasons: