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

Possibility to define grpc-timeout dynamically without interacting directly with GrpcCallContext #2321

Open
dominity opened this issue Mar 6, 2023 · 1 comment
Assignees
Labels
api: spanner Issues related to the googleapis/java-spanner API.

Comments

@dominity
Copy link

dominity commented Mar 6, 2023

Thanks for stopping by to let us know something could be better!

Is your feature request related to a problem? Please describe.
My current system receives request from other system which defines deadline/finishby timeout which varies from request type to request type.
I'd like to instruct spanner client to propagate this value to spanner using 'grpc-timeout' header.
Currently it's possible to do this interacting directly with GrpcCallContext via SpannerOptions.CallContextConfigurator.
It would be great to have it as part of SpannerStubSettings, so I don't need to provide my own implementation of SpannerOptions.CallContextConfigurator and attach it to GrpcContext each time it's needed.

Describe the solution you'd like
Not sure of what would be the best approach here. I have one idea in mind:
SpannerStubSettings.Builder already contains method applyToAllUnaryMethods(...).
But it's invoked once when settings are build.
applyDynamicallyToAllUnaryMethods(ApiFunction f) method could be introduced which causes invocation of provided ApiFunction on each method invocation (or limit it to specific methods only to move it to UnaryCallSettings level).

Describe alternatives you've considered
Currently my system interact with GrpcCallContext directly via SpannerOptions.CallContextConfigurator:

    public static class SpannerGrpcCallContextConfigurator implements SpannerOptions.CallContextConfigurator {
        public <ReqT, RespT> ApiCallContext configure(ApiCallContext context, ReqT request,
                MethodDescriptor<ReqT, RespT> method) {
            if (method == SpannerGrpc.getStreamingReadMethod()) {
                 return GrpcCallContext.createDefault().withCallOptions(CallOptions.DEFAULT.withDeadlineAfter(/*some deadline*/));            
            }
            return null;
        }
    }

then spanner invocation is wrapped with custom grpc context:

        Context.current()
                .withValue(SpannerOptions.CALL_CONTEXT_CONFIGURATOR_KEY, new SpannerGrpcCallContextConfigurator())
                .run(() -> { /* spanner invocation here */ });
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Mar 6, 2023
@ansh0l ansh0l assigned gauravpurohit06 and unassigned ansh0l Mar 8, 2023
@rahul2393
Copy link
Contributor

@arpan14 can you please help triage?

@arpan14 arpan14 assigned rahul2393 and unassigned arpan14 Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API.
Projects
None yet
Development

No branches or pull requests

5 participants