-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Add ClientTransportFilter #10646
Add ClientTransportFilter #10646
Conversation
dc9592d
to
a40996c
Compare
* to modify the channels or transport life-cycle event behavior, but they can be useful hooks | ||
* for transport observability. Multiple filters may be registered to the client. | ||
*/ | ||
@ExperimentalApi("https://gitub.com/grpc/grpc-java/issues/TODO") |
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.
👋 @ejona86 any update on this PR? is this still on track for v61 release? |
Sorry I went silent on this. I had been hoping to sneak it into 1.60 but then issues with the release cropped up that ended up taking a lot of my time. (I actually didn't see your comment two days ago either...) We discussed in our API review and the general verdict was "make it a filter like on server-side." Having it just be a hook caused a whole slew of naming/identity/purpose crises that are all solved by mirroring the existing server-side API. Before my time evaporated I was going to actually make the necessary plumbing change... The listener could receive and return Attributes, just like is done on server-side. In OkHttpClientTransport, BinderTransport, InProcessTransport, CronetClientTransport look to be pretty easy to support (some places attributes would no longer be final; that's okay). NettyClientHandler could pass the Attributes through ClientTransportLifecycleManager.nofiyReady() and update the attributes on return. But I think that would be inherently racy, in a way not present on server-side. So instead of adding Attributes to transportReady(), let's add a new method to ManagedClientTransport.Listener just to do this filtering. It can be called just before transportReady(). With a default implementation that just echos back the same attributes, I hope there's not even many tests that have to be updated. |
(FYI, the branch cut for 1.61 is a week earlier than normal, or maybe a bit more. So it is coming up soon. I'd be fine backporting this to the release, even though it is technically a feature, if we can do so at least a week before the release. If there's any bugs, seem they should only impact you and not destabilize others.) |
Thanks for getting back to me! I addressed these suggestions, ptal and let me know if i understood you correctly. As for backporting this to 1.61, I think we're fine with waiting for 1.62 if you folks are at all worried about the risk. Thanks again! |
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 looks good to me, other than some nits.
binder/src/main/java/io/grpc/binder/internal/BinderTransport.java
Outdated
Show resolved
Hide resolved
core/src/test/java/io/grpc/internal/InternalSubchannelTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Eric Anderson <ejona@google.com>
Co-authored-by: Eric Anderson <ejona@google.com>
Co-authored-by: Eric Anderson <ejona@google.com>
Co-authored-by: Eric Anderson <ejona@google.com>
binder/src/main/java/io/grpc/binder/internal/BinderTransport.java
Outdated
Show resolved
Hide resolved
|
Note to build the android related classes (which is what is catching this),
use `-PskipAndroid=false`
…On Tue, Dec 26, 2023 at 3:17 PM Sergii Tkachenko ***@***.***> wrote:
/tmpfs/src/github/grpc-java/cronet/src/main/java/io/grpc/cronet/CronetClientTransport.java:172: error: cannot assign a value to final variable attrs
attrs = CronetClientTransport.this.listener.filterTransport(attrs);
^
—
Reply to this email directly, view it on GitHub
<#10646 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZQMCXWTIFHPVHQX77ROTVLYLNLHPAVCNFSM6AAAAAA64ZPITOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRZHAYTMMZWGM>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
@joybestourous The builds failed because of For example:
|
Thanks for bringing this to completion 🙏 sorry I missed these errors my android setup was not working properly. |
No Problem. Thanks for creating this and taking care of all of the other
issues.
…On Wed, Jan 3, 2024 at 11:20 AM joybestourous ***@***.***> wrote:
@joybestourous <https://github.com/joybestourous> The builds failed
because of CronetClientTransportTest. That test uses a mock for
clientTransportListener which by default returns null for all of the
methods. You will need to put a when clause into setUp() so that
clientTransportListener.filterTransport(attr) just returns its argument.
For example:
when(clientTransportListener.filterTransport(any()).thenAnswer(i -> i.getArguments()[0])
Thanks for bringing this to completion 🙏 sorry I missed these errors my
android setup was not working properly.
—
Reply to this email directly, view it on GitHub
<#10646 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZQMCXR3L3PK45TYNWWB66TYMWVQRAVCNFSM6AAAAAA64ZPITOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZVHA2TANRZGU>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
#10805 is suspicious, and shouldn't be necessary. I feel like there's no harm happening at present with making the field volatile, but the fact TSAN is finding issues makes clear something is happening that we don't expect. So we aren't going to backport this into the 1.61 release. We'll probably try to remove the volatile before 1.62, but even if we don't, at that point it will have seen enough testing that we are then more confident it won't cause an issue. |
Oh hm that's super surprising / suspicious. Makes complete sense to put this in 1.62. Thanks for the heads up! |
Problem
We're trying to add some stats on the number of connections opened, closed, and active on the client side for grpc-java. On the server side, ServerTransportFilter acts as a reasonable hook for this, but there doesn't seem to be anything comparable on the client side that I can find (if there is, please direct me to it!).
Closes #10647
Solution
Add a ClientTransportFilter. Similarly to ServerTransportFilter this will provide an observability hook and allows direct modification of the transport's attributes.
To wire this in, this PR also adds a
filterTransport
method toManagedClientTransport.Listener
which handles modifying the transport's attributes. This is called just beforetransportReady