Commit Graph

12054 Commits

Author SHA1 Message Date
adcdr
05a9b02bb7
Fix broken links
The documentation linked below contains 3 rendering errors:
https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/What%20is%20the%20Jupyter%20Notebook.html

These are caused by limitations in the Sphinx tool used to render the page:
https://docutils.sourceforge.io/FAQ.html#is-nested-inline-markup-possible

This PR fixes them with the least amount of changes.
2020-10-13 21:11:23 +01:00
Matt Riedemann
6a883e0a1c Fix NotebookAppJSONLoggingTests.test_log_json_enabled
The intent of the test is to make sure that log_json defaults
to True when JUPYTER_ENABLE_JSON_LOGGING is set to "true" so
this makes the test more explicit and to pass when json-logging
is not installed so that does not interfere due to validation.
2020-10-13 10:25:07 -05:00
Matt Riedemann
4ee4bb24f9 Use unittest assertion methods for improved logging 2020-10-12 16:39:28 -05:00
Matt Riedemann
08f8ccd1f8 Add log_json=True test for log_request
Basic test just to make sure log_request handles log_json=True
properly.
2020-10-12 16:31:15 -05:00
Matt Riedemann
093aee290f Add some basic tests for log_json config
Make sure the default value is handled properly based
on environment variables. Also checks the validation
code based on whether or not json_logging is imported.
2020-10-12 16:06:02 -05:00
Matt Riedemann
fac228567e Fix logging in _validate_log_json
Just use the app logger since that has the default LogFormatter
logging until we change it to JSON.
2020-10-12 12:17:24 -05:00
Matt Riedemann
8b06db3eae Address review comments 2020-10-12 11:54:38 -05:00
Sai Rahul Poruri
2641b64ada CLN : Remove code for unsupported python versions
specifically, code which was handling python 2.x and < 3.4

	modified:   notebook/base/zmqhandlers.py
	modified:   notebook/services/contents/tests/test_manager.py
	modified:   notebook/tests/test_serverextensions.py
2020-10-10 16:02:36 +01:00
Sai Rahul Poruri
667e0d7519 CLN : Remove unnecessary future imports
specifically print_function and absolute_import future imports
2020-10-10 15:54:34 +01:00
Sai Rahul Poruri
84df5297d5 CLN : Update super usage
This commit updates the super usage. Because Python 2 is not supported
anymore, super usage can be updated such that super is called without
any arguments in the default case where super is called with the class
name and self.

Note that all usage of super has not been updated - a few cases which
smelled funny have been ignored.
2020-10-10 15:49:55 +01:00
Sai Rahul Poruri
9dd2af27de CLN : Remove utf8 coding cookies
On Python 3, the default source file encoding for Python files is utf-8
and because Python 2 is no longer supported, the utf8 coding cookies can
be removed
2020-10-10 15:30:06 +01:00
Matt Riedemann
47e06b013b Log request properties separately when log_json=True
This updates the log_request method to get the request
properties logged separately if `log_json=True`. This
ends up looking like:

```
{"written_at": "2020-10-09T20:59:52.044Z", "written_ts": 1602277192044732000, "msg": "", "type": "log", "logger": "NotebookApp", "thread": "MainThread", "level": "WARNING", "module": "log", "line_no": 50, "status": 404, "method": "GET", "ip": "127.0.0.1", "uri": "/api/kernels/a6dd447b-282a-4e1c-ab65-eb340ad12965/channels?session_id=472907c27ed94e2cbfbae86501f7d159", "request_time": 8.63, "referer": "None"}
```
2020-10-09 16:02:30 -05:00
Matt Riedemann
3e32ce576c Cleanup for log_json review 2020-10-09 15:26:01 -05:00
Matt Riedemann
6a74393f95 Pass NotebookApp logger to log_request
In order to use the same logger from the notebook app we
need to pass it through to the log_request function. To
do that we need to use a partial function so the `log` kwarg
is available. If not provided the default logger is the same
as before, the tornado web access logger.

This is necessary for the `log_json` settings to be used for
both the notebook app logs and the web app request logging.

There is still a todo needed here so that the individual
request fields get formatted separately rather than dumped
into the `msg` field.
2020-10-09 15:09:54 -05:00
Matt Riedemann
ca95490d7c Add log_json config option with default and validation handling
This adds the `NotebookApp.log_json` CLI option which defaults to
False. The default value comes from the `JUPYTER_ENABLE_JSON_LOGGING`
environment variable. A validation hook is added such that if json
logging is enabled but the `json-logging` package is not installed,
an error is logged and the effective `log_json` value is False.

If enabled and the `json-logging` package is installed, the `init_logging`
method will initialize the non-web [1] json logging formatter.

[1] https://github.com/bobbui/json-logging-python#21-non-web-application-log
2020-10-09 14:30:47 -05:00
Matt Riedemann
b617d91052 Check for json log formatting in log_request
This gets us closer to logging parts of the request
as separate json fields but not all the way there.

For example:

```json
{"written_at": "2020-10-07T21:52:16.975Z", "written_ts": 1602107536975497000, "msg": "{'status': 404, 'method': 'GET', 'ip': '127.0.0.1', 'uri': '/nbextensions/widgets/notebook/js/extension.js', 'request_time': 1.9807815551757812, 'referer': 'http://localhost:8888/notebooks/test.ipynb'}", "type": "log", "logger": "NotebookApp", "thread": "MainThread", "level": "WARNING", "module": "log", "line_no": 54}
```
2020-10-07 16:57:43 -05:00
Matt Riedemann
1929fb53b8 Add support for JSON formatted logs
This adds a new extra package dependency on `json-logging`
and an environment variable, which when set to "true" regardless
of case, will try to use the json-logging non-web app log formatter.

If the `json-logging` package is not installed but the environment
variable is True, something like this will be logged but it will not
crash the application:

```
$ ENABLE_JSON_LOGGING=true jupyter notebook
Unable to use json logging due to missing packages. Run "pip install notebook[json-logging]" to fix.
Traceback (most recent call last):
  File "/home/osboxes/jupyter/notebook/notebook/notebookapp.py", line 144, in <module>
    import json_logging
ModuleNotFoundError: No module named 'json_logging'
```

Initially I tried to add a new Bool config option to toggle this but
the problem is (from my limited understanding of traitlets and tornado)
is that `_log_formatter_cls` needs to be set early and trying to se the
log formatter later in `init_logging` is too late - or at least I couldn't
figure out a way to reset the log formatter dynamically (I tried calling
`_log_format_changed` [1] but that didn't work).

With this working you get logs like this:

```
{"written_at": "2020-10-07T21:10:51.606Z", "written_ts": 1602105051606265000, "msg": "404 GET /nbextensions/widgets/notebook/js/extension.js (127.0.0.1) 9.26ms referer=http://localhost:8888/notebooks/Untitled.ipynb", "type": "log", "logger": "NotebookApp", "thread": "MainThread", "level": "WARNING", "module": "log", "line_no": 49}
{"written_at": "2020-10-07T21:10:54.443Z", "written_ts": 1602105054443309000, "msg": "Starting buffering for f260ddd7-938c-42d0-ac3b-455bea76694f:49f30b53fc4b4ec6a8f2fb748a171613", "type": "log", "logger": "NotebookApp", "thread": "MainThread", "level": "INFO", "module": "kernelmanager", "line_no": 222}
{"written_at": "2020-10-07T21:10:54.446Z", "written_ts": 1602105054446264000, "msg": "Kernel shutdown: f260ddd7-938c-42d0-ac3b-455bea76694f", "type": "log", "logger": "NotebookApp", "thread": "MainThread", "level": "INFO", "module": "multikernelmanager", "line_no": 201}
```

An obvious improvement here would to be able to split the `msg` fields apart
so that we can log things like response status code, request method, request
URL, response_time_ms etc. That should be possible with the `JSONLogWebFormatter`
from `json-logging` but when I tried using that I was getting errors from
the library about a correlation id (which is based on a request header we
don't use). The `json-logging` library supports several web frameworks like
Flask but unfortunately does not have built in support for Tornado, but it does
support custom formatters so that might be a follow up option to improve on this.

[1] https://github.com/ipython/traitlets/blob/4.3.3/traitlets/config/application.py#L195

Closes #5798
2020-10-07 16:27:16 -05:00
Kevin Bates
2ba296039a
Merge pull request #5488 from toonijn/refactor-markdown
Refactor code duplication of markdown renderers
2020-10-07 11:33:08 -07:00
Kevin Bates
d74049d06d
Merge pull request #5743 from mriedem/5741-building-docs
Make sure notebook is pip installed when building docs
2020-10-07 10:13:08 -07:00
Matt Riedemann
1ca45de433
Merge branch 'master' into 5741-building-docs 2020-10-07 11:40:29 -05:00
Kevin Bates
466f0f3096
Merge pull request #5780 from bdbai/patch-2
Update translation for zh_CN
2020-10-07 08:25:54 -07:00
Kevin Bates
bc28d61231
Merge pull request #5789 from mueslo/patch-1
Fix _check_pid_win32
2020-10-07 08:00:41 -07:00
mueslo
cd91bd1ac8 Prevent leaking of handle in _check_pid_win32
credit to @garu57
fixes #4862
2020-10-02 20:50:02 +02:00
virejdasani
ea6dd66270 Made doc translations in Hindi and Chinese in hi-IN and zh-CN 2020-10-02 21:03:56 +05:30
Kevin Bates
2b47644820
Merge pull request #5769 from hrnciar/requests-unixsocket-import
Move requests_unixsocket import outside of UNIXSocketNotebookTestBase.fetch_url()
2020-10-02 08:00:39 -07:00
Tomas Hrnciar
63ee7ac809 Move requests_unixsocket import outside of fetch_url() 2020-10-02 10:23:42 +02:00
virejdasani
eeda9ed278 Add Hindi document 2020-10-02 12:03:32 +05:30
virejdasani
3f617a3c33 Add Chinese document 2020-10-02 11:00:25 +05:30
Kevin Bates
d5bcecd4c9
Merge pull request #5783 from hrnciar/sphinx_rtd_theme-dependency
Add sphinx_rtd_theme to documentation dependencies in setup.py
2020-09-30 07:59:16 -07:00
Tomas Hrnciar
cdb103c3f0 Add sphinx_rtd_theme to documentation dependencies in setup.py
Fixes: #5781
2020-09-30 13:06:31 +02:00
包布丁
30097e16d9
Update translation for zh_CN 2020-09-29 23:54:28 +08:00
Matt Riedemann
c6bd48f0fa Remove reference to building conda env from yml file
Since the guide isn't using the environment.yml file anymore
it doesn't make a lot of sense to link to a doc about building
a conda environment from a yml file.
2020-09-11 11:41:29 -05:00
Matt Riedemann
d45a46ad54 Use docs extra for building docs instructions
With the `docs` install extra in setup.py we can simplify the
setup for building the docs by avoiding the now redundant
docs/doc-requirements.txt and docs/environment.yml.
One change is needed in setup.py though which is to add the
`sphinx-rtd-theme` package to the setup.py `docs` extra install
package list which was in doc-requirements.txt and environment.yml
but missing from setup.py.
2020-09-11 11:34:41 -05:00
Matt Riedemann
503d5e7569 Also pip install the notebook for building docs via conda env
To build the docs you need the notebook package installed from
the local project so this updates the contributor guide for the
conda instructions.

Related #5741
2020-09-11 08:56:42 -05:00
Kevin Bates
09ba565c96
Merge pull request #5742 from mriedem/5740-docs-frontend-config-links
Embed frontend_config toctree in config_overview
2020-09-10 14:43:32 -07:00
Matt Riedemann
b7b600952e Make sure notebook is pip installed when building docs
The instructions on building the docs fail to mention that
the notebook package itself needs to be installed. I was following
the pip-based instructions so this fixes that case. I'm not familiar
with using conda really so that case isn't fixed here.

Partial #5741
2020-09-10 09:03:19 -05:00
Matt Riedemann
02b1769e5d Embed frontend_config toctree in config_overview
The section `Notebook front-end client` in the config overview
page was essentially a toc tree except the sub-section links
went to the top of the frontend_config page rather than the real
sub-sections in that page because they all used the same reference.

Rather than create a unique reference for each sub-section in the
frontend_config page, this simply embeds the frontend_config toctree
within the config_overview page which essentially has the same effect.

Closes #5740
2020-09-10 08:50:03 -05:00
Kevin Bates
a35b511991
Back to dev version 2020-09-08 10:52:26 -07:00
Kevin Bates
d8308e1380
Release 6.1.4 2020-09-08 10:47:36 -07:00
Pavel Panchekha
e6e05853d0
Update notebook.js (#5733) 2020-09-08 09:00:25 -05:00
Kevin Bates
5af23431d6
Merge pull request #5730 from bdbai/patch-1
Fix typo for Check in zh_CN
2020-09-05 12:00:10 -07:00
包布丁
652e86c3cd
Remove unnecessary ellipses 2020-09-06 00:25:44 +08:00
包布丁
c84af49dfd
Remove ellipsis 2020-09-05 10:27:09 +08:00
包布丁
9e7c8515a8
Fix typo for Check in zh_CN 2020-09-04 22:47:29 +08:00
Kevin Bates
4255cfe4d3
Merge pull request #5720 from Zsailer/download-files-bug
bug fix: remove double encoding in download files
2020-08-31 10:51:37 -07:00
Zsailer
45a7616075 bug fix: remove double encoding in download files 2020-08-31 10:38:11 -07:00
Zachary Sailer
2e5cf497a6
Merge pull request #5695 from kevin-bates/troubleshooting-docs
Add additional entries to troubleshooting section
2020-08-28 08:10:41 -07:00
Zachary Sailer
bb55a1b41c
Update docs/source/troubleshooting.rst 2020-08-28 08:09:47 -07:00
Zachary Sailer
138b406f00
Merge pull request #5703 from Zsailer/revert-html-alignment
Revert change in page alignment
2020-08-28 08:07:48 -07:00
Kevin Bates
78f185f76a
Add reference to IPython docs for multi-env scenarios 2020-08-27 17:11:19 -07:00