I'm pretty puzzled by a good way to create logging from tasks that run inside Docker containers (tha...
v

Vincent Rubingh

12 months ago
I'm pretty puzzled by a good way to create logging from tasks that run inside Docker containers (that reflects correctly in the Cloud UI). I have a flow spinning up a bunch of different docker containers as part of a deployment. However I am not sure what is a good way to handle logging for the individual containers through Prefect. Right now everything is running on the same machine, with a worker on Docker that runs a flow that has various tasks where docker containers are created and run using the prefect.infrastructure.container package. The logging from the containers is piped through to Prefect UI using log_prints=True. However that means there is no proper error handling as everything has the same severity, and errors are not propagated from the containers. It seems there are a few ways to handle this: • Parse the logs after a task is finished. This could work but it's not real-time and any unexpected crashes might prevent this from running as expected • Parse the logs while the container is running by running and connecting to the containers using the python docker package. This might work but I'm introducing another dependency (docker package) and this would not work when the machine is remote. It does not seem this is possible by only using the default prefect python package. • Somehow setup logging inside the container that gets parsed the relevant flow/task information from the worker, so that it can recreate a prefect logger and log everything directly to Prefect It feels like this should be easier and a ready solution should be available however after searching a lot online and trying various options I still haven't found a satisfying solution. Maybe I'm missing something about how Prefect is supposed to be set up and what the philosophy behind it is.