Skip to main content

Hi!

 

We are developing a monitoring solution that depend on deployed Cognite Functions running our Python backend.

 

What is the exact environment for a Cognite Function? How is the container configured? We would like to test our backend code in a runtime environment as close as possible to the deployed environment. Currently we build a docker image and execute our tests within the image based on “FROM python:3.11-slim”, and install all our dependencies here.

 

How can we configure the environment to be as similar as possible to a Cognite Function? Is there a publicly available image we can base our container on that would ensure a more similar environment? Or is our current method “good enough”?

 

All help appreciated!

Anders

Hello Anders!

Thanks for reaching out! 

Currently, we do not provide explicit details about the underlying containers, and there is no publicly available base-image (that is a good idea, maybe something we can look into). Are you asking specifically for the python-environment or for the whole container environment? 

You are correct in that we are basing them off of the python-slim images, so that is definitely a good place to start.
We do however need to install some packages related to our own infrastructure and these might vary over time, which is why we are a bit hesitant to publish a specific set of dependencies. 

 

It is possible to introspect the environment from a running Cognite Function if you are interested in the exact python packages / package versions installed, for instance using the `pip`-package. 

When it comes to what is good enough, I can’t really say from my end. Are you experiencing a lot of issues related to mismatching environments? 

 

Kind regards,

Ivar 


Hi,

In addition to what @Ivar Stangeby is saying, you may want to check out https://developer.cognite.com/sdks/toolkit/references/configs#running-functions-locally

It allows you to run functions in a local environment with environment variables and the right packages installed.

Greger


Thank you for the fast feedback!

We were interested in reproducing not only the python environment but also the more general system environment. The reason we were looking into this is that sometimes we get weird behavior and errors that never occur in our local virtual environment and only in the deployed functions. We are having a hard time reproducing the error consistently, and wanted to eliminate as many variables as possible in our debugging.

@greger Thanks for the tip! I was not aware of this. We will check this out and see if we can incorporate this into our workflow. It looks like it would speed up our testing/debugging significantly!


Reply