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.
UI for blocked kernel actions (jupyter-server#222)
* add a error modal in the UI when a kernel action is blocked * make the console log less aggressive * add initial test for kernelblock plugin * test ui element for exact match
- Loading branch information
Showing
7 changed files
with
149 additions
and
8 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
23 changes: 23 additions & 0 deletions
23
...io_jupyter_extensions/extensions/telemetry/schemas/kernels/kernel-blocked-message.v1.yaml
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,23 @@ | ||
$id: event.datastudio.jupyter.com/kernel-blocked | ||
version: 1 | ||
title: Kernel Blocked Message | ||
description: | | ||
Emit a message that the last kernel action was blocked. | ||
type: object | ||
properties: | ||
process_id: | ||
title: Kernel Process ID | ||
description: | | ||
UUID for this kernel process. | ||
action: | ||
title: Attempted action | ||
description: | | ||
The action that was attempted and blocked by the server. | ||
message: | ||
title: Message type | ||
description: | | ||
Message returned by the Kernel Provisioner. | ||
required: | ||
- process_id | ||
- action | ||
- message |
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,43 @@ | ||
import { | ||
JupyterFrontEnd, | ||
JupyterFrontEndPlugin | ||
} from '@jupyterlab/application'; | ||
|
||
import { PageConfig, URLExt } from '@jupyterlab/coreutils'; | ||
import { showErrorMessage } from '@jupyterlab/apputils'; | ||
|
||
/** | ||
* A plugin to capture Kernel action blocking events and surface to the user. | ||
*/ | ||
export const KernelBlockedPlugin: JupyterFrontEndPlugin<void> = { | ||
id: 'data_studio:kernel_blocked_plugin', | ||
autoStart: true, | ||
requires: [], | ||
activate: async (app: JupyterFrontEnd) => { | ||
console.log('JupyterLab extension "Kernel Blocked Dialog" is activated!'); | ||
|
||
let url = | ||
PageConfig.getOption('studioSubscribeURL') || | ||
URLExt.join(PageConfig.getWsUrl(), 'subscribe'); | ||
|
||
const ws = new WebSocket(url); | ||
|
||
ws.addEventListener('message', function (event) { | ||
const data = JSON.parse(event.data); | ||
console.log('Kernel action blocked:', data); | ||
|
||
// Use session messages to update the path map and also log them. | ||
if (data.__schema__ == 'event.datastudio.jupyter.com/kernel-blocked') { | ||
const msg = | ||
'Cannot ' + | ||
data.action + | ||
' the kernel at this time. ' + | ||
"It is currently in a state, '" + | ||
data.status + | ||
"', which blocks this action."; | ||
|
||
showErrorMessage('409: Kernel Action Blocked', msg); | ||
} | ||
}); | ||
} | ||
}; |
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,52 @@ | ||
import { JupyterLab } from '@jupyterlab/application'; | ||
|
||
import { waitForDialog } from '@jupyterlab/testutils'; | ||
|
||
import WS from 'jest-websocket-mock'; | ||
|
||
import { KernelBlockedPlugin } from '../src/kernelblocked'; | ||
|
||
import { PageConfig } from '@jupyterlab/coreutils'; | ||
|
||
describe('kernel blocked', () => { | ||
let app: JupyterLab; | ||
|
||
beforeEach(async () => { | ||
// Wait for the server to start before creating the application | ||
// so we pick up the page config (base url, etc.) | ||
app = new JupyterLab(); | ||
}); | ||
|
||
it('should capture blocked kernel messages from telemetry bus', async () => { | ||
// Prepare a move websocket. | ||
const url = 'ws://localhost:5555'; | ||
PageConfig.setOption('studioSubscribeURL', url); | ||
const server = new WS(url, { jsonProtocol: true }); | ||
|
||
// Activate the extension. | ||
await KernelBlockedPlugin.activate(app); | ||
|
||
await server.connected; | ||
|
||
// Mock a message from the server | ||
const message = { | ||
__timestamp__: '2021-08-26T11:36:40.946609Z', | ||
__schema__: 'event.datastudio.jupyter.com/kernel-blocked', | ||
__schema_version__: 1, | ||
__metadata_version__: 1, | ||
action: 'restart', | ||
process_id: 'test-id' | ||
}; | ||
server.send(message); | ||
|
||
// Wait for the error dialog. | ||
await waitForDialog(); | ||
|
||
const dialog = document.body.getElementsByClassName('jp-Dialog')[0]; | ||
const header = dialog.getElementsByClassName('jp-Dialog-header')[0]; | ||
|
||
expect(header.innerHTML).toBe('409: Kernel Action Blocked'); | ||
server.close(); | ||
WS.clean(); | ||
}); | ||
}); |