Skip to content

Commit

Permalink
Merge pull request #61 from lsst-sqre/tickets/DM-40143
Browse files Browse the repository at this point in the history
DM-40143: Adopt new notebook execution result with error field
  • Loading branch information
jonathansick authored Jan 4, 2024
2 parents e51d0f0 + 8cea126 commit 466e8c6
Show file tree
Hide file tree
Showing 22 changed files with 770 additions and 499 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: "3.12"

- name: Run pre-commit
uses: pre-commit/[email protected]
Expand All @@ -40,7 +40,7 @@ jobs:
strategy:
matrix:
python:
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Run neophile
uses: lsst-sqre/run-neophile@v1
with:
python-version: "3.11"
python-version: "3.12"
mode: pr
types: pre-commit
app-id: ${{ secrets.NEOPHILE_APP_ID }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: "3.12"

- name: Install graphviz and ImageMagick
run: sudo apt-get install graphviz imagemagick

- name: Run tox
uses: lsst-sqre/run-tox@v1
with:
python-version: "3.11"
python-version: "3.12"
tox-envs: "docs"

- name: Upload documentation
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/periodic-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
python:
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v3
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Run neophile
uses: lsst-sqre/run-neophile@v1
with:
python-version: "3.11"
python-version: "3.12"
mode: update

- name: Run tests in tox
Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

<!-- scriv-insert-here -->

<a id='changelog-0.8.0'></a>
## 0.8.0 (2024-01-04)

### Backwards-incompatible changes

-

### New features

- The response to `GET /notebooks/:job_id` now includes an `ipynb_error` field that contains structured information about any exception that occurred when executing the notebook. As well, if an exception occurred, the resultant notebook is still included in the response. That is, notebook failures are no longer considered failed jobs.

- The `job_id` is now included in log messages when running the `nbexec` job under arq.

- The user guide includes a new tutorial for using the Noteburst web API.

### Bug fixes

-

### Other changes

- Update to Pydantic 2
- Adopt FastAPI's lifespan feature
- Adopt scriv for changelog management

- Update GitHub Actions workflows, including integrating Neophile for dependency updates.

- Update to Python 3.12.

## 0.7.1 (2023-07-23)

### Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# - Runs a non-root user.
# - Sets up the entrypoint and port.

FROM python:3.11.4-slim-bullseye as base-image
FROM python:3.12.1-slim-bullseye as base-image

# Update system packages
COPY scripts/install-base-packages.sh .
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2021 Association of Universities for Research in Astronomy, Inc. (AURA)
Copyright (c) 2021-2024 Association of Universities for Research in Astronomy, Inc. (AURA)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# The dependencies need --allow-unsafe because kubernetes-asyncio and
# (transitively) pre-commit depends on setuptools, which is normally not
# allowed to appear in a hashed dependency file.
.PHONY: update-deps
update-deps:
pip install --upgrade pip-tools pip setuptools
pip-compile --upgrade --build-isolation --generate-hashes --output-file requirements/main.txt requirements/main.in
pip-compile --upgrade --build-isolation --generate-hashes --output-file requirements/dev.txt requirements/dev.in
pip-compile --upgrade --resolver=backtracking --build-isolation \
--allow-unsafe --generate-hashes \
--output-file requirements/main.txt requirements/main.in
pip-compile --upgrade --resolver=backtracking --build-isolation \
--allow-unsafe --generate-hashes \
--output-file requirements/dev.txt requirements/dev.in

# Useful for testing against a Git version of Safir.
.PHONY: update-deps-no-hashes
update-deps-no-hashes:
pip install --upgrade pip-tools pip setuptools
pip-compile --upgrade --resolver=backtracking --build-isolation \
--allow-unsafe \
--output-file requirements/main.txt requirements/main.in
pip-compile --upgrade --resolver=backtracking --build-isolation \
--allow-unsafe \
--output-file requirements/dev.txt requirements/dev.in

.PHONY: init
init:
Expand All @@ -14,7 +32,3 @@ init:

.PHONY: update
update: update-deps init

.PHONY: run
run:
tox run -e=run
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@

Noteburst is a Rubin Science Platform service that coordinates running Jupyter Notebooks in a JupyterLab context.
Noteburst can be used by CI and monitoring services, as well as for applications that need to compute and render Jupyter Notebooks programatically.
[Times Square](https://times-square.lsst.io) uses Noteburst to render Jupyter Notebooks in the browser, for example.

## Links

- [User guide](https://noteburst.lsst.io)
- [SQR-065](https://sqr-065.lsst.io/) (design document)
- [Noteburst in Phalanx](https://phalanx.lsst.io/applications/noteburst/index.html)
5 changes: 0 additions & 5 deletions changelog.d/20231220_121437_jsick_DM_40143.md

This file was deleted.

3 changes: 0 additions & 3 deletions changelog.d/20231220_160149_jsick_DM_40143.md

This file was deleted.

2 changes: 2 additions & 0 deletions docs/_rst_epilog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.. _pre-commit: https://pre-commit.com
.. _pytest: https://docs.pytest.org/en/latest/
.. _tox: https://tox.readthedocs.io/en/latest/
.. _httpie: https://httpie.io/cli
.. _`Rubin Science Platform environment`:
2 changes: 1 addition & 1 deletion docs/documenteer.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
title = "Noteburst"
copyright = "2021-2023 Association of Universities for Research in Astronomy, Inc. (AURA)"
copyright = "2021-2024 Association of Universities for Research in Astronomy, Inc. (AURA)"

[project.python]
package = "noteburst"
Expand Down
136 changes: 136 additions & 0 deletions docs/user-guide/basic-usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
########################################
How to execute a notebook with Noteburst
########################################

This page shows how to execute a Jupyter Notebook programmatically on the Rubin Science Platform with Noteburst's web API.
This approach is applicable to developers who want to integrate notebook execution into their own applications.
Most users won't use this method directly, but instead use Notebook through an application like Times Square.

Prerequisites
=============

HTTP client
-----------

To use the Noteburst web API, you need an HTTP client.
For this tutorial, we'll use HTTPie_, a command-line HTTP client.
You can also use curl or a Python library like Requests if you're more comfortable with that.

Rubin Science Platform token
----------------------------

To use the Noteburst web API, you need a token from the appropriate Rubin Science Platform instance.
This token generally needs the ``exec:notebook`` scope.

For more information on getting a token, see `the Rubin Science Platform documentation <https://rsp.lsst.io/guides/auth/creating-user-tokens.html>`__.

Once you get a token, it's convenient to store in an environment variable in your shell:

.. prompt:: bash

export RSP_TOKEN="gt-..."

Send a Notebook to Noteburst
============================

To execute a Jupyter Notebook (``.ipynb`` file), first send a ``POST`` request:

.. prompt:: bash

http -A bearer -a $RSP_TOKEN post https://usdf-rsp.slac.stanford.edu/noteburst/v1/notebooks/ [email protected]

Set the ``ipynb`` field to the contents of the notebook (HTTPie_\ ’s ``@`` syntax automatically loads the content from a file).
Change the hostname as appropriate for your `Rubin Science Platform environment`_.

The response contains a ``Location`` header with a unique URL for this execution request (you can also get the same URL from the ``self_url`` field in the JSON response body).
You'll use this URL in the next step.

.. code-block:: http
:caption: Example response headers
:emphasize-lines: 7
HTTP/1.1 202 Accepted
Connection: keep-alive
Content-Length: 226
Content-Type: application/json
Date: Thu, 04 Jan 2024 19:53:15 GMT
Strict-Transport-Security: max-age=31536000; includeSubDomains
location: https://data-dev.lsst.cloud/noteburst/v1/notebooks/821bd07de5e645b9b30a4e48a0a38b64
.. code-block:: json
:caption: Example response body
:emphasize-lines: 5
{
"enqueue_time": "2024-01-04T19:53:15.045000Z",
"job_id": "821bd07de5e645b9b30a4e48a0a38b64",
"kernel_name": "LSST",
"self_url": "https://data-dev.lsst.cloud/noteburst/v1/notebooks/821bd07de5e645b9b30a4e48a0a38b64",
"status": "queued"
}
Get the executed notebook
=========================

Now make another request, this time a ``GET``, to that ``Location`` URL to get the executed notebook:

.. prompt:: bash

http -A bearer -a $RSP_TOKEN get https://data-dev.lsst.cloud/noteburst/v1/notebooks/821bd07de5e645b9b30a4e48a0a38b64

The HTTP response body will look similar to the original response from the ``POST`` you made earlier.
Look at the ``status`` field, though.
If it's still ``queued``, the notebook hasn't been scheduled to execute yet.
If the status is ``in_progress``, the notebook is being executed, but has not yet finished.
You can periodically send more ``GET`` requests to check the status until it finally reads ``completed``.

.. code-block:: json
:caption: Example response body
{
"enqueue_time": "2024-01-04T19:53:15.045000Z",
"finish_time": "2024-01-04T19:53:22.229000Z",
"ipynb": "{...}",
"job_id": "821bd07de5e645b9b30a4e48a0a38b64",
"kernel_name": "LSST",
"self_url": "https://data-dev.lsst.cloud/noteburst/v1/notebooks/821bd07de5e645b9b30a4e48a0a38b64",
"start_time": "2024-01-04T19:53:15.548000Z",
"status": "complete",
"success": true
}
In the response, the executed notebook is in the ``ipynb`` field.

You can use the other fields to get statistics and information about the notebook execution.
For example, the difference between ``finish_time`` and ``start_time`` is the overall execution time.

Notebooks that raise an exception
=================================

If the notebook raised an exception, the partially notebook is still returned (and the ``success`` field is still ``true``).
However, now there will be an ``ipynb_error`` field with information about the exception:

.. code-block:: json
:caption: Example response body with exception information
:emphasize-lines: 5,6,7,8
{
"enqueue_time": "2024-01-04T19:53:15.045000Z",
"finish_time": "2024-01-04T19:53:22.229000Z",
"ipynb": "{...}",
"ipynb_error": {
"message": "An error occurred while executing the following cell:\n------------------\nraise RuntimeError(\"This is an error.\")\n",
"name": "RuntimeError"
},
"job_id": "821bd07de5e645b9b30a4e48a0a38b64",
"kernel_name": "LSST",
"self_url": "https://data-dev.lsst.cloud/noteburst/v1/notebooks/821bd07de5e645b9b30a4e48a0a38b64",
"start_time": "2024-01-04T19:53:15.548000Z",
"status": "complete",
"success": true
}
Further reading
===============

For more information about the Noteburst API, see the :doc:`API reference </api>`.
6 changes: 6 additions & 0 deletions docs/user-guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ User guide

configuring-workers
environment-variables

.. toctree::
:maxdepth: 2
:caption: Usage

basic-usage
Loading

0 comments on commit 466e8c6

Please sign in to comment.