From 7a2a56a54797f9429c00a7779a35a1d0f7f8f6fb Mon Sep 17 00:00:00 2001 From: Ray Douglass Date: Thu, 29 Feb 2024 11:37:35 -0500 Subject: [PATCH 1/3] DOC Updates for 0.11.0 --- ci/release/update-version.sh | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/release/update-version.sh b/ci/release/update-version.sh index ce1709f..dada846 100755 --- a/ci/release/update-version.sh +++ b/ci/release/update-version.sh @@ -29,5 +29,5 @@ function sed_runner() { sed -i.bak ''"$1"'' $2 && rm -f ${2}.bak } -jq -e --arg tag "$NEXT_FULL_TAG" '.version=$tag' package.json > package.json.tmp +jq --indent 4 -e --arg tag "$NEXT_FULL_TAG" '.version=$tag' package.json > package.json.tmp mv package.json.tmp package.json diff --git a/package.json b/package.json index 9a59afd..054fdc2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jupyterlab-nvdashboard", - "version": "0.10.0", + "version": "0.11.0", "description": "A JupyterLab extension for displaying GPU usage dashboards", "keywords": [ "jupyter", From 10d4f91e94c40f030df850b79c10d41033ea23c1 Mon Sep 17 00:00:00 2001 From: Ajay Thorve Date: Wed, 1 May 2024 11:45:21 -0700 Subject: [PATCH 2/3] Fix/base url issue (#193) * fix base url retrieval method * incorrect base --- src/charts/PciThroughputChart.tsx | 2 +- src/handler.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/charts/PciThroughputChart.tsx b/src/charts/PciThroughputChart.tsx index 425b457..90440d8 100644 --- a/src/charts/PciThroughputChart.tsx +++ b/src/charts/PciThroughputChart.tsx @@ -24,7 +24,7 @@ const PciThroughputChart: React.FC = ({ settingRegistry }) => { // Load settings and initialize WebSocket connection loadSettingRegistry(settingRegistry, setUpdateFrequency, setIsSettingsLoaded); useWebSocket( - 'nvlink_throughput', + 'pci_stats', false, updateFrequency, setPciStats, diff --git a/src/handler.ts b/src/handler.ts index 9c177c3..69bccf1 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -1,3 +1,6 @@ +import { URLExt } from '@jupyterlab/coreutils'; +import { ServerConnection } from '@jupyterlab/services'; + /** * Connect to a WebSocket API endpoint * @@ -5,10 +8,11 @@ * @returns A WebSocket object connected to the endpoint */ export function connectToWebSocket(endPoint = '') { - const baseUrl = document.location.origin.replace(/^http/, 'ws'); - const wsUrl = new URL(`nvdashboard/${endPoint}`, baseUrl); + const settings = ServerConnection.makeSettings(); + const baseUrl = settings.baseUrl.replace(/^http/, 'ws'); + const wsUrl = URLExt.join(baseUrl, 'nvdashboard', endPoint); - const ws = new WebSocket(wsUrl.href); + const ws = new WebSocket(wsUrl); ws.onopen = () => { console.log(`WebSocket connected to ${endPoint}`); From 96bad0134dc72ad6ccbf19fa6e53efb0f08ba17a Mon Sep 17 00:00:00 2001 From: Ajay Thorve Date: Mon, 3 Jun 2024 07:22:46 -0700 Subject: [PATCH 3/3] Add authentication to ws requests (#196) * add auth to ws requests * style check fix --- jupyterlab_nvdashboard/apps/utils.py | 7 ++++++- jupyterlab_nvdashboard/tests/test_cpu_handlers.py | 5 +++++ jupyterlab_nvdashboard/tests/test_gpu_handlers.py | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/jupyterlab_nvdashboard/apps/utils.py b/jupyterlab_nvdashboard/apps/utils.py index 9392dd1..e437b6a 100644 --- a/jupyterlab_nvdashboard/apps/utils.py +++ b/jupyterlab_nvdashboard/apps/utils.py @@ -1,10 +1,15 @@ from tornado.websocket import WebSocketHandler +from jupyter_server.base.handlers import JupyterHandler import tornado import json -class CustomWebSocketHandler(WebSocketHandler): +class CustomWebSocketHandler(JupyterHandler, WebSocketHandler): def open(self): + if not self.current_user: + self.write_message(json.dumps({"error": "Unauthorized access"})) + self.close() + return self.write_message(json.dumps({"status": "connected"})) self.set_nodelay(True) # Start a periodic callback to send data every 50ms diff --git a/jupyterlab_nvdashboard/tests/test_cpu_handlers.py b/jupyterlab_nvdashboard/tests/test_cpu_handlers.py index 53ce9b5..a67f068 100644 --- a/jupyterlab_nvdashboard/tests/test_cpu_handlers.py +++ b/jupyterlab_nvdashboard/tests/test_cpu_handlers.py @@ -20,6 +20,11 @@ def handler_args(): with patch("tornado.web.Application") as mock_application, patch( "tornado.httputil.HTTPServerRequest" ) as mock_request: + # Mock the settings to return appropriate values + mock_settings = { + "base_url": "/", + } + mock_application.settings = mock_settings yield mock_application, mock_request diff --git a/jupyterlab_nvdashboard/tests/test_gpu_handlers.py b/jupyterlab_nvdashboard/tests/test_gpu_handlers.py index c204a2e..97752a0 100644 --- a/jupyterlab_nvdashboard/tests/test_gpu_handlers.py +++ b/jupyterlab_nvdashboard/tests/test_gpu_handlers.py @@ -26,6 +26,11 @@ def handler_args(): with patch("tornado.web.Application") as mock_application, patch( "tornado.httputil.HTTPServerRequest" ) as mock_request: + # Mock the settings to return appropriate values + mock_settings = { + "base_url": "/", + } + mock_application.settings = mock_settings yield mock_application, mock_request