-
Notifications
You must be signed in to change notification settings - Fork 310
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
Don't assume that resources entries are relative #1182
Conversation
Starting with the 2.0.2 release of jupyter_server, every entry in the `resources` field of a kernelspec reported by the kernel gateway is assumed to be a path relative to the kernel gateway URL starting with `/kernelspecs`). However, this assumption is not documented anywhere in the REST API doc, and I have a kernel gateway server that uses the resources object to report additional URLs that are not relative to `/kernelspecs/`. With that combination, any attempts to use this kernel gateway with a version newer than 2.0.2 results in the following failure trace: ``` Traceback (most recent call last): File "/home/ojarjur/.local/lib/python3.9/site-packages/tornado/web.py", line 1713, in _execute result = await result File "/home/ojarjur/.local/lib/python3.9/site-packages/jupyter_server/services/kernelspecs/handlers.py", line 70, in get kspecs = await ensure_async(ksm.get_all_specs()) File "/home/ojarjur/.local/lib/python3.9/site-packages/jupyter_core/utils/__init__.py", line 184, in ensure_async result = await obj File "/home/ojarjur/.local/lib/python3.9/site-packages/jupyter_server/gateway/managers.py", line 243, in get_all_specs fetched_kspecs = await self.list_kernel_specs() File "/home/ojarjur/.local/lib/python3.9/site-packages/jupyter_server/gateway/managers.py", line 267, in list_kernel_specs kernel_specs = self._replace_path_kernelspec_resources(kernel_specs) File "/home/ojarjur/.local/lib/python3.9/site-packages/jupyter_server/gateway/managers.py", line 221, in _replace_path_kernelspec_resources new_path = url_path_join(self.parent.base_url, "kernelspecs", split_eg_base_url[1]) IndexError: list index out of range ``` This change tries to remove that assumption by checking whether or not the string split actually resulted in a list of more than one element.
This change extends the mock kernelspec used for testing the gateway client logic so that it includes one entry in the `resources` object that is not a local file path relative to the `/kernelspecs/` directory. Adding that change is sufficient to make the tests fail with the previous version of the code and to demonstrate that the change in this PR fixes them.
Thanks for submitting your first pull request! You are awesome! 🤗 |
for more information, see https://pre-commit.ci
Codecov ReportBase: 80.13% // Head: 80.14% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1182 +/- ##
==========================================
+ Coverage 80.13% 80.14% +0.01%
==========================================
Files 68 68
Lines 8149 8150 +1
Branches 1604 1605 +1
==========================================
+ Hits 6530 6532 +2
Misses 1191 1191
+ Partials 428 427 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Starting with #1124 (released in 2.0.2) an issue was resolved whereby if the notebook server (client to gateway) is started with a Since I've been working on Jupyter (6 years now), every entry in the resources stanza, of which there can be multiple, is a key/value pair with the key being the resource name and the value being the url path to the resource so the appropriate handler is called.
You're right, the API doc doesn't get down to this level of detail.[*]
Do these kinds of I think the better location for this particular entry is in the more free-form [*] Please note that should we decide to better document the REST API, we cc: @bloomsa |
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 @ojarjur - thank you. We can talk about documenting the API and such another time (perhaps this week's server meeting?).
Hi @ojarjur. I'd like to apologize for my tone in yesterday's response as it may have come across as defensive and a bit agitated. I'm sorry. Regarding the customization, sans official documentation, I think precedent says a lot and I don't think there have really been changes to the kernelspec model returned from servers (notebook or gateway), at least in the last 6 years. I can't guarantee that applications that need to interpret that content won't break when new items are encountered - thus the emphasis to use the |
@kevin-bates Thank you for your rapid and thoughtful feedback!
I definitely want to join that meeting, but I have a personal conflict during it, so I don't know if/when I'll be able to join. Thanks for making sure that I am aware of it, though.
I did not pick up on anything like that, but I really appreciate how proactive you are about it.
That makes perfect sense.
I appreciate that context. I'm also happy to get feedback on better ways for me to use the API, so thank you for that.
I haven't seen any issues with Jupyter Lab arising from this. To be clear, though; I've only tried this for new entries in the So, for example, I have not tried it to see what would happen if I set one of the logo entries so that the logo was loaded from a CDN instead of the Jupyter server. That seems like something someone might want to do, but if it hasn't come up in the past 6 years then maybe I'm wrong about that.
Thanks! I really appreciate any guidance you are willing to share here. To clarify, you are not referencing an existing stanza, right (I couldn't find a reference to that in the API docs)? I.E. is the suggestion to have my server return an additional
By this, you mean something like add an object to the top level of the ... so, an example kernelspec might look like:
Do we have any tests that exercise additional fields being passed through the server? If not, I might be able to add such in a future PR, but would need guidance on the right place to put them. |
Oh, shoot. It slipped my mind that Is this information something that is relatively static and could be persisted in the I hesitate to recommend injecting into the
I haven't dug into how Lab uses the entries in the resources stanza. They may only look for I will try to bring this topic up in tomorrow's meeting and let you know. |
@kevin-bates Thanks again for all of your insights here. Can you share a link to what you are referring to? I've been looking at the Swagger API spec here, but it seems that is missing the things you are referring to. Have I been looking in the wrong place? Regardless, this is a bit of a tangent from the original PR. What do we (I?) need to do next to close that out? Does this require discussion at the server meeting tomorrow or review from someone else? Thanks again for all of your feedback and discussion here. |
Yeah, the swagger doc is not very detailed. The location of where the The The Jupyter Client docs have a section on kernelspecs in which the metadata field is listed. Since you're using EG, this is where the |
Hi @ojarjur. We discussed this in today's server meeting and feel the best/safest course of action is to use the |
@blink1073 - I think this is ready to merge but I wanted to get your opinion on the build failure as I suspect it is unrelated to the PR. Appears to be something amiss with |
I've been seeing that failure intermittently on other PRs. |
Thank you @kevin-bates and @blink1073 thanks for all of your feedback and help here! |
Starting with the 2.0.2 release of jupyter_server, every entry in the
resources
field of a kernelspec reported by the kernel gateway is assumed to be a path relative to the kernel gateway URL starting with/kernelspecs
).However, this assumption is not documented anywhere in the REST API doc (as far as I can tell), and I have a kernel gateway server that uses the resources object to report additional URLs that are not relative to
/kernelspecs/
.With that combination, any attempts to use this kernel gateway with a version newer than 2.0.2 results in the following failure trace:
This change tries to remove that assumption by checking whether or not the string split actually resulted in a list of more than one element.