Skip to content
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

Support returning a preferred remote controller #9978

Merged
merged 13 commits into from
May 11, 2022
Merged

Support returning a preferred remote controller #9978

merged 13 commits into from
May 11, 2022

Conversation

DonJayamanne
Copy link
Contributor

@DonJayamanne DonJayamanne commented May 11, 2022

Part of #9683

Part of this PR:

  • Introduce the method selectJuptyerUri (but renamed to getSuggestedController)
  • Ensure extensions won't need to add an entry named pythonRemoteServerProvider into their package.json
  • Rename computeUri to computeServerId, that seems more meaningful as that's exactly what it is.
  • Throw an error to handle situations where server providers (3rd party extensions) cannot return the IJupyterServerUri information (this way we can display meaning full errors)
  • Changes to code to return preferred remote notebook controller (look for kernelspec name, else just fallback to the language)

Note:
The api method selectJuptyerUri described here microsoft/vscode#146942 has been renamed to getSuggestedController, as the Jupyter API doesn't select any controller, it merely returns the suggested controller for a given remote Jupyter server.
(discussed with Peng), and will update the upstream issue once this work has been completed.

@@ -1,7 +1,7 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": true, // set this to true to hide the "out" folder with the compiled JS files
"out": false, // set this to true to hide the "out" folder with the compiled JS files
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok to have, i keep setting this.

"DataScience.remoteJupyterConnectionFailedWithServer": "Failed to connect to the remote Jupyter Server {0}. Verify the server is running and reachable.",
"DataScience.remoteJupyterConnectionFailedWithServerWithError":"Failed to connect to the remote Jupyter Server {0}. Verify the server is running and reachable. ({1}).",
"DataScience.remoteJupyterConnectionFailedWithServer": "Failed to connect to the remote Jupyter Server '{0}'. Verify the server is running and reachable.",
"DataScience.remoteJupyterConnectionFailedWithServerWithError":"Failed to connect to the remote Jupyter Server '{0}'. Verify the server is running and reachable. ({1}).",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was previously displaying the baseUrl, but in the case of somethign like Azure ML, we can display the displayName (which could contain spaces), hence quoting this string.

@@ -48,7 +48,7 @@ export class JupyterServerSelectorCommand implements IDisposable {
// Find one that is the default for this remote
if (notebook) {
// Recompute the preferred controller
await this.controllerManager.computePreferredNotebookController(notebook);
await this.controllerManager.initializePreferredNotebookController(notebook);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not only computing the preferred controller, it was also setting it using the VS Code api.
I've renamed this to be more specific.
The method computePreferredNotebookController is now used to return the preferred controller without changing it.

@@ -65,7 +66,7 @@ export class JupyterConnection implements IExtensionSyncActivationService {
private async getUriFromServerId(serverId: string) {
// Since there's one server per session, don't use a resource to figure out these settings
const savedList = await this.serverUriStorage.getSavedUriList();
return savedList.find((item) => computeUriHash(item.uri) === serverId)?.uri;
return savedList.find((item) => computeServerId(item.uri) === serverId)?.uri;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed computeUriHash to be computeServerId, the implementation should not define the method name, its a server id, hence the name should reflect that.

}
} catch (ex) {
throw new RemoteJupyterServerUriProviderError(idAndHandle.id, idAndHandle.handle, ex);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw a custom error so we can handle this, e.g. possible the jupyter server is down and user can now choose to ignore this connection completely.

@@ -53,14 +61,35 @@ export class JupyterUriProviderRegistration implements IJupyterUriProviderRegist
}

private async loadOtherExtensions(): Promise<void> {
const extensionIds = new Set<string>();
this.globalMemento
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of github extensions, they can register the lazy proxy controller when a notebook opens and they register the provider with us.
When we reload vscode, we try to get the provider information, however its possible github or other extensions haven't activated yet, for such extensions we don'e need an entry in package.json for pythonRemoteServerProvider, instead we can just keep track of the extensions that own a specific provider and load and activate those extensions.

@@ -14,6 +14,9 @@ export class JupyterUriProviderWrapper implements IJupyterUriProvider {
return this.provider.id;
}
public getQuickPickEntryItems(): vscode.QuickPickItem[] {
if (!this.provider.getQuickPickEntryItems) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extensions such as github or others won't need to implement getQuickPickEntryItems (see type definition)


@captureTelemetry(Telemetry.EnterJupyterURI)
@traceDecoratorError('Failed to enter Jupyter Uri')
public async enterJupyterURI(): Promise<string | undefined> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrote this code for server picker for our own lazy controller, don't see any harm keeping this here.
Not used for now, as i didn't want to checkin the layzy proxy controller as that API could change.
Requries a bit more work to remove this hence left it, hope its ok (the plan is to make use of this in the future)

@@ -234,7 +235,7 @@ export class JupyterSession extends BaseJupyterSession {

// Create our session options using this temporary notebook and our connection info
const sessionOptions: Session.ISessionOptions = {
path: backingFile?.filePath || `${uuid()}.ipynb`, // Name has to be unique
path: backingFile?.filePath || generateBackingIPyNbFileName(this.resource), // Name has to be unique
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now all paths generate have a predictable name & we can strip out the unnecessary guff and have a meaningful and prettier display name in the kernel picker, previously we'd just display a guid.

readonly id: string;
onDidChangeHandlers?: Event<void>;
getQuickPickEntryItems?(): QuickPickItem[];
handleQuickPick?(item: QuickPickItem, backEnabled: boolean): Promise<JupyterServerUriHandle | 'back' | undefined>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extensions such as github or others won't need to implement getQuickPickEntryItems
Haven't hooked up the code to make use of this API just yet, but added this nevertheless, basically as defined here microsoft/vscode#146942

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code that uses this has a few more changes, figured i'd submit this PR without those changes as its pretty large as is.

cancelToken?: CancellationToken,
useCache?: 'useCache' | 'ignoreCache'
useCache?: 'useCache' | 'ignoreCache',
serverId?: string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new argument serverId so that we can filter out the kernels that apply to a specific remote jupyter server.
Applies to the lazy controller that spins up jupyter and then asks us to get the prefered controller (surely at that point we need to return the preferred controller specific to that jupyter server)

const isPythonNbOrInteractiveWindow = isPythonNotebook(notebookMetadata) || resourceType === 'interactive';

// Always include the interpreter in the search if we can
const preferredInterpreter =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this code from the base method, the exact same code preferredInterpreter is calculated in the calling code, hence might as well pass that into this method instead of computing this here, also remove a few dependencies.

@codecov-commenter
Copy link

codecov-commenter commented May 11, 2022

Codecov Report

Merging #9978 (0e4e290) into main (8f7f38e) will decrease coverage by 0%.
The diff coverage is 52%.

❗ Current head 0e4e290 differs from pull request most recent head ad7abf6. Consider uploading reports for the commit ad7abf6 to get more accurate results

@@         Coverage Diff          @@
##           main   #9978   +/-   ##
====================================
- Coverage    63%     63%   -1%     
====================================
  Files       208     209    +1     
  Lines      9912    9948   +36     
  Branches   1574    1591   +17     
====================================
+ Hits       6314    6323    +9     
- Misses     3090    3113   +23     
- Partials    508     512    +4     
Impacted Files Coverage Δ
src/platform/common/utils/localize.ts 98% <ø> (ø)
src/platform/errors/types.ts 77% <ø> (ø)
src/platform/api.ts 48% <38%> (-9%) ⬇️
src/platform/errors/errorHandler.ts 64% <45%> (-4%) ⬇️
...form/errors/remoteJupyterServerUriProviderError.ts 88% <88%> (ø)
...rc/platform/common/dataScienceSurveyBanner.node.ts 65% <0%> (-6%) ⬇️

@DonJayamanne DonJayamanne marked this pull request as ready for review May 11, 2022 17:03
@DonJayamanne DonJayamanne requested a review from a team as a code owner May 11, 2022 17:04
src/platform/api.ts Outdated Show resolved Hide resolved
}
if (item.connection.kernelSpec.name === kernelName) {
matchingKernelNameController = item;
} else if (item.connection.kernelSpec.language === language) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I moved over the exact match code I ran into one existing error case where the kernelspec language didn't match up with the notebook language_info languages due to capitalization, so maybe need a toLower check here? Pretty sure it was for a C# file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shoot, I thought I had a translation code, will use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function that you can use to translate from kenel to monaco language is translateKernelLanguageToMonaco
Here it doesn't apply as we're only dealing with languages of kernelspecs & no language components from VS Code (monaco).

Copy link
Member

@IanMatthewHuff IanMatthewHuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small comments, but looks good to me.

@DonJayamanne DonJayamanne merged commit 38caef1 into main May 11, 2022
@DonJayamanne DonJayamanne deleted the issue9683 branch May 11, 2022 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants