Jupyter Ecological Secondary Development Series (4)

Because Party A’s “data scientist” often executes some dangerous codes or commands without knowing it, and the lab itself does not record the user’s operation records, which leads to some data being deleted and no one can find it, so we must give jupyter Add the code and terminal execution log to prevent Party A from throwing the pot. It is also a last resort. 

The jupyterlab we used for the "data scientists" of Party A is placed in the k8s pod, which is considered a cloud platform. I will talk about the architecture design of our private data cloud when we have time. Now we are working on the internal data application of the big boss. , Do not have time.

The notebook is embedded in jupyterlab, the actual notebook execution is in jupyter_client, and jupyterlab uses jupyter_server to push the code in the notebook code cell to the zeromq queue to send to ipython for execution, and then jupyter_client consumes the execution result of the zmq queue, and then gives the notebook echo In short, it is a very complicated process. In detail, the execution process of import os can't be drawn on an A4.

Jupyter_client and notebook are embedded in jupyterlab, so the log of client and nb cannot be displayed in lab and server. I did not study it in detail. It should be said that the tornado log objects on both sides of C/S have no inheritance relationship. .

Then to log in the lab log, you can only start with lab and server.Lab itself is just a framework and does not execute code, and server is related to executing code, so modifying the server should be the most correct choice.

Then, find the part of the code execution in the server and write it to self.log.warn. It is still very easy to find. Jupyter's notebook and terminal are executed by websocket, so just find the tornaod handler class related to websocket Enough.

image.png

The following is the execution log of terminal

image.png


In short, we don't prevent "data scientists" from executing stupid commands and codes, but we don't prevent Party A from dumping the pot.

Guess you like

Origin blog.51cto.com/slaytanic/2634231