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

Add configurable session timeouts for supervisor #5693

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion extensions/positron-supervisor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"default": false,
"description": "%configuration.showTerminal.description%"
},
"positronKernelSupervisor.connectionTimeout": {
"type": "integer",
"default": 30,
"description": "%configuration.connectionTimeout.description%"
},
"positronKernelSupervisor.logLevel": {
"scope": "window",
"type": "string",
Expand Down Expand Up @@ -97,7 +102,7 @@
},
"positron": {
"binaryDependencies": {
"kallichore": "0.1.21"
"kallichore": "0.1.22"
}
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions extensions/positron-supervisor/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"configuration.logLevel.description": "Log level for the kernel supervisor (restart Positron to apply)",
"configuration.enable.description": "Run Jupyter kernels under the Positron kernel supervisor.",
"configuration.showTerminal.description": "Show the host terminal for the Positron kernel supervisor",
"configuration.connectionTimeout.description": "Timeout in seconds for connecting to the kernel's sockets",
"configuration.attachOnStartup.description": "Run <f5> before starting up Jupyter kernel (when supported)",
"configuration.sleepOnStartup.description": "Sleep for n seconds before starting up Jupyter kernel (when supported)",
"command.positron.supervisor.category": "Kernel Supervisor",
Expand Down
4 changes: 3 additions & 1 deletion extensions/positron-supervisor/src/KallichoreSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class KallichoreSession implements JupyterLanguageRuntimeSession {
const config = vscode.workspace.getConfiguration('positronKernelSupervisor');
const attachOnStartup = config.get('attachOnStartup', false) && this._extra?.attachOnStartup;
const sleepOnStartup = config.get('sleepOnStartup', undefined) && this._extra?.sleepOnStartup;
const connectionTimeout = config.get('connectionTimeout', 30);
if (attachOnStartup) {
this._extra!.attachOnStartup!.init(args);
}
Expand All @@ -273,7 +274,8 @@ export class KallichoreSession implements JupyterLanguageRuntimeSession {
env,
workingDirectory: workingDir,
username: os.userInfo().username,
interruptMode
interruptMode,
connectionTimeout,
};
await this._api.newSession(session);
this.log(`${kernelSpec.display_name} session '${this.metadata.sessionId}' created in ${workingDir} with command:`, vscode.LogLevel.Info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ api/apis.ts
api/defaultApi.ts
git_push.sh
model/activeSession.ts
model/adoptedSession.ts
model/connectionInfo.ts
model/executionQueue.ts
model/interruptMode.ts
model/modelError.ts
Expand Down
70 changes: 70 additions & 0 deletions extensions/positron-supervisor/src/kcclient/api/defaultApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import http from 'http';

/* tslint:disable:no-unused-locals */
import { ActiveSession } from '../model/activeSession';
import { AdoptedSession } from '../model/adoptedSession';
import { ModelError } from '../model/modelError';
import { NewSession } from '../model/newSession';
import { NewSession200Response } from '../model/newSession200Response';
Expand Down Expand Up @@ -98,6 +99,75 @@ export class DefaultApi {
this.interceptors.push(interceptor);
}

/**
*
* @summary Adopt an existing session
* @param adoptedSession
*/
public async adoptSession (adoptedSession: AdoptedSession, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.IncomingMessage; body: NewSession200Response; }> {
const localVarPath = this.basePath + '/sessions/adopt';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams.Accept = 'application/json';
} else {
localVarHeaderParams.Accept = produces.join(',');
}
let localVarFormParams: any = {};

// verify required parameter 'adoptedSession' is not null or undefined
if (adoptedSession === null || adoptedSession === undefined) {
throw new Error('Required parameter adoptedSession was null or undefined when calling adoptSession.');
}

(<any>Object).assign(localVarHeaderParams, options.headers);

let localVarUseFormData = false;

let localVarRequestOptions: localVarRequest.Options = {
method: 'PUT',
qs: localVarQueryParameters,
headers: localVarHeaderParams,
uri: localVarPath,
useQuerystring: this._useQuerystring,
json: true,
body: ObjectSerializer.serialize(adoptedSession, "AdoptedSession")
};

let authenticationPromise = Promise.resolve();
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));

let interceptorPromise = authenticationPromise;
for (const interceptor of this.interceptors) {
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
}

return interceptorPromise.then(() => {
if (Object.keys(localVarFormParams).length) {
if (localVarUseFormData) {
(<any>localVarRequestOptions).formData = localVarFormParams;
} else {
localVarRequestOptions.form = localVarFormParams;
}
}
return new Promise<{ response: http.IncomingMessage; body: NewSession200Response; }>((resolve, reject) => {
localVarRequest(localVarRequestOptions, (error, response, body) => {
if (error) {
reject(error);
} else {
if (response.statusCode && response.statusCode >= 200 && response.statusCode <= 299) {
body = ObjectSerializer.deserialize(body, "NewSession200Response");
resolve({ response: response, body: body });
} else {
reject(new HttpError(response, body, response.statusCode));
}
}
});
});
});
}
/**
*
* @summary Upgrade to a WebSocket for channel communication
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Kallichore API
* Kallichore is a Jupyter kernel gateway and supervisor
*
* The version of the OpenAPI document: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

import { RequestFile } from './models';
import { ConnectionInfo } from './connectionInfo';
import { NewSession } from './newSession';

/**
* The session to adopt
*/
export class AdoptedSession {
'session': NewSession;
'connectionInfo': ConnectionInfo;

static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "session",
"baseName": "session",
"type": "NewSession"
},
{
"name": "connectionInfo",
"baseName": "connection_info",
"type": "ConnectionInfo"
} ];

static getAttributeTypeMap() {
return AdoptedSession.attributeTypeMap;
}
}

109 changes: 109 additions & 0 deletions extensions/positron-supervisor/src/kcclient/model/connectionInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* Kallichore API
* Kallichore is a Jupyter kernel gateway and supervisor
*
* The version of the OpenAPI document: 1.0.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

import { RequestFile } from './models';

/**
* Connection information for an existing session
*/
export class ConnectionInfo {
/**
* The port for control messages
*/
'controlPort': number;
/**
* The port for shell messages
*/
'shellPort': number;
/**
* The port for stdin messages
*/
'stdinPort': number;
/**
* The port for heartbeat messages
*/
'hbPort': number;
/**
* The port for IOPub messages
*/
'iopubPort': number;
/**
* The signature scheme for messages
*/
'signatureScheme': string;
/**
* The key for messages
*/
'key': string;
/**
* The transport protocol
*/
'transport': string;
/**
* The IP address for the connection
*/
'ip': string;

static discriminator: string | undefined = undefined;

static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
{
"name": "controlPort",
"baseName": "control_port",
"type": "number"
},
{
"name": "shellPort",
"baseName": "shell_port",
"type": "number"
},
{
"name": "stdinPort",
"baseName": "stdin_port",
"type": "number"
},
{
"name": "hbPort",
"baseName": "hb_port",
"type": "number"
},
{
"name": "iopubPort",
"baseName": "iopub_port",
"type": "number"
},
{
"name": "signatureScheme",
"baseName": "signature_scheme",
"type": "string"
},
{
"name": "key",
"baseName": "key",
"type": "string"
},
{
"name": "transport",
"baseName": "transport",
"type": "string"
},
{
"name": "ip",
"baseName": "ip",
"type": "string"
} ];

static getAttributeTypeMap() {
return ConnectionInfo.attributeTypeMap;
}
}

6 changes: 6 additions & 0 deletions extensions/positron-supervisor/src/kcclient/model/models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import localVarRequest from 'request';

export * from './activeSession';
export * from './adoptedSession';
export * from './connectionInfo';
export * from './executionQueue';
export * from './interruptMode';
export * from './modelError';
Expand All @@ -25,6 +27,8 @@ export type RequestFile = string | Buffer | fs.ReadStream | RequestDetailedFile;


import { ActiveSession } from './activeSession';
import { AdoptedSession } from './adoptedSession';
import { ConnectionInfo } from './connectionInfo';
import { ExecutionQueue } from './executionQueue';
import { InterruptMode } from './interruptMode';
import { ModelError } from './modelError';
Expand Down Expand Up @@ -54,6 +58,8 @@ let enumsMap: {[index: string]: any} = {

let typeMap: {[index: string]: any} = {
"ActiveSession": ActiveSession,
"AdoptedSession": AdoptedSession,
"ConnectionInfo": ConnectionInfo,
"ExecutionQueue": ExecutionQueue,
"ModelError": ModelError,
"NewSession": NewSession,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export class NewSession {
* Environment variables to set for the session
*/
'env': { [key: string]: string; };
/**
* The number of seconds to wait for a connection to the session\'s ZeroMQ sockets before timing out
*/
'connectionTimeout'?: number = 30;
'interruptMode': InterruptMode;

static discriminator: string | undefined = undefined;
Expand Down Expand Up @@ -100,6 +104,11 @@ export class NewSession {
"baseName": "env",
"type": "{ [key: string]: string; }"
},
{
"name": "connectionTimeout",
"baseName": "connection_timeout",
"type": "number"
},
{
"name": "interruptMode",
"baseName": "interrupt_mode",
Expand Down
Loading