From acb8784f61574539821f7e946b3b3c1d4c3e6251 Mon Sep 17 00:00:00 2001 From: Kevin Bates Date: Thu, 4 Oct 2018 08:35:42 -0700 Subject: [PATCH 1/7] Include status types when logging activity Recently I needed to troubleshoot kernel responses and found it helpful to distinguish status types (busy vs. idle) - thought others might find it useful as well. Entries that previously appeared as... ``` activity on 33383dcc-c054-4dc0-b842-16063ea160fe: status activity on 33383dcc-c054-4dc0-b842-16063ea160fe: status activity on 33383dcc-c054-4dc0-b842-16063ea160fe: status activity on 33383dcc-c054-4dc0-b842-16063ea160fe: status activity on 33383dcc-c054-4dc0-b842-16063ea160fe: execute_input activity on 33383dcc-c054-4dc0-b842-16063ea160fe: display_data activity on 33383dcc-c054-4dc0-b842-16063ea160fe: execute_result activity on 33383dcc-c054-4dc0-b842-16063ea160fe: status ``` will now appear as... ``` activity on 33383dcc-c054-4dc0-b842-16063ea160fe: status (idle) activity on 33383dcc-c054-4dc0-b842-16063ea160fe: status (busy) activity on 33383dcc-c054-4dc0-b842-16063ea160fe: status (idle) activity on 33383dcc-c054-4dc0-b842-16063ea160fe: status (busy) activity on 33383dcc-c054-4dc0-b842-16063ea160fe: execute_input activity on 33383dcc-c054-4dc0-b842-16063ea160fe: display_data activity on 33383dcc-c054-4dc0-b842-16063ea160fe: execute_result activity on 33383dcc-c054-4dc0-b842-16063ea160fe: status (idle) ``` --- jupyter_server/services/kernels/kernelmanager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jupyter_server/services/kernels/kernelmanager.py b/jupyter_server/services/kernels/kernelmanager.py index b7f6d9f9a3..4d000e1698 100644 --- a/jupyter_server/services/kernels/kernelmanager.py +++ b/jupyter_server/services/kernels/kernelmanager.py @@ -415,9 +415,11 @@ def record_activity(msg_list): msg = session.deserialize(fed_msg_list) msg_type = msg['header']['msg_type'] - self.log.debug("activity on %s: %s", kernel_id, msg_type) if msg_type == 'status': kernel.execution_state = msg['content']['execution_state'] + self.log.debug("activity on %s: %s (%s)", kernel_id, msg_type, kernel.execution_state) + else: + self.log.debug("activity on %s: %s", kernel_id, msg_type) kernel._activity_stream.on_recv(record_activity) From 5a1ea1ad730bacf23121db16ab8200a6b43a9992 Mon Sep 17 00:00:00 2001 From: Michal Charemza Date: Sat, 13 Oct 2018 22:46:31 +0100 Subject: [PATCH 2/7] Allow more contents manager functions to return futures This allows slower contents managers to not block the event loop by allowing more of their API to return futures. Other usages of contents manager functions are already wrapped in maybe_future, including a use of `file_exists` in contents/handlers.py --- jupyter_server/files/handlers.py | 8 ++++---- jupyter_server/services/contents/handlers.py | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/jupyter_server/files/handlers.py b/jupyter_server/files/handlers.py index b1051ac182..d6bc5e4a8a 100644 --- a/jupyter_server/files/handlers.py +++ b/jupyter_server/files/handlers.py @@ -8,7 +8,7 @@ from base64 import decodebytes -from tornado import web +from tornado import gen, web from jupyter_server.base.handlers import JupyterHandler @@ -46,9 +46,9 @@ def get(self, path, include_body=True): _, name = path.rsplit('/', 1) else: name = path - - model = cm.get(path, type='file', content=include_body) - + + model = yield gen.maybe_future(cm.get(path, type='file', content=include_body)) + if self.get_argument("download", False): self.set_attachment_header(name) diff --git a/jupyter_server/services/contents/handlers.py b/jupyter_server/services/contents/handlers.py index 475282ff16..24eb1a19df 100644 --- a/jupyter_server/services/contents/handlers.py +++ b/jupyter_server/services/contents/handlers.py @@ -182,10 +182,12 @@ def post(self, path=''): cm = self.contents_manager - if cm.file_exists(path): + file_exists = yield gen.maybe_future(cm.file_exists(path)) + if file_exists: raise web.HTTPError(400, "Cannot POST to files, use PUT instead.") - if not cm.dir_exists(path): + dir_exists = yield gen.maybe_future(cm.dir_exists(path)) + if not dir_exists: raise web.HTTPError(404, "No such directory: %s" % path) model = self.get_json_body() From cbd3f61ee1cee5acdaee8f64bd7281bd64067ead Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Mon, 15 Oct 2018 09:51:18 +0100 Subject: [PATCH 3/7] Fix copy/paste-ability of default URL presented on startup Currently the default URL message given on the console on startup is: --- Copy/paste this URL into your browser when you connect for the first time, to login with a token: http://(myip.com or 127.0.0.1):8888/?token=8fdc8 ... --- This will always need editing to use. Replace with host IP (e.g. 'myip.com') to make it copy/pastable again. --- jupyter_server/serverapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 582056c204..76b1fd4d3e 100755 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -1330,7 +1330,7 @@ def display_url(self): url += '/' else: if self.ip in ('', '0.0.0.0'): - ip = "(%s or 127.0.0.1)" % socket.gethostname() + ip = "%s" % socket.gethostname() else: ip = self.ip url = self._url(ip) From c4b56eb0684a00312d3e4cc56fc8a3b5d6b2d18c Mon Sep 17 00:00:00 2001 From: Mark Einon Date: Mon, 15 Oct 2018 20:27:22 +0100 Subject: [PATCH 4/7] Present both possible URL options as separate copy/pastable options Currently the default URL message given on the console on startup is: --- Copy/paste this URL into your browser when you connect for the first time, to login with a token: http://(myip.com or 127.0.0.1):8888/?token=8fdc8 ... --- This will always need editing to use. Replace with one host IP (e.g. 'myip.com') option and one local ip (127.0.0.1) option to make it copy/pastable again. --- jupyter_server/serverapp.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 76b1fd4d3e..7decfad301 100755 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -1337,7 +1337,9 @@ def display_url(self): if self.token: # Don't log full token if it came from config token = self.token if self._token_generated else '...' - url = url_concat(url, {'token': token}) + url = (url_concat(url, {'token': token}) + + '\n or ' + + url_concat(self._url('127.0.0.1'), {'token': token})) return url @property From a6ee595e0510c70fd0f41e05605d98bc6fc68032 Mon Sep 17 00:00:00 2001 From: Dmitry Mikushin Date: Wed, 17 Oct 2018 21:52:49 +0300 Subject: [PATCH 5/7] Enable login mode - to automatically source the /etc/profile script --- jupyter_server/terminal/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jupyter_server/terminal/__init__.py b/jupyter_server/terminal/__init__.py index 1f8360739a..c20001c894 100644 --- a/jupyter_server/terminal/__init__.py +++ b/jupyter_server/terminal/__init__.py @@ -21,6 +21,9 @@ def initialize(webapp, root_dir, connection_url, settings): shell = settings.get('shell_command', [os.environ.get('SHELL') or default_shell] ) + # Enable login mode - to automatically source the /etc/profile script + if os.name != 'nt': + shell.append('-l') terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager( shell_command=shell, extra_env={'JUPYTER_SERVER_ROOT': root_dir, From 0c159111a21a2e262c193a9e13d69417a07c02f7 Mon Sep 17 00:00:00 2001 From: Dave Foster Date: Thu, 25 Oct 2018 09:36:01 -0400 Subject: [PATCH 6/7] Fix default value method for `allow_remote_access` when ip is '*' --- jupyter_server/serverapp.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 7decfad301..c94e7793cf 100755 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -849,6 +849,12 @@ def _token_changed(self, change): @default('allow_remote_access') def _default_allow_remote(self): """Disallow remote access if we're listening only on loopback addresses""" + + # if blank, self.ip was configured to "*" meaning bind to all interfaces, + # see _valdate_ip + if self.ip == "": + return True + try: addr = ipaddress.ip_address(self.ip) except ValueError: From 5b8e62775ae5306bd66230880b73a87188eeaa5d Mon Sep 17 00:00:00 2001 From: Zsailer Date: Wed, 25 Sep 2019 15:25:45 -0700 Subject: [PATCH 7/7] remove reference to notebook in prometheus --- jupyter_server/prometheus/log_functions.py | 2 +- jupyter_server/services/kernels/kernelmanager.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jupyter_server/prometheus/log_functions.py b/jupyter_server/prometheus/log_functions.py index 338b59d0d1..548c5fd8d4 100644 --- a/jupyter_server/prometheus/log_functions.py +++ b/jupyter_server/prometheus/log_functions.py @@ -1,4 +1,4 @@ -from notebook.prometheus.metrics import HTTP_REQUEST_DURATION_SECONDS +from jupyter_server.prometheus.metrics import HTTP_REQUEST_DURATION_SECONDS def prometheus_log_method(handler): diff --git a/jupyter_server/services/kernels/kernelmanager.py b/jupyter_server/services/kernels/kernelmanager.py index 4d000e1698..ae2fd6a251 100644 --- a/jupyter_server/services/kernels/kernelmanager.py +++ b/jupyter_server/services/kernels/kernelmanager.py @@ -26,7 +26,7 @@ from jupyter_server._tz import utcnow, isoformat from ipython_genutils.py3compat import getcwd -from notebook.prometheus.metrics import KERNEL_CURRENTLY_RUNNING_TOTAL +from jupyter_server.prometheus.metrics import KERNEL_CURRENTLY_RUNNING_TOTAL class MappingKernelManager(MultiKernelManager):