-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
interceptor: new APIs for chaining client interceptors. #2696
Conversation
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.
The interceptors will be executed in a left-to-right order
"left-to-right" is not clear to me. Instead, we should define which is the inner-most and which is outer-most.
In your tests, it seems left is assumed to be outer-most, so it both first and also last (it wraps other interceptors).
Yes the left-most interceptor passed in is the outer-most, and the right-most is the inner-most. I have updated the doc string to avoid confusion. |
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.
Overall LGTM, some minor comments.
call.go
Outdated
@@ -39,19 +39,20 @@ func (cc *ClientConn) Invoke(ctx context.Context, method string, args, reply int | |||
interceptors = append([]UnaryClientInterceptor{cc.dopts.unaryInt}, interceptors...) | |||
} | |||
|
|||
return getChainInvoker(interceptors, invoke)(ctx, method, args, reply, cc, opts...) | |||
if len(interceptors) > 0 { | |||
return interceptors[0](ctx, method, args, reply, cc, getChainInvoker(interceptors, 0, invoke), opts...) |
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.
This still re-chains the interceptors for each RPC.
Chain can done in Dial (either while specifying dial options, or after processing all dial options). Then there will be only one interceptor, and can be used by all RPCs.
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.
I see... I misunderstood it before. I have moved the chaining logic to clientconn init time.
Just a follow up, is there anything else I need to do for this PR? |
Add two new APIs in dialoptions:
WithChainUnaryInterceptor
// Chainable client unary interceptorsWithChainStreamInterceptor
// Chainable client stream interceptorsThe chaining interceptors will be appended after the original interceptor defined by
WithUnaryInterceptor
andWithStreamInterceptor
. The interceptors will be executed in a left-to-right order. e.g. For a chaining interceptors [int1, int2, int3], we will execute int1, and then int2, int3, before sending out the requests.This provides the similar functionality as https://godoc.org/github.com/grpc-ecosystem/go-grpc-middleware#hdr-Chaining
API names are TBD. Please let me know if there are better names for these two APIs. Thanks!