diff --git a/zou/app/__init__.py b/zou/app/__init__.py index 9597bcc5a1..9111259a32 100644 --- a/zou/app/__init__.py +++ b/zou/app/__init__.py @@ -162,24 +162,31 @@ def add_permissions(_, payload): def load_api(): from zou.app import api + from zou.app.utils import permissions from zou import __version__ as zou_version api.configure(app) - try: - from prometheus_flask_exporter.multiprocess import ( - GunicornPrometheusMetrics, - ) - - metrics = GunicornPrometheusMetrics( - app, defaults_prefix="zou", group_by="url_rule" - ) - except ValueError: - from prometheus_flask_exporter import RESTfulPrometheusMetrics - metrics = RESTfulPrometheusMetrics( - app, api, defaults_prefix="zou", group_by="url_rule" - ) - metrics.info("zou_info", "Application info", version=zou_version) + if config.PROMETHEUS_METRICS_ENABLED: + try: + from prometheus_flask_exporter.multiprocess import ( + GunicornPrometheusMetrics, + ) + + metrics = GunicornPrometheusMetrics( + app, defaults_prefix="zou", group_by="url_rule" + ) + except ValueError: + from prometheus_flask_exporter import RESTfulPrometheusMetrics + + metrics = RESTfulPrometheusMetrics( + app, + api, + defaults_prefix="zou", + group_by="url_rule", + metrics_decorator=permissions.require_admin, + ) + metrics.info("zou_info", "Application info", version=zou_version) fs.mkdir_p(app.config["TMP_DIR"]) configure_auth() diff --git a/zou/app/config.py b/zou/app/config.py index 3f47cb152c..96080656b2 100644 --- a/zou/app/config.py +++ b/zou/app/config.py @@ -135,6 +135,8 @@ SENTRY_SR = float(os.getenv("SENTRY_SR", 1.0)) SENTRY_DEBUG_URL = os.getenv("SENTRY_DEBUG_URL", False) +PROMETHEUS_METRICS_ENABLED = envtobool("PROMETHEUS_METRICS_ENABLED", False) + CRISP_TOKEN = os.getenv("CRISP_TOKEN", "") DEFAULT_TIMEZONE = os.getenv("DEFAULT_TIMEZONE", "Europe/Paris")