Skip to content

Implement/service config#2731

Open
nathanielford wants to merge 5 commits into
grpc:masterfrom
nathanielford:implement/ServiceConfig
Open

Implement/service config#2731
nathanielford wants to merge 5 commits into
grpc:masterfrom
nathanielford:implement/ServiceConfig

Conversation

@nathanielford

Copy link
Copy Markdown
Contributor

Motivation

ServiceConfig requires an internal representation that we can de/serialize.

Solution

This CL implements the ServiceConfig struct and necessary plumbing for de/serialization. In a follow-on CL(s) we will be adding the plumbing to fully utilize the ServiceConfig, including adding the option to the Channel builde, passing it to the load balancer tree for utilization, and interactions with the Name Resolver.

@nathanielford
nathanielford force-pushed the implement/ServiceConfig branch from 29c707f to 52589c3 Compare July 13, 2026 21:32
@nathanielford
nathanielford requested a review from dfawley July 13, 2026 21:43
@nathanielford
nathanielford marked this pull request as ready for review July 13, 2026 21:43
Comment thread grpc/src/client/service_config/json.rs Outdated
Comment thread grpc/src/client/service_config/json.rs Outdated
use serde::Deserialize;
use std::time::Duration;

// See [service config format notes](https://protobuf.dev/reference/protobuf/google.protobuf/#duration)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The link text here may be misleading. The link itself is to the proto duration parsing page, not service config notes.

Also, without triple slashes, I don't think this ever renders as a link anyway? (Probably should triple-slash this?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed the language here - LMK what you think.

Comment thread grpc/src/client/service_config/json.rs
Comment thread grpc/src/client/service_config/json.rs Outdated
Comment thread grpc/src/client/service_config/json.rs Outdated
Comment thread grpc/src/client/service_config/json.rs Outdated
.transpose()
}

// This included to allow deserializing both u32 and string (or "stringified")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we supporting stringified numbers? Is that a requirement?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I read the spec as requiring it, but re-reading it I think there are multiple ways to parse it. In any event, it appears that Golang does not support stringification, but Java and C++ do:

Java:

C++:

I think in the original design it deferred to the C++ implementation. Let me know if you want to pull this, however, and we can only accept pure numbers.

Comment thread grpc/src/client/service_config/mod.rs Outdated

impl ServiceConfig {
/// Parses a service configuration from a JSON string.
pub fn parse(config_json: &str) -> Result<Self, String> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe we might want a service_config::ParseResult type here that is Result<ServiceConfig, String>, for newtype reasons. The name resolve will be passing the full ParseResult to the channel.

(Go reference: https://pkg.go.dev/google.golang.org/grpc@v1.82.1/serviceconfig#ParseResult + passed to channel with https://pkg.go.dev/google.golang.org/grpc/resolver#State)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've gone ahead and implemented this. We didn't talk about it in the design stage, but it seems like a good idea. That said, take a look and let me know if that fits properly.

Comment thread grpc/src/client/channel.rs
Comment thread grpc/src/client/channel.rs
Comment thread grpc/src/inmemory/mod.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants