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

Allow adding ClientInterceptors to specific services and methods #2113

Merged
merged 7 commits into from
Nov 15, 2024

Conversation

gjcairo
Copy link
Collaborator

@gjcairo gjcairo commented Nov 13, 2024

Motivation

We want to allow users to customise the RPCs a registered interceptor should apply to on the client:

  • Intercept all requests
  • Intercept requests only meant for specific services
  • Intercept requests only meant for specific methods

Modifications

This PR adds a new ClientInterceptorPipelineOperation type that allows users to specify what the target of the interceptor should be.
Existing APIs accepting [any ClientInterceptor] have been kept, but new initialisers taking [ClientInterceptorPipelineOperation] instead have been added.

Result

Users can have more control over to which requests interceptors are applied.

@gjcairo gjcairo added the ⚠️ semver/major Breaks existing public API. label Nov 13, 2024
@gjcairo gjcairo requested a review from glbrntt November 13, 2024 16:51
///
/// The order in which interceptors are added reflects the order in which they are called. The
/// first interceptor added will be the first interceptor to intercept each request. The last
/// interceptor added will be the final interceptor to intercept each request before calling
/// the appropriate handler.
private let interceptors: [any ClientInterceptor]
private let interceptorsPerMethod: Mutex<[MethodDescriptor: [any ClientInterceptor]]>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought this caching could be useful to speed things up, similar to what we do in the RPCRouter on the server. However I wonder if we care more about the client not taking up too much space (which could be the case if it calls many methods and this dictionary grows a lot).

@gjcairo gjcairo requested a review from glbrntt November 15, 2024 09:23
@gjcairo gjcairo requested a review from glbrntt November 15, 2024 10:11
@glbrntt glbrntt enabled auto-merge (squash) November 15, 2024 10:29
@gjcairo gjcairo force-pushed the service-specific-client-interceptors branch from 0329e42 to 2bf4d02 Compare November 15, 2024 10:59
@glbrntt glbrntt merged commit e160fd0 into grpc:main Nov 15, 2024
43 of 45 checks passed
@gjcairo gjcairo deleted the service-specific-client-interceptors branch November 15, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ semver/major Breaks existing public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants