Server#

This module contains code for generating the Gordo server Flask application.

Running this module will run the application using Flask’s development webserver. Gunicorn can be used to run the application as gevent async workers by using the run_server() function.

class gordo.server.server.Config[source]#

Bases: object

Server config

gordo.server.server.adapt_proxy_deployment(wsgi_app: Callable) Callable[source]#

Decorator specific to fixing behind-proxy-issues when on Kubernetes and using Envoy proxy.

Parameters:

wsgi_app – The underlying WSGI application of a flask app, for example

Notes

Special note about deploying behind Ambassador, or prefixed proxy paths in general:

When deployed on kubernetes/ambassador there is a prefix in-front of the server. ie:

/gordo/v0/some-project-name/some-target

The server itself only knows about routes to the right of such a prefix: such as /metadata or /predictions when in reality, the full path is:

/gordo/v0/some-project-name/some-target/metadata

This is solved by getting the current application’s assigned prefix, where HTTP_X_ENVOY_ORIGINAL_PATH is the full path, including the prefix. and PATH_INFO is the actual relative path the server knows about.

This function wraps the WSGI app itself to map the current full path to the assigned route function.

ie. /metadata -> metadata route function, by default, but updates /gordo/v0/some-project-name/some-target/metadata -> metadata route function

Example

>>> app = Flask(__name__)
>>> app.wsgi_app = adapt_proxy_deployment(app.wsgi_app)
gordo.server.server.build_app(config: Dict[str, Any] | None = None, prometheus_registry: CollectorRegistry | None = None)[source]#

Build app and any associated routes

gordo.server.server.create_prometheus_metrics(project: str | None = None, registry: CollectorRegistry | None = None) GordoServerPrometheusMetrics[source]#
gordo.server.server.enable_prometheus()[source]#
gordo.server.server.run_cmd(cmd)[source]#

Run a shell command and handle CalledProcessError and OSError types

Note

This function is abstracted from run_server() in order to test the calling of commands that would allow the subprocess call to break, depending on how it is parameterized. For example, calling this without sending stderr to stdout will cause a segmentation fault when calling an executable that does not exist.

gordo.server.server.run_server(host: str, port: int, workers: int, log_level: str, config_module: str | None = None, worker_connections: int | None = None, threads: int | None = None, worker_class: str = 'gthread', server_app: str = 'gordo.server.server:build_app()')[source]#

Run application with Gunicorn server using Gevent Async workers

Parameters:
  • host – The host to run the server on.

  • port – The port to run the server on.

  • workers – The number of worker processes for handling requests.

  • log_level – The log level for the gunicorn webserver. Valid log level names can be found in the [gunicorn documentation](http://docs.gunicorn.org/en/stable/settings.html#loglevel).

  • config_module – The config module. Will be passed with python: [prefix](https://docs.gunicorn.org/en/stable/settings.html#config).

  • worker_connections – The maximum number of simultaneous clients per worker process.

  • threads – The number of worker threads for handling requests.

  • worker_class – The type of workers to use.

  • server_app – The application to run