Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use in Google Cloud Jupyter Notebook #139

Open
TychonautVII opened this issue Nov 10, 2022 · 1 comment
Open

Unable to use in Google Cloud Jupyter Notebook #139

TychonautVII opened this issue Nov 10, 2022 · 1 comment
Labels

Comments

@TychonautVII
Copy link

TychonautVII commented Nov 10, 2022

Bug description

I have not been able to get jupyter-rsession-proxy to work in a Google Cloud Vertex AI Jupyter Notebook.

I understand this is pretty niche and platform specific, even if you no one picks this up as a bug I'd love some guidance on what to do next. I've been beating my head against the wall a bit.

Expected behaviour

I have jupyter-rsession-proxy installed in a google Cloud Vertex AI Jupyter Notebook

image

Rstudio appears as an available type of notebook

When I click it I'm able to access R studio.

Actual behaviour

Rstudio appears as an available type of notebook, as expected

When I click on it a new tab opens the page attempts to load for a while, and then eventually fails with a too many redirects error.

It sounds alot like an issue that was recently fixed, but I am using the most up to date versions of all the relevant packages.

You can see an example of what the chain or redirects looks like here.

image

I'm not sure what the expected behavior is here, or I'd fork and try to adjust init.py / rewrite_netloc myself. I'm hoping someone with experience with how this redirection issue was solved elsewhere can provide some guidance.

How to reproduce

So to really reproduce, you'd have to

  1. Create a Vertex AI GCP R notebook, following the instructions here
    https://cloud.google.com/architecture/data-science-with-r-on-gcp-eda#create_an_ai_platform_notebooks_instance_with_r

I know that first step is a tall ask, but I'm happy to work this myself if y'all could point me in the right directly.

You might be able to replicate the behavior with the docker container that GCP is using which is gcr.io/deeplearning-platform-release/r-cpu.4-2:latest

  1. Update the following packages
conda update jupyterlab
conda install jupyter-rsession-proxy
  1. Restart the jupyter notebook

  2. Click on the Rstudio icon in the launcher.

Your personal set up

My environment is based on the docker container gcr.io/deeplearning-platform-release/r-cpu.4-2:latest

I've attempted to make it as similar to the rocker containers in a hope to get this to work, here's the docker file I'm using

# -----------------------------------
# GCP ML Container
# -----------------------------------

FROM  gcr.io/deeplearning-platform-release/r-cpu.4-2:latest
RUN conda update --all
RUN conda update jupyterlab

# -----------------------------------
# Install R Tools using Rocker
# -----------------------------------

# RStudio
RUN git clone https://github.com/rocker-org/rocker-versioned2.git

ENV R_VERSION=4.2.2
ENV R_HOME=/usr/local/lib/R
ENV TZ=Etc/UTC
ENV S6_VERSION=v2.1.0.2
ENV RSTUDIO_VERSION=2022.07.2+576
ENV DEFAULT_USER=jupyter
ENV PANDOC_VERSION=default
ENV QUARTO_VERSION=default
ENV SHINY_SERVER_VERSION=latest
ENV NB_USER=jupyter

RUN mv rocker-versioned2/scripts rocker_scripts

RUN /rocker_scripts/install_rstudio.sh
RUN /rocker_scripts/install_pandoc.sh
RUN /rocker_scripts/install_quarto.sh

# Rshiny
RUN R -e 'install.packages(c("littler","docopt"))'
RUN ln -sf "${R_HOME}/site-library/littler/bin/r" /usr/local/bin/r
RUN ln -sf "${R_HOME}/site-library/littler/examples/installGithub.r" /usr/local/bin/installGithub.r
RUN ln -sf /rocker_scripts/bin/install2.r /usr/local/bin/install2.r
RUN /rocker_scripts/install_shiny_server.sh
RUN chmod 777 /usr/local/lib/R/site-library
# -----------------------------------
# Application specific config
# -----------------------------------
RUN conda install jupyter-rsession-proxy
RUN R -e 'install.packages(c("renv","tidylog"))'
# RUN pip install git+https://github.com/jupyterhub/jupyter-rsession-proxy.git@master

  • OS:
~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

Python 3.7.12

jupyter-rsession-proxy 2.1.0
jupyter-server-proxy 3.2.2
jupyterlab 3.4.8

Full environment
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
absl-py                   1.3.0              pyhd8ed1ab_0    conda-forge
aiohttp                   3.8.3            py37h540881e_0    conda-forge
aiosignal                 1.3.1              pyhd8ed1ab_0    conda-forge
alsa-lib                  1.2.8                h166bdaf_0    conda-forge
ansiwrap                  0.8.4                      py_0    conda-forge
anyio                     3.6.2              pyhd8ed1ab_0    conda-forge
argon2-cffi               21.3.0             pyhd8ed1ab_0    conda-forge
argon2-cffi-bindings      21.2.0           py37h540881e_2    conda-forge
async-timeout             4.0.2              pyhd8ed1ab_0    conda-forge
asynctest                 0.13.0                     py_0    conda-forge
attr                      2.5.1                h166bdaf_1    conda-forge
attrs                     22.1.0             pyh71513ae_1    conda-forge
babel                     2.11.0             pyhd8ed1ab_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports-zoneinfo        0.2.1                    pypi_0    pypi
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
bcrypt                    3.2.2            py37h540881e_0    conda-forge
beatrix-jupyterlab        2022.1028.200048          pypi_0    pypi
beautifulsoup4            4.11.1             pyha770c72_0    conda-forge
black                     22.10.0          py37h89c1867_1    conda-forge
bleach                    5.0.1              pyhd8ed1ab_0    conda-forge
blinker                   1.5                pyhd8ed1ab_0    conda-forge
brotli                    1.0.9                h166bdaf_8    conda-forge
brotli-bin                1.0.9                h166bdaf_8    conda-forge
brotlipy                  0.7.0           py37h540881e_1004    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
c-ares                    1.18.1               h7f98852_0    conda-forge
ca-certificates           2022.9.24            ha878542_0    conda-forge
cachetools                5.2.0              pyhd8ed1ab_0    conda-forge
certifi                   2022.9.24          pyhd8ed1ab_0    conda-forge
cffi                      1.15.1           py37h43b0acd_1    conda-forge
charset-normalizer        2.1.1              pyhd8ed1ab_0    conda-forge
click                     8.1.3            py37h89c1867_0    conda-forge
cloud-tpu-client          0.10                     pypi_0    pypi
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
conda                     22.9.0           py37h89c1867_1    conda-forge
conda-package-handling    1.9.0            py37h540881e_0    conda-forge
cryptography              38.0.2           py37h38fbfac_1    conda-forge
cycler                    0.11.0             pyhd8ed1ab_0    conda-forge
dbus                      1.13.6               h5008d03_3    conda-forge
debugpy                   1.6.3            py37hd23a5d3_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
dlenv-base                1.0.20221030     py37hfeaa757_0    file:///tmp/conda
docker-py                 6.0.0              pyhd8ed1ab_0    conda-forge
entrypoints               0.4                pyhd8ed1ab_0    conda-forge
expat                     2.5.0                h27087fc_0    conda-forge
fftw                      3.3.10          nompi_hf0379b8_105    conda-forge
flit-core                 3.8.0              pyhd8ed1ab_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.14.1               hc2a2eb6_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
fonttools                 4.38.0           py37h540881e_0    conda-forge
freetype                  2.12.1               hca18f0e_0    conda-forge
frozenlist                1.3.1            py37h540881e_0    conda-forge
fsspec                    2022.11.0          pyhd8ed1ab_0    conda-forge
gcsfs                     2022.11.0          pyhd8ed1ab_0    conda-forge
gettext                   0.21.1               h27087fc_0    conda-forge
gitdb                     4.0.9              pyhd8ed1ab_0    conda-forge
gitpython                 3.1.29             pyhd8ed1ab_0    conda-forge
glib                      2.74.1               h6239696_1    conda-forge
glib-tools                2.74.1               h6239696_1    conda-forge
google-api-core           1.33.2                   pypi_0    pypi
google-api-core-grpcio-gcp 2.8.0                hd8ed1ab_1    conda-forge
google-api-python-client  1.8.0                    pypi_0    pypi
google-auth               2.14.0             pyh1a96a4e_0    conda-forge
google-auth-httplib2      0.1.0              pyhd8ed1ab_1    conda-forge
google-auth-oauthlib      0.7.1              pyhd8ed1ab_0    conda-forge
google-cloud-aiplatform   1.18.2                   pypi_0    pypi
google-cloud-appengine-logging 1.1.6                    pypi_0    pypi
google-cloud-audit-log    0.2.4                    pypi_0    pypi
google-cloud-bigquery     2.34.4                   pypi_0    pypi
google-cloud-bigquery-storage 2.16.2                   pypi_0    pypi
google-cloud-bigtable     2.13.2                   pypi_0    pypi
google-cloud-core         2.3.2              pyhd8ed1ab_0    conda-forge
google-cloud-dataproc     5.0.3                    pypi_0    pypi
google-cloud-datastore    2.9.0                    pypi_0    pypi
google-cloud-firestore    2.7.2                    pypi_0    pypi
google-cloud-kms          2.12.3                   pypi_0    pypi
google-cloud-language     2.6.1                    pypi_0    pypi
google-cloud-logging      3.2.5                    pypi_0    pypi
google-cloud-monitoring   2.11.3                   pypi_0    pypi
google-cloud-pubsub       2.13.10                  pypi_0    pypi
google-cloud-resource-manager 1.6.3                    pypi_0    pypi
google-cloud-scheduler    2.7.3                    pypi_0    pypi
google-cloud-spanner      3.22.2                   pypi_0    pypi
google-cloud-speech       2.16.2                   pypi_0    pypi
google-cloud-storage      2.6.0              pyh1a96a4e_0    conda-forge
google-cloud-tasks        2.10.4                   pypi_0    pypi
google-cloud-translate    3.8.4                    pypi_0    pypi
google-cloud-videointelligence 2.8.3                    pypi_0    pypi
google-cloud-vision       3.1.4                    pypi_0    pypi
google-crc32c             1.1.2            py37h5d4fa31_3    conda-forge
google-resumable-media    2.4.0              pyhd8ed1ab_0    conda-forge
googleapis-common-protos  1.56.4           py37h89c1867_0    conda-forge
greenlet                  1.1.3            py37hd23a5d3_0    conda-forge
grpc-cpp                  1.48.1               h05bd8bd_1    conda-forge
grpc-google-iam-v1        0.12.4                   pypi_0    pypi
grpcio                    1.50.0                   pypi_0    pypi
grpcio-gcp                0.2.2              pyhd8ed1ab_6    conda-forge
grpcio-status             1.48.2                   pypi_0    pypi
gst-plugins-base          1.21.1               h3e40eee_1    conda-forge
gstreamer                 1.21.1               hd4edc92_1    conda-forge
htmlmin                   0.1.12                     py_1    conda-forge
httplib2                  0.21.0             pyhd8ed1ab_0    conda-forge
icu                       70.1                 h27087fc_0    conda-forge
idna                      3.4                pyhd8ed1ab_0    conda-forge
imagehash                 4.3.1              pyhd8ed1ab_0    conda-forge
importlib-metadata        4.11.4           py37h89c1867_0    conda-forge
importlib_resources       5.10.0             pyhd8ed1ab_0    conda-forge
ipykernel                 6.16.2             pyh210e3f2_0    conda-forge
ipython                   7.33.0           py37h89c1867_0    conda-forge
ipython-sql               0.3.9           pyhd8ed1ab_1004    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
ipywidgets                8.0.2              pyhd8ed1ab_1    conda-forge
jack                      1.9.21               he978b8e_1    conda-forge
jaraco-classes            3.2.3                    pypi_0    pypi
jedi                      0.18.1             pyhd8ed1ab_2    conda-forge
jeepney                   0.8.0                    pypi_0    pypi
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
joblib                    1.2.0              pyhd8ed1ab_0    conda-forge
jpeg                      9e                   h166bdaf_2    conda-forge
json5                     0.9.5              pyh9f0ad1d_0    conda-forge
jsonschema                4.17.0             pyhd8ed1ab_0    conda-forge
jupyter-http-over-ws      0.0.8                    pypi_0    pypi
jupyter-rsession-proxy    2.1.0              pyhd8ed1ab_0    conda-forge
jupyter-server-mathjax    0.2.6              pyhc268e32_0    conda-forge
jupyter-server-proxy      3.2.2              pyhd8ed1ab_0    conda-forge
jupyter_client            7.4.5              pyhd8ed1ab_0    conda-forge
jupyter_core              4.11.1           py37h89c1867_0    conda-forge
jupyter_server            1.23.1             pyhd8ed1ab_0    conda-forge
jupyterlab                3.4.8              pyhd8ed1ab_0    conda-forge
jupyterlab-git            0.39.3             pyhd8ed1ab_0    conda-forge
jupyterlab_pygments       0.2.2              pyhd8ed1ab_0    conda-forge
jupyterlab_server         2.16.2             pyhd8ed1ab_0    conda-forge
jupyterlab_widgets        3.0.3              pyhd8ed1ab_0    conda-forge
jupytext                  1.14.0             pyheef035f_0    conda-forge
keyring                   23.9.3                   pypi_0    pypi
keyrings-google-artifactregistry-auth 1.1.1                    pypi_0    pypi
keyutils                  1.6.1                h166bdaf_0    conda-forge
kiwisolver                1.4.4            py37h7cecad7_0    conda-forge
krb5                      1.19.3               h3790be6_0    conda-forge
lame                      3.100             h166bdaf_1003    conda-forge
lcms2                     2.14                 h6ed2654_0    conda-forge
ld_impl_linux-64          2.39                 hc81fddc_0    conda-forge
lerc                      4.0.0                h27087fc_0    conda-forge
libabseil                 20220623.0      cxx17_h48a1fff_5    conda-forge
libblas                   3.9.0           16_linux64_openblas    conda-forge
libbrotlicommon           1.0.9                h166bdaf_8    conda-forge
libbrotlidec              1.0.9                h166bdaf_8    conda-forge
libbrotlienc              1.0.9                h166bdaf_8    conda-forge
libcap                    2.66                 ha37c62d_0    conda-forge
libcblas                  3.9.0           16_linux64_openblas    conda-forge
libclang                  15.0.4          default_h2e3cab8_0    conda-forge
libclang13                15.0.4          default_h3a83d3e_0    conda-forge
libcrc32c                 1.1.2                h9c3ff4c_0    conda-forge
libcups                   2.3.3                h3e49a29_2    conda-forge
libdb                     6.2.32               h9c3ff4c_0    conda-forge
libdeflate                1.14                 h166bdaf_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libevent                  2.1.10               h9b69904_4    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libflac                   1.4.2                h27087fc_0    conda-forge
libgcc-ng                 12.2.0              h65d4601_19    conda-forge
libgfortran-ng            12.2.0              h69a702a_19    conda-forge
libgfortran5              12.2.0              h337968e_19    conda-forge
libglib                   2.74.1               h606061b_1    conda-forge
libgomp                   12.2.0              h65d4601_19    conda-forge
libiconv                  1.17                 h166bdaf_0    conda-forge
liblapack                 3.9.0           16_linux64_openblas    conda-forge
libllvm10                 10.0.1               he513fc3_3    conda-forge
libllvm11                 11.1.0               he0ac6c6_5    conda-forge
libllvm14                 14.0.6               he0ac6c6_1    conda-forge
libllvm15                 15.0.4               h63197d8_1    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libogg                    1.3.4                h7f98852_1    conda-forge
libopenblas               0.3.21          pthreads_h78a6416_3    conda-forge
libopus                   1.3.1                h7f98852_1    conda-forge
libpng                    1.6.38               h753d276_0    conda-forge
libpq                     14.5                 hd77ab85_1    conda-forge
libprotobuf               3.21.8               h6239696_0    conda-forge
libsndfile                1.1.0                h27087fc_0    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libsqlite                 3.39.4               h753d276_0    conda-forge
libstdcxx-ng              12.2.0              h46fd767_19    conda-forge
libtiff                   4.4.0                h55922b4_4    conda-forge
libtool                   2.4.6             h9c3ff4c_1008    conda-forge
libudev1                  252                  h166bdaf_0    conda-forge
libuuid                   2.32.1            h7f98852_1000    conda-forge
libuv                     1.44.2               h166bdaf_0    conda-forge
libvorbis                 1.3.7                h9c3ff4c_0    conda-forge
libwebp-base              1.2.4                h166bdaf_0    conda-forge
libxcb                    1.13              h7f98852_1004    conda-forge
libxkbcommon              1.0.3                he3ba5ed_0    conda-forge
libxml2                   2.10.3               h7463322_0    conda-forge
libzlib                   1.2.13               h166bdaf_4    conda-forge
llvmlite                  0.39.1           py37h0761922_0    conda-forge
markdown-it-py            2.1.0              pyhd8ed1ab_0    conda-forge
markupsafe                2.1.1            py37h540881e_1    conda-forge
matplotlib                3.5.3            py37h89c1867_2    conda-forge
matplotlib-base           3.5.3            py37hf395dca_2    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
mdit-py-plugins           0.3.1              pyhd8ed1ab_0    conda-forge
mdurl                     0.1.0              pyhd8ed1ab_0    conda-forge
missingno                 0.4.2                      py_1    conda-forge
mistune                   2.0.4              pyhd8ed1ab_0    conda-forge
more-itertools            9.0.0                    pypi_0    pypi
mpg123                    1.30.2               h27087fc_1    conda-forge
multidict                 6.0.2            py37h540881e_1    conda-forge
multimethod               1.4                        py_0    conda-forge
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
mypy_extensions           0.4.3            py37h89c1867_5    conda-forge
mysql-common              8.0.31               haf5c9bc_0    conda-forge
mysql-libs                8.0.31               h28c427c_0    conda-forge
nb_conda                  2.2.1                    unix_6    conda-forge
nb_conda_kernels          2.3.1            py37h89c1867_1    conda-forge
nbclassic                 0.4.8              pyhd8ed1ab_0    conda-forge
nbclient                  0.7.0              pyhd8ed1ab_0    conda-forge
nbconvert                 7.2.4              pyhd8ed1ab_0    conda-forge
nbconvert-core            7.2.4              pyhd8ed1ab_0    conda-forge
nbconvert-pandoc          7.2.4              pyhd8ed1ab_0    conda-forge
nbdime                    3.1.1              pyhd8ed1ab_0    conda-forge
nbformat                  5.7.0              pyhd8ed1ab_0    conda-forge
ncurses                   6.3                  h27087fc_1    conda-forge
nest-asyncio              1.5.6              pyhd8ed1ab_0    conda-forge
networkx                  2.7.1              pyhd8ed1ab_0    conda-forge
nodejs                    18.12.1              h96d913c_0    conda-forge
notebook                  6.5.2              pyha770c72_1    conda-forge
notebook-executor         0.2                      pypi_0    pypi
notebook-shim             0.2.2              pyhd8ed1ab_0    conda-forge
nspr                      4.32                 h9c3ff4c_1    conda-forge
nss                       3.78                 h2350873_0    conda-forge
numba                     0.56.3           py37hf081915_0    conda-forge
numpy                     1.21.6           py37h976b520_0    conda-forge
oauth2client              4.1.3                    pypi_0    pypi
oauthlib                  3.2.2              pyhd8ed1ab_0    conda-forge
openjpeg                  2.5.0                h7d73246_1    conda-forge
openssl                   1.1.1s               h166bdaf_0    conda-forge
packaging                 21.3               pyhd8ed1ab_0    conda-forge
pandas                    1.3.5            py37he8f5f7f_0    conda-forge
pandas-profiling          3.4.0              pyhd8ed1ab_1    conda-forge
pandoc                    2.19.2               h32600fe_1    conda-forge
pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
papermill                 2.3.4              pyhd8ed1ab_0    conda-forge
paramiko                  2.12.0             pyhd8ed1ab_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pathspec                  0.10.1             pyhd8ed1ab_0    conda-forge
patsy                     0.5.3              pyhd8ed1ab_0    conda-forge
pcre2                     10.40                hc3806b6_0    conda-forge
pexpect                   4.8.0              pyh1a96a4e_2    conda-forge
phik                      0.12.2           py37h237e563_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    9.2.0            py37h850a105_2    conda-forge
pip                       22.3.1             pyhd8ed1ab_0    conda-forge
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_0    conda-forge
platformdirs              2.5.2              pyhd8ed1ab_1    conda-forge
plotly                    5.11.0             pyhd8ed1ab_0    conda-forge
ply                       3.11                       py_1    conda-forge
prettytable               3.4.1              pyhd8ed1ab_0    conda-forge
prometheus_client         0.15.0             pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.32             pyha770c72_0    conda-forge
proto-plus                1.22.1                   pypi_0    pypi
protobuf                  3.20.3                   pypi_0    pypi
psutil                    5.9.3            py37h540881e_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pulseaudio                14.0                h0d2025b_11    conda-forge
pyarrow                   10.0.0                   pypi_0    pypi
pyasn1                    0.4.8                      py_0    conda-forge
pyasn1-modules            0.2.7                      py_0    conda-forge
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pycosat                   0.6.4            py37h540881e_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pydantic                  1.10.2           py37h540881e_0    conda-forge
pygments                  2.13.0             pyhd8ed1ab_0    conda-forge
pyjwt                     2.6.0              pyhd8ed1ab_0    conda-forge
pynacl                    1.5.0            py37h540881e_1    conda-forge
pyopenssl                 22.1.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyqt                      5.15.7           py37hf30b843_1    conda-forge
pyqt5-sip                 12.11.0          py37hd23a5d3_1    conda-forge
pyrsistent                0.18.1           py37h540881e_1    conda-forge
pysocks                   1.7.1            py37h89c1867_5    conda-forge
python                    3.7.12          hb7a2778_100_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-fastjsonschema     2.16.2             pyhd8ed1ab_0    conda-forge
python_abi                3.7                     2_cp37m    conda-forge
pytz                      2022.6             pyhd8ed1ab_0    conda-forge
pytz-deprecation-shim     0.1.0.post0              pypi_0    pypi
pyu2f                     0.1.5              pyhd8ed1ab_0    conda-forge
pywavelets                1.3.0            py37hda87dfa_1    conda-forge
pywin32-on-windows        0.1.0              pyh1179c8e_3    conda-forge
pyyaml                    6.0              py37h540881e_4    conda-forge
pyzmq                     24.0.1           py37h0c0c2a8_0    conda-forge
qt-main                   5.15.6               hd477bba_1    conda-forge
re2                       2022.06.01           h27087fc_0    conda-forge
readline                  8.1.2                h0f457ee_0    conda-forge
requests                  2.28.1             pyhd8ed1ab_1    conda-forge
requests-oauthlib         1.3.1              pyhd8ed1ab_0    conda-forge
retrying                  1.3.3                    pypi_0    pypi
rpy2                      3.5.5                    pypi_0    pypi
rsa                       4.9                pyhd8ed1ab_0    conda-forge
ruamel_yaml               0.15.80         py37h540881e_1007    conda-forge
scikit-learn              1.0.2            py37hf9e9bfc_0    conda-forge
scipy                     1.7.3            py37hf2a6cf1_0    conda-forge
seaborn                   0.12.1               hd8ed1ab_0    conda-forge
seaborn-base              0.12.1             pyhd8ed1ab_0    conda-forge
secretstorage             3.3.3                    pypi_0    pypi
send2trash                1.8.0              pyhd8ed1ab_0    conda-forge
setuptools                59.8.0           py37h89c1867_1    conda-forge
simpervisor               0.4                pyhd8ed1ab_0    conda-forge
sip                       6.7.2            py37hd23a5d3_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
smmap                     3.0.5              pyh44b312d_0    conda-forge
sniffio                   1.3.0              pyhd8ed1ab_0    conda-forge
soupsieve                 2.3.2.post1        pyhd8ed1ab_0    conda-forge
sqlalchemy                1.4.42           py37h540881e_0    conda-forge
sqlite                    3.39.4               h4ff8645_0    conda-forge
sqlparse                  0.4.3              pyhd8ed1ab_0    conda-forge
statsmodels               0.13.2           py37hda87dfa_0    conda-forge
tangled-up-in-unicode     0.2.0              pyhd8ed1ab_0    conda-forge
tenacity                  8.1.0              pyhd8ed1ab_0    conda-forge
terminado                 0.17.0             pyh41d4057_0    conda-forge
textwrap3                 0.9.2                      py_0    conda-forge
threadpoolctl             3.1.0              pyh8a188c0_0    conda-forge
tinycss2                  1.2.1              pyhd8ed1ab_0    conda-forge
tk                        8.6.12               h27826a3_0    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
toolz                     0.12.0             pyhd8ed1ab_0    conda-forge
tornado                   6.2              py37h540881e_0    conda-forge
tqdm                      4.64.1             pyhd8ed1ab_0    conda-forge
traitlets                 5.5.0              pyhd8ed1ab_0    conda-forge
typed-ast                 1.5.4            py37h540881e_0    conda-forge
typing-extensions         4.4.0                hd8ed1ab_0    conda-forge
typing_extensions         4.4.0              pyha770c72_0    conda-forge
tzdata                    2022.6                   pypi_0    pypi
tzlocal                   4.2                      pypi_0    pypi
unicodedata2              14.0.0           py37h540881e_1    conda-forge
uritemplate               3.0.1                    pypi_0    pypi
urllib3                   1.26.11            pyhd8ed1ab_0    conda-forge
visions                   0.7.5              pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
websocket-client          1.4.2              pyhd8ed1ab_0    conda-forge
wheel                     0.38.4             pyhd8ed1ab_0    conda-forge
widgetsnbextension        4.0.3              pyhd8ed1ab_0    conda-forge
xcb-util                  0.4.0                h166bdaf_0    conda-forge
xcb-util-image            0.4.0                h166bdaf_0    conda-forge
xcb-util-keysyms          0.4.0                h166bdaf_0    conda-forge
xcb-util-renderutil       0.3.9                h166bdaf_0    conda-forge
xcb-util-wm               0.4.1                h166bdaf_0    conda-forge
xorg-libxau               1.0.9                h7f98852_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge
yarl                      1.7.2            py37h540881e_2    conda-forge
zeromq                    4.3.4                h9c3ff4c_1    conda-forge
zipp                      3.10.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h166bdaf_4    conda-forge
zstd                      1.5.2                h6239696_4    conda-forge
Configuration

jupyter_notebook_config.py

"""Vertex Workbench. Jupyter Service configuration file."""

import logging
import os
import sys

from jupyter_client import kernelspec
import requests
from requests.adapters import HTTPAdapter

# pylint: disable=anomalous-backslash-in-string, line-too-long, undefined-variable
c.NotebookApp.open_browser = False
c.ServerApp.token = ""
c.ServerApp.password = ""
c.ServerApp.port = 8080
c.ServerApp.allow_origin_pat = "(^https://8080-dot-[0-9]+-dot-devshell\.appspot\.com$)|(^https://colab\.sandbox\.google\.com$)|(^https://colab\.research\.google\.com$)|((https?://)?[0-9a-z]+-dot-datalab-vm[\-0-9a-z]*\.googleusercontent\.com)|((https?://)?[0-9a-z]+-dot-[\-0-9a-z]*\.notebooks\.googleusercontent\.com)|((https?://)?[0-9a-z\-]+\.[0-9a-z\-]+\.cloudshell\.dev)|((https?://)ssh\.cloud\.google\.com/devshell)"
c.ServerApp.allow_remote_access = True
c.ServerApp.root_dir = "/home/jupyter"

# pylint: enable=anomalous-backslash-in-string, line-too-long, undefined-variable

BASE_PATH = "/opt/deeplearning/metadata/"
MAX_RETRIES = 2
METADATA_URL = "http://metadata/computeMetadata/v1"
METADATA_FLAVOR = {"Metadata-Flavor": "Google"}


def _get_session(prefix="http://", max_retries=MAX_RETRIES):
  """Return an HTTP Session.

  Args:
    prefix(str): Prefix for URL
    max_retries(int): Maximum number of retries each connection should attempt.

  Returns:
    A requests.Session()
  """
  session = requests.Session()
  session.mount(prefix, HTTPAdapter(max_retries=max_retries))
  return session


def get_jupyter_user():
  """Get default Jupyter user."""
  jupyter_user = "jupyter"
  if get_attribute_value("jupyter-user"):
    jupyter_user = get_attribute_value("jupyter-user")
  return jupyter_user


def get_attribute_value(attribute):
  """Get Metadata value.

  Args:
    attribute(str): Attribute key to look in Compute Metadata.

  Returns:
    Attribute value or None
  """
  if attribute is None:
    raise ValueError("Invalid attribute. Attribute is None")
  try:
    session = _get_session(max_retries=5)
    response = session.get(
        f"{METADATA_URL}/instance/attributes/{attribute}",
        headers=METADATA_FLAVOR,
    )
    response.raise_for_status()
    print(f"Metadata {attribute}:{response.text}")
    return response.text
  except requests.exceptions.HTTPError as err:
    if err.response.status_code == 404:
      print(err)
  return None


def handle_attribute_value(attribute_value):
  """If attribute value exists, check if its true or false."""
  if not attribute_value:
    return False
  if attribute_value.lower() == "true":
    return True
  return False


def _disable_downloads():
  """Disable file downloads from JupyterLab.

  Handlers are created at startup time.
  """
  jupyter_user = get_jupyter_user()
  jupyter_home = f"/home/{jupyter_user}"
  sys.path.append(f"{jupyter_home}/.jupyter/")
  # pylint: disable=unused-import,import-outside-toplevel,undefined-variable
  import handlers
  c.ContentsManager.files_handler_class = "handlers.ForbidFilesHandler"
  c.ContentsManager.files_handler_params = {}
  # Prevent export/printing of calculated values that likely have PII
  c.TemplateExporter.exclude_input_prompt = True
  c.TemplateExporter.exclude_output = True
  # pylint: enable=unused-import,import-outside-toplevel,undefined-variable


def read_from_file(path):
  """Read metadata file.

  Args:
    path(str): Location of file with metadata information.

  Returns:
    A string.
  """
  with open(path, "r", encoding="utf-8") as file:
    return file.read().replace("\n", "")


def get_env_name():
  return read_from_file(os.path.join(BASE_PATH, "env_version"))


def get_env_uri():
  return read_from_file(os.path.join(BASE_PATH, "env_uri"))


local_kernelspec_cache = {}


def metadata_env_pre_save(model, **kwargs):  # pylint: disable=unused-argument
  """Save metadata from Jupyter Environment.

  Args:
    model(dict): Notebooks information
    **kwargs: Keyword Arguments.
  """

  try:
    # only run on notebooks
    if model["type"] != "notebook":
      return
    # only run on nbformat v4 or later
    if model["content"]["nbformat"] < 4:
      return
    model_metadata = model["content"]["metadata"]
    if "kernelspec" in model_metadata:
      kernel = model_metadata["kernelspec"]["name"]
      # remote kernels have no compatible container at the moment
      if kernel.startswith("remote-"):
        del model_metadata["kernelspec"]
        model_metadata["environment"] = {
            "type": "gcloud",
            "name": get_env_name(),
        }
        return
      # local kernels will have the local prefix in managed notebooks
      if kernel.startswith("local-"):
        kernel = kernel.split("-", 1)[1]
        if kernel not in local_kernelspec_cache:
          for k in kernelspec.find_kernel_specs():
            local_kernelspec_cache[k] = kernelspec.get_kernel_spec(k)
        kernel_metadata = local_kernelspec_cache[kernel].metadata
        model_metadata["environment"] = {
            "type": "gcloud",
            "name": get_env_name(),
            "uri": kernel_metadata["google.kernel_container"],
            # local name may not match kernel name on container
            "kernel": kernel_metadata["google.kernel_name"],
        }
        return
      # non-managed notebooks should have correct kernelspec listed
      model_metadata["environment"] = {
          "type": "gcloud",
          "name": get_env_name(),
          "uri": get_env_uri(),
          "kernel": kernel,
      }
  # pylint: disable=broad-except
  except (FileNotFoundError, KeyError, OSError, Exception) as e:
    logging.error("Failed to enrich the Notebook with metadata: %s", e)

# pylint: disable=undefined-variable
c.FileContentsManager.pre_save_hook = metadata_env_pre_save

# Enable debugging
enable_debug = get_attribute_value("notebook-enable-debug")
if handle_attribute_value(enable_debug):
  c.Application.log_level = 0

# Allow cross-site requests
is_managed_notebook = get_attribute_value("runtime-resource-name")
disable_check_xsrf = get_attribute_value("disable-check-xsrf")
if handle_attribute_value(disable_check_xsrf) or is_managed_notebook:
  c.ServerApp.disable_check_xsrf = True

# https://jupyterlab.readthedocs.io/en/stable/user/rtc.html
use_collaborative = get_attribute_value("use-collaborative")
if handle_attribute_value(use_collaborative):
  print("Using JupyterLab Collaborative flag")
  c.LabApp.collaborative = True

disable_downloads = get_attribute_value("notebook-disable-downloads")
if handle_attribute_value(disable_downloads):
  _disable_downloads()

disable_terminal = get_attribute_value("notebook-disable-terminal")
if handle_attribute_value(disable_terminal):
  c.NotebookApp.terminals_enabled = False

c.FileContentsManager.delete_to_trash = False
delete_to_trash = get_attribute_value("notebook-enable-delete-to-trash")
if handle_attribute_value(delete_to_trash):
  c.FileContentsManager.delete_to_trash = True

# Additional scripts append Jupyter configuration. Please keep this line.
Logs Cannot figure out where to see any logs
@welcome
Copy link

welcome bot commented Nov 10, 2022

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant