-
Notifications
You must be signed in to change notification settings - Fork 309
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
New configurable/overridable kernel ZMQ+Websocket connection API #1047
Conversation
Notes from today's discussion
|
625866a
to
af672cd
Compare
5f8d2f3
to
bfc4153
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1047 +/- ##
==========================================
- Coverage 76.28% 75.90% -0.39%
==========================================
Files 63 68 +5
Lines 8228 8305 +77
Branches 1637 1655 +18
==========================================
+ Hits 6277 6304 +27
- Misses 1546 1605 +59
+ Partials 405 396 -9 ☔ View full report in Codecov by Sentry. |
The macos failures are unrelated, I'll make them more robust in #1069. There are a number of typing failures though. |
2650341
to
4f520d1
Compare
4f520d1
to
f157a16
Compare
Bringing this out of draft state. I think it is ready for final review. @blink1073 do you mind taking a look over? |
Yep, I'll take a look, but probably not today. |
9c8924a
to
ea0d72c
Compare
The Jupyter Server Terminals tests are failing because of the deprecation warning on the zmqhandlers module. I can remove this warning if preferred, or update jupyter_server_terminals to import from the new location, |
Since the terminals plugin depends on 2.0, I'd say update there |
But not until after the rc is released |
Actually, it seems like we need to ignore the warning here, release the RC, release a fix in terminals, and then remove the warning ignore here. |
Okay—I've ignored the warnings here. The downstream tests will still fail because we need to update jupyter_server terminals. I've opened this PR in jupyter_server_terminals to handle the new module. If I understand correctly, we'll
|
Yep, sounds good! |
Okay, I'll cut an RC tomorrow with this. We can still target 5 Dec for the final since a lot of folks will be out of office this week. |
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.
Thanks!
I was just looking at overriding the /kernel-id/channels endpoint to do a check that the user requesting the WS was the user that owned the kernel. great timing on this abstraction piece! thank you |
shoot, I was hoping to use this with Enterprise-gateway but conflicting deps. force me to use a 1.x version of jupyter-server. Is a backport of this to 1.x possible, or does it depend on other 2.0 functionality? @Zsailer (not asking you to do the work, I can try to implement it, just wondering about the feasibility) |
Hi @bloomsa. (I am "out of the office" this week, as, I believe, is @Zsailer - just fyi.) My understanding is that this feature is intended for 2.0+. Should a backport to 1.x be considered, it must not introduce a dependency on jupyter_client 7+ (which is currently the reason EG needs to cap Server < 2) since current EG releases (<= 3.0) require jupyter_client < 7. That is, the dependency ice on which EG rests is extremely thin! 😄 I think it may make more sense to use this feature (which I agree is great!) as another impetus to getting EG 4.0 going where we plan to derive EG directly from |
@kevin-bates I appreciate the reply, especially while OOO! My use case for this is to ensure that the person trying to connect to a kernel with the |
I'm not sure how much something like this will interfere with RTC (real-time collaboration) aside from my concern about EG's precarious dependency position - so I'm more concerned about when and where than how. I think it's great that you're looking into this, but we should also keep in mind the other areas of recent activity like RTC and authorization. Unfortunately, I'm not intimately familiar with RTC or the authorization work (I apologize). I'm assuming your changes would be directed at the EG server itself, not the EG gateway client package built into ServerApp - correct? Once EG 4.0 is in place (deriving from or at least closer to |
@kevin-bates I hadn't considered the interference with RTC, good point. In the end, I was able to override the ZMQChannelsHandler method simply by making a child class off of ZMQChannelsHandler and overriding the |
Great -thanks for getting back to us @bloomsa. |
Is there an issue that tracks EG on ServerApp + RemoteProvisionner? |
@echarles - It's vaguely on the EG project roadmap but it's probably time we can open an issue or two (in EG). |
The two `WebSocketChannelsHandler` and `GatewayResourceHandler` classes are removed and their corresponding functionality is merged into the respective `KernelWebsocketHandler` and `KernelSpecResourceHandler` classes. For the `KernelSpecResourceHandler` class, this change is rather straightforward as we can simply make the existing handler check if the kernel spec manager has a `get_kernel_spec_resource` method, and if so delegate to that method instead of trying to read resources from disk. The `KernelWebsocketHandler` conversion is more complicated, though. The handling of websocket connections was generalized/extended in jupyter-server#1047 to allow the definition of a `kernel_websocket_connection_class` as an alternative to replacing the entire websocket handler. This change builds on that by converting the `GatewayWebSocketClient` class to be an instance of the kernel websocket connection class, and accordingly renames it to `GatewayWebSocketConnection`. When the gateway client is enabled, the default `kernel_websocket_connection_class` is changed to this `GatewayWebSocketConnection` class similarly to how the kernel and kernel spec manager default classes are updated.
Summary
Decouples the ZMQ socket handling logic from the websocket handler definition to enable server deployers to override this logic without forking the websocket handler.
The Problem
The logic for connecting a websocket to a kernel's set of ZMQ sockets is defined under methods in kernel's websocket handler.
This presents the following problem:
If you need to change, override, and remove logic underneath the kernel's
/api/kernels/<kernel-id>/channels
handler, you are forced to 1) fork Jupyter Server'sZMQChannelshandler
and 2) insert the forked version earlier in the list of Jupyter Server's handlers to ensure it intercepts all kernel channels requests.(This PR was inspired by some work I have been doing, experimenting with adding events and additional logging to the kernel's websocket API and found it impossible to do this without forking.)
Proposed solution
Separate the "business" logic into an overrideable, configurable class.
In other services, Jupyter Server uses a different pattern than the current websocket handler; it decouples "business" logic from the REST API handlers/definitions by defining a configurable, overrideable "manager" that follows a defined interface and handles the "business" logic underneath the REST API handlers. You can completely override the logic in the managers, as long as they follow the defined manager interface (usually an ABC).
In this PR, I've defined a new abstraction/interface called a
KernelWebsocketConnectionABC
. The interface is minimal and clearly maps to the methods in Tornado's defaultWebsocketHandler
.I've also added a base class that handles the instantiation of Jupyter Client Session objects.
Then, the default implementation, called
ZMQChannelsWebsocketConnection
includes all the methods previously found in the websocket handler.A Note on Backwards Compatibility.
Most user/deployers will not be impacted by this change.
This impacts anyone who has forked the
ZMQChannelsHandler
, but it doesn't break their fork. Presumably, anyone who has forked this handler will still inject their handler before this new API is ever called. As a result, this change would leave them unaffected, but we should recommend that they update their code to use this new API.Todo
prepare
optionalopen
asyncparent
of the kernel websocket connection object thekernel_manager
andparent.parent
themulti_kernel_manager
.ServerApp
and move toZMQChannelsWebsocketConnection