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

Apply grpc service config from consul #1045

Closed
onyn opened this issue Jan 31, 2024 · 1 comment · Fixed by #1046
Closed

Apply grpc service config from consul #1045

onyn opened this issue Jan 31, 2024 · 1 comment · Fixed by #1046
Labels
enhancement A feature request or improvement
Milestone

Comments

@onyn
Copy link
Contributor

onyn commented Jan 31, 2024

We have DiscoveryClientNameResolver which allows to specify grpc client target like discovery:///service-name. Actual ip:port data is fetched from consul. Port also taken from gRPC_port metadata.

I suggest adding gRPC_service_config metadata key, similar to gRPC_port. Under this key grpc servers may publish service config.

This feature already present in standard DNS name resolver (details).

I already implement this in my custom name resolver and it work just fine.

On server side I specify my desired service config:

Server's application.yml
spring:
  cloud:
    consul:
      discovery:
        metadata:
          gRPC_service_config: |
            {
              "loadBalancingConfig": [
                {"round_robin": {}}
              ],
              "methodConfig": [
                {
                  "name": [{}],
                  "retryPolicy": {
                    "maxAttempts": 5,
                    "initialBackoff": "0.05s",
                    "maxBackoff": "1s",
                    "backoffMultiplier": 2,
                    "retryableStatusCodes": [
                      "UNAVAILABLE",
                      "ABORTED",
                      "DATA_LOSS",
                      "INTERNAL",
                      "DEADLINE_EXCEEDED"
                    ]
                  },
                  "timeout": "5s"
                }
              ]
            }

On client side my name resolver parse it and pass to listener:

Code sample
var result = ResolutionResult.newBuilder().setAddresses(list);
if (!serviceConfig.isEmpty()) {
    try {
        @SuppressWarnings("unchecked")
        Map<String, ?> parsed = gson.fromJson(serviceConfig, Map.class);
        result.setServiceConfig(serviceConfigParser.parseServiceConfig(parsed));
    } catch (JsonSyntaxException e) {
        result.setServiceConfig(
            ConfigOrError.fromError(
                Status.UNKNOWN
                    .withDescription("Failed to parse gRPC_service_config")
                    .withCause(e)
            )
        );
    }
}
savedListener.onResult(result.build());
@onyn onyn added the enhancement A feature request or improvement label Jan 31, 2024
@ST-DDT
Copy link
Collaborator

ST-DDT commented Feb 1, 2024

I already implement this in my custom name resolver and it work just fine.

Would you like to create a PR for that?

onyn pushed a commit to onyn/grpc-spring that referenced this issue Feb 2, 2024
onyn pushed a commit to onyn/grpc-spring that referenced this issue Mar 13, 2024
onyn pushed a commit to onyn/grpc-spring that referenced this issue Mar 26, 2024
onyn pushed a commit to onyn/grpc-spring that referenced this issue Apr 2, 2024
yidongnan added a commit that referenced this issue Apr 12, 2024
feat: apply grpc service config from consul (#1045)
@yidongnan yidongnan added this to the 3.1.0 milestone Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature request or improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants