forked from jupyter-server/jupyter_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UI to show a kernel's info (jupyter-server#340)
* add a kernel info section to the advanced tools section * add process/Pod ID to kernel info * UI: kernel info item components * rename to process id to pod id in kernel_info UI * relax testing thresholds in UI
- Loading branch information
Showing
6 changed files
with
196 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
A JupyterLab plugin that renders a panel in the "Cell Tools" --> "Advanced Tools" | ||
tab showing information about the kernel, i.e. session_id, kernel_id, process_id, etc. | ||
*/ | ||
import * as React from 'react'; | ||
|
||
import { | ||
JupyterFrontEnd, | ||
JupyterFrontEndPlugin | ||
} from '@jupyterlab/application'; | ||
|
||
import { | ||
INotebookTools, | ||
INotebookTracker, | ||
NotebookTools | ||
} from '@jupyterlab/notebook'; | ||
import { ReactWidget } from '@jupyterlab/apputils'; | ||
import { PanelLayout } from '@lumino/widgets'; | ||
import { Message } from '@lumino/messaging'; | ||
import { getSessionModel } from '@jupyterlab/services/lib/session/restapi'; | ||
|
||
export interface IKernelSessionItem { | ||
label: string; | ||
value: string; | ||
} | ||
|
||
const KernelInfoListItem = (props: IKernelSessionItem) => { | ||
return ( | ||
<div id="list-item"> | ||
<b>{props.label}:</b> {props.value} | ||
</div> | ||
); | ||
}; | ||
|
||
export interface IKernelSessionInfo { | ||
session_id: string; | ||
kernel_id: string; | ||
process_id: string; | ||
} | ||
|
||
/** | ||
* A kernel session info panel element. | ||
*/ | ||
const KernelSessionInfo = (props: IKernelSessionInfo) => { | ||
let content: JSX.Element; | ||
|
||
content = ( | ||
<div> | ||
<div id="title">Kernel session info</div> | ||
<KernelInfoListItem label={'Session ID'} value={props.session_id} /> | ||
<KernelInfoListItem label="Kernel ID" value={props.kernel_id} /> | ||
<KernelInfoListItem label="Pod ID" value={props.process_id} /> | ||
</div> | ||
); | ||
return content; | ||
}; | ||
|
||
export class KernelSessionInfoWidget extends ReactWidget { | ||
/** | ||
* Render the react content for the widget. | ||
*/ | ||
setState(status: IKernelSessionInfo) { | ||
this._kernel_id = status.kernel_id; | ||
this._session_id = status.session_id; | ||
this._process_id = status.process_id; | ||
this.update(); | ||
} | ||
|
||
protected render(): JSX.Element { | ||
return ( | ||
<KernelSessionInfo | ||
session_id={this._session_id} | ||
kernel_id={this._kernel_id} | ||
process_id={this._process_id} | ||
/> | ||
); | ||
} | ||
|
||
private _session_id = ''; | ||
private _kernel_id = ''; | ||
private _process_id = ''; | ||
} | ||
|
||
export class KernelInfoTool extends NotebookTools.Tool { | ||
public tracker: INotebookTracker; | ||
|
||
constructor(tracker: INotebookTracker, app: JupyterFrontEnd) { | ||
super(); | ||
app; | ||
this.tracker = tracker; | ||
this.layout = new PanelLayout(); | ||
} | ||
|
||
async _update() { | ||
/* | ||
Fetch the kernel session info from the | ||
`/api/kernel_session_info` endpoint | ||
*/ | ||
const kernel_info = await this.getInfo(); | ||
const widget = new KernelSessionInfoWidget(); | ||
widget.setState(kernel_info); | ||
/* | ||
Clear any previous panels so that we don't | ||
get duplicate subpanels. | ||
*/ | ||
const layout = this.layout as PanelLayout; | ||
const count = layout.widgets.length; | ||
for (let i = 0; i < count; i++) { | ||
layout.widgets[i].dispose(); | ||
} | ||
/* | ||
Update the panel with the latest view. | ||
*/ | ||
layout.addWidget(widget); | ||
} | ||
|
||
protected onActiveNotebookPanelChanged(msg: Message): void { | ||
/* Adds a panel with the notebook panel is opened or changed. */ | ||
this._update(); | ||
/* If the session changes or the connection status changes, update this panel. */ | ||
this.tracker.currentWidget?.sessionContext.sessionChanged.connect( | ||
async () => { | ||
await this._update(); | ||
} | ||
); | ||
this.tracker.currentWidget?.sessionContext.connectionStatusChanged.connect( | ||
async () => { | ||
await this._update(); | ||
} | ||
); | ||
} | ||
|
||
async getInfo() { | ||
// Only fetch the info if we have a session. | ||
let sessionContext = this.tracker.currentWidget?.sessionContext; | ||
if (sessionContext && sessionContext.session) { | ||
/* | ||
Fetch the kernel session info from the | ||
`/api/kernel_session_info` endpoint | ||
*/ | ||
let model: any = await getSessionModel(sessionContext.session.id); | ||
let kernel_session_info = { | ||
session_id: model['id'], | ||
kernel_id: model['kernel']['id'], | ||
process_id: model['kernel']['process_id'] | ||
}; | ||
return kernel_session_info; | ||
} | ||
return { | ||
session_id: 'unknown', | ||
kernel_id: 'unknown', | ||
process_id: 'unknown' | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Initialization data for the celltags extension. | ||
*/ | ||
export const KernelInfoPlugin: JupyterFrontEndPlugin<void> = { | ||
id: 'data_studio:kernel_info_plugin', | ||
autoStart: true, | ||
requires: [INotebookTools, INotebookTracker], | ||
activate: ( | ||
app: JupyterFrontEnd, | ||
tools: INotebookTools, | ||
tracker: INotebookTracker | ||
) => { | ||
console.log('JupyterLab extension "Kernel Info" is activated!'); | ||
const tool = new KernelInfoTool(tracker, app); | ||
tool.addClass('ds-KernelSessionInfoWidget'); | ||
tools.addItem({ tool: tool, section: 'advanced', rank: 0 }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
@import url('base.css'); | ||
@import url('pixiedust.css'); | ||
@import url('kernelinfo.css'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.ds-KernelSessionInfoWidget { | ||
padding: 10px 0px 0px 0px; | ||
} | ||
|
||
.ds-KernelSessionInfoWidget div[id*='title'] { | ||
padding: 0px 0px 10px 0px; | ||
} | ||
|
||
.ds-KernelSessionInfoWidget div[id*='list-item'] { | ||
padding: 0px 0px 5px 20px; | ||
} |