jupyter / kernel_gateway_demos

Demos associated with the kernel gateway incubator project
BSD 3-Clause "New" or "Revised" License
152 stars 76 forks source link

Support having different WS and HTTP urls #57

Closed snowch closed 6 years ago

snowch commented 6 years ago

nb2kg does not work when connecting to a host that has different urls for WS and HTTP, for example:

This patch allows users to specify the KG_WS_URL.

snowch commented 6 years ago

@parente that setting looks like it only allows you to set the scheme, host and port? The requirement is to be able to set the path.

parente commented 6 years ago

I'm pretty sure it allows the path too. It gets passed to the jinja template renderer here:

https://github.com/jupyter/notebook/blob/74fbc5b5784d5dbadcc66d7a78cedf029d1bb7d9/notebook/base/handlers.py#L401

populates the notebook template here:

https://github.com/jupyter/notebook/blob/5a0ee98441109156a537e3c2a59b6eaf6e8934e1/notebook/templates/notebook.html

and ultimately gets joined to a kernel path here in the JavaScript:

https://github.com/jupyter/notebook/blob/9f578dcec041aa1ad724a27afd2e26b2d79ff099/notebook/static/services/kernels/kernel.js#L461

I think that URL join should work fine even if the ws_url has a path included in it.

Can you give it a shot? If it works, we can send a PR to notebook to update the documentation of the websocket_url traitlet.

snowch commented 6 years ago

I've set the parameter NotebookApp.websocket_url:

cd /home/jovyan/work
. /usr/local/bin/start.sh jupyter notebook --debug \
     --no-browser \
     --port=$NB_PORT \
     --NotebookApp.ip=0.0.0.0 \
     --NotebookApp.websocket_url=$KG_WS_URL \
     --NotebookApp.session_manager_class=nb2kg.managers.SessionManager \
     --NotebookApp.kernel_manager_class=nb2kg.managers.RemoteKernelManager \
     --NotebookApp.kernel_spec_manager_class=nb2kg.managers.RemoteKernelSpecManager 2>&1

However, I only see http calls in the log output, no ws calls.

To enable me to debug this further, is it possible to switch on http/ws trace debugging so the log output shows the actual http/ws requests and responses?

Update: I found out that I can debug the ws calls in the browser in a notebook session.

snowch commented 6 years ago

I've identified some differences in the behavoir ...

This works:

This doesn't work:

 

parente commented 6 years ago

@snowch Merging your original since clearly the alternative doesn't do what I think it did. Thanks for experimenting with the command line parameter and your patience.

snowch commented 6 years ago

Thanks, @parente! No worries - it was a really useful adventure into the jupyter source code for me. The code is starting to feel familiar which is nice :)