From 689929cbc5cb80c63f5478a9ab50809e46138f92 Mon Sep 17 00:00:00 2001 From: Ralf Grubenmann Date: Fri, 13 Oct 2023 09:59:52 +0200 Subject: [PATCH] feat: add prometheus metrics --- poetry.lock | 41 +++++++++++++++++++++++++++++----- pyproject.toml | 2 ++ renku/ui/service/entrypoint.py | 3 +++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/poetry.lock b/poetry.lock index 8c9fdcea1d..8b13e0673f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. [[package]] name = "addict" @@ -749,8 +749,8 @@ files = [ [package.dependencies] "ruamel.yaml" = [ {version = ">=0.16.0,<0.18", markers = "python_version >= \"3.10\""}, - {version = ">=0.15.78,<0.18", markers = "python_version >= \"3.8\""}, - {version = ">=0.15.98,<0.18", markers = "python_version >= \"3.9\""}, + {version = ">=0.15.98,<0.18", markers = "python_version >= \"3.9\" and python_version < \"3.10\""}, + {version = ">=0.15.78,<0.18", markers = "python_version >= \"3.8\" and python_version < \"3.9\""}, ] schema-salad = "*" setuptools = "*" @@ -1040,7 +1040,7 @@ files = [ name = "flask" version = "2.2.5" description = "A simple framework for building complex web applications." -optional = true +optional = false python-versions = ">=3.7" files = [ {file = "Flask-2.2.5-py3-none-any.whl", hash = "sha256:58107ed83443e86067e41eff4631b058178191a355886f8e479e347fa1285fdf"}, @@ -1357,7 +1357,7 @@ requirements-deprecated-finder = ["pip-api", "pipreqs"] name = "itsdangerous" version = "2.1.2" description = "Safely pass data to untrusted environments and back." -optional = true +optional = false python-versions = ">=3.7" files = [ {file = "itsdangerous-2.1.2-py3-none-any.whl", hash = "sha256:2c2349112351b88699d8d4b6b075022c0808887cb7ad10069318a8b0bc88db44"}, @@ -2390,6 +2390,35 @@ wcwidth = "*" [package.extras] tests = ["pytest", "pytest-cov", "pytest-lazy-fixture"] +[[package]] +name = "prometheus-client" +version = "0.17.1" +description = "Python client for the Prometheus monitoring system." +optional = false +python-versions = ">=3.6" +files = [ + {file = "prometheus_client-0.17.1-py3-none-any.whl", hash = "sha256:e537f37160f6807b8202a6fc4764cdd19bac5480ddd3e0d463c3002b34462101"}, + {file = "prometheus_client-0.17.1.tar.gz", hash = "sha256:21e674f39831ae3f8acde238afd9a27a37d0d2fb5a28ea094f0ce25d2cbf2091"}, +] + +[package.extras] +twisted = ["twisted"] + +[[package]] +name = "prometheus-flask-exporter" +version = "0.22.4" +description = "Prometheus metrics exporter for Flask" +optional = false +python-versions = "*" +files = [ + {file = "prometheus_flask_exporter-0.22.4-py3-none-any.whl", hash = "sha256:e130179c26d5a9b903c12c0d8826127ae491b04b298cae0b92b98677dcf2c06f"}, + {file = "prometheus_flask_exporter-0.22.4.tar.gz", hash = "sha256:959b69f1e740b6736ea53fe5f28dc2ab6229b2ebeade6582b3dbb5d74c7d58e4"}, +] + +[package.dependencies] +flask = "*" +prometheus-client = "*" + [[package]] name = "prov" version = "1.5.1" @@ -4582,4 +4611,4 @@ service = ["apispec", "apispec-oneofschema", "apispec-webframeworks", "circus", [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<3.12" -content-hash = "a75f7197bf53bde1db069a16c1192aa982dbdf84d6c864bb032f8f764c34f154" +content-hash = "1649b695abc65d476919f07e320a2675210a1232d59897783aa66359f0163af3" diff --git a/pyproject.toml b/pyproject.toml index e4633b2b7c..cc77e4c256 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -114,6 +114,7 @@ redis = { version = ">=3.5.3,<4.6.0,!=4.5.5", optional = true } rq = { version = "==1.15.0", optional = true } sentry-sdk = { version = ">=1.5.11,<1.26.0", extras = ["flask"], optional = true } walrus = { version = ">=0.8.2,<0.10.0", optional = true } +prometheus-flask-exporter = "^0.22.4" [tool.poetry.group.dev.dependencies] black = "==23.1.0" @@ -301,6 +302,7 @@ module = [ "pexpect", "PIL", "pluggy", + "prometheus_flask_exporter", "psutil", "pyld", "pyshacl", diff --git a/renku/ui/service/entrypoint.py b/renku/ui/service/entrypoint.py index 1571c5ebda..b45a8136fd 100644 --- a/renku/ui/service/entrypoint.py +++ b/renku/ui/service/entrypoint.py @@ -22,6 +22,7 @@ import sentry_sdk from flask import Flask, Response, jsonify, request, url_for from jwt import InvalidTokenError +from prometheus_flask_exporter import PrometheusMetrics from sentry_sdk.integrations.flask import FlaskIntegration from sentry_sdk.integrations.redis import RedisIntegration from sentry_sdk.integrations.rq import RqIntegration @@ -73,6 +74,8 @@ def create_app(custom_exceptions=True): app.config["MAX_CONTENT_LENGTH"] = MAX_CONTENT_LENGTH app.config["cache"] = cache + metrics = PrometheusMetrics.for_app_factory() + metrics.init_app(app) build_routes(app)