diff --git a/server/pyproject.toml b/server/pyproject.toml index b59b8254..4ce3a838 100644 --- a/server/pyproject.toml +++ b/server/pyproject.toml @@ -24,6 +24,7 @@ urllib3 = "^2.2.1" pymongo = "<4.9.0" pyjwt = "^2.8.0" bcrypt = "^4.2.0" +prometheus-flask-exporter = "^0.23.1" [tool.poetry.dev-dependencies] pytest = "^8.1.2" diff --git a/server/src/api/v1.py b/server/src/api/v1.py index 4d3b2ecd..7ac5c41b 100644 --- a/server/src/api/v1.py +++ b/server/src/api/v1.py @@ -38,9 +38,14 @@ from . import schemas -jobs_metric = Counter("jobs", "Number of jobs", ["queue"]) +jobs_metric = Counter( + "jobs", "Number of jobs", ["queue"], namespace="testflinger" +) reservations_metric = Counter( - "reservations", "Number of reservations", ["queue"] + "reservations", + "Number of reservations", + ["queue"], + namespace="testflinger", ) diff --git a/server/src/application.py b/server/src/application.py index 33f9cdc5..d0d8062d 100644 --- a/server/src/application.py +++ b/server/src/application.py @@ -29,6 +29,7 @@ from src.api.v1 import v1 from src.providers import ISODatetimeProvider from src.views import views +from .extensions import metrics try: import sentry_sdk @@ -63,6 +64,9 @@ def create_flask_app(config=None): dsn=sentry_dsn, integrations=[FlaskIntegration()] ) + metrics.group_by = "endpoint" + metrics.init_app(tf_app) + @tf_app.errorhandler(NotFound) def handle_404(exc): tf_log.error("[404] Not found: %s", request.url) diff --git a/server/src/extensions.py b/server/src/extensions.py new file mode 100644 index 00000000..28ca4bd5 --- /dev/null +++ b/server/src/extensions.py @@ -0,0 +1,7 @@ +""" +Flask extensions that may be imported by other modules +""" + +from prometheus_flask_exporter import PrometheusMetrics + +metrics = PrometheusMetrics.for_app_factory()