Skip to content

Commit d3eedb5

Browse files
authored
feat: add prometheus metrics (#3640)
1 parent 01a0798 commit d3eedb5

File tree

7 files changed

+62
-7
lines changed

7 files changed

+62
-7
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
!.git
99
!.gitignore
1010
!Makefile
11+
!gunicorn.conf.py
1112
.git/config

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN apt-get install --no-install-recommends -y build-essential && \
1515
# time the code changes
1616
# set the BUILD_CORE_SERVICE to non null to install additional service dependencies
1717
ARG BUILD_CORE_SERVICE
18-
COPY pyproject.toml poetry.lock README.rst CHANGES.rst Makefile /code/renku/
18+
COPY pyproject.toml poetry.lock README.rst CHANGES.rst Makefile gunicorn.conf.py /code/renku/
1919
COPY .git /code/renku/.git
2020
COPY renku /code/renku/renku
2121
WORKDIR /code/renku
@@ -46,6 +46,7 @@ RUN addgroup -gid 1000 shuhitsu && \
4646
if [ -n "${BUILD_CORE_SERVICE}" ]; then mkdir /svc && chown shuhitsu:shuhitsu /svc ; fi
4747

4848
COPY --from=builder /code/renku /code/renku
49+
WORKDIR /code/renku
4950
ENV PATH="${PATH}:/code/renku/.venv/bin"
5051

5152
# shuhitsu (執筆): The "secretary" of the renga, as it were, who is responsible for
@@ -55,5 +56,6 @@ USER shuhitsu
5556
ENV RENKU_SVC_NUM_WORKERS 4
5657
ENV RENKU_SVC_NUM_THREADS 8
5758
ENV RENKU_DISABLE_VERSION_CHECK=1
59+
ENV PROMETHEUS_MULTIPROC_DIR /tmp
5860

5961
ENTRYPOINT ["tini", "-g", "--", "renku"]

gunicorn.conf.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Gunicorn Configuration."""
2+
import os
3+
4+
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics
5+
6+
7+
def when_ready(server):
8+
"""Run metrics server on separate port."""
9+
GunicornPrometheusMetrics.start_http_server_when_ready(int(os.getenv("METRICS_PORT", "8765")))
10+
11+
12+
def child_exit(server, worker):
13+
"""Properly exit when metrics server stops."""
14+
GunicornPrometheusMetrics.mark_process_dead_on_child_exit(worker.pid)

poetry.lock

Lines changed: 35 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ redis = { version = ">=3.5.3,<4.6.0,!=4.5.5", optional = true }
114114
rq = { version = "==1.15.0", optional = true }
115115
sentry-sdk = { version = ">=1.5.11,<1.26.0", extras = ["flask"], optional = true }
116116
walrus = { version = ">=0.8.2,<0.10.0", optional = true }
117+
prometheus-flask-exporter = "^0.22.4"
117118

118119
[tool.poetry.group.dev.dependencies]
119120
black = "==23.1.0"
@@ -301,6 +302,7 @@ module = [
301302
"pexpect",
302303
"PIL",
303304
"pluggy",
305+
"prometheus_flask_exporter.*",
304306
"psutil",
305307
"pyld",
306308
"pyshacl",

renku/ui/cli/service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def run_api(addr="0.0.0.0", port=8080, timeout=600):
5050
"gunicorn",
5151
"renku.ui.service.entrypoint:app",
5252
loading_opt,
53+
"-c",
54+
"gunicorn.conf.py",
5355
"-b",
5456
f"{addr}:{port}",
5557
"--timeout",

renku/ui/service/entrypoint.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import sentry_sdk
2323
from flask import Flask, Response, jsonify, request, url_for
2424
from jwt import InvalidTokenError
25+
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics
2526
from sentry_sdk.integrations.flask import FlaskIntegration
2627
from sentry_sdk.integrations.redis import RedisIntegration
2728
from sentry_sdk.integrations.rq import RqIntegration
2829

30+
from renku.core.util.util import is_test_session_running
2931
from renku.ui.service.cache import cache
3032
from renku.ui.service.config import CACHE_DIR, MAX_CONTENT_LENGTH, SENTRY_ENABLED, SENTRY_SAMPLERATE, SERVICE_PREFIX
3133
from renku.ui.service.errors import (
@@ -74,6 +76,9 @@ def create_app(custom_exceptions=True):
7476

7577
app.config["cache"] = cache
7678

79+
if not is_test_session_running():
80+
GunicornPrometheusMetrics(app)
81+
7782
build_routes(app)
7883

7984
@app.route(SERVICE_PREFIX)

0 commit comments

Comments
 (0)