Skip to content

Commit

Permalink
feat: add prometheus metrics (#3640)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Oct 18, 2023
1 parent 01a0798 commit d3eedb5
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Expand Up @@ -8,4 +8,5 @@
!.git
!.gitignore
!Makefile
!gunicorn.conf.py
.git/config
4 changes: 3 additions & 1 deletion Dockerfile
Expand Up @@ -15,7 +15,7 @@ RUN apt-get install --no-install-recommends -y build-essential && \
# time the code changes
# set the BUILD_CORE_SERVICE to non null to install additional service dependencies
ARG BUILD_CORE_SERVICE
COPY pyproject.toml poetry.lock README.rst CHANGES.rst Makefile /code/renku/
COPY pyproject.toml poetry.lock README.rst CHANGES.rst Makefile gunicorn.conf.py /code/renku/
COPY .git /code/renku/.git
COPY renku /code/renku/renku
WORKDIR /code/renku
Expand Down Expand Up @@ -46,6 +46,7 @@ RUN addgroup -gid 1000 shuhitsu && \
if [ -n "${BUILD_CORE_SERVICE}" ]; then mkdir /svc && chown shuhitsu:shuhitsu /svc ; fi

COPY --from=builder /code/renku /code/renku
WORKDIR /code/renku
ENV PATH="${PATH}:/code/renku/.venv/bin"

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

ENTRYPOINT ["tini", "-g", "--", "renku"]
14 changes: 14 additions & 0 deletions gunicorn.conf.py
@@ -0,0 +1,14 @@
"""Gunicorn Configuration."""
import os

from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics


def when_ready(server):
"""Run metrics server on separate port."""
GunicornPrometheusMetrics.start_http_server_when_ready(int(os.getenv("METRICS_PORT", "8765")))


def child_exit(server, worker):
"""Properly exit when metrics server stops."""
GunicornPrometheusMetrics.mark_process_dead_on_child_exit(worker.pid)
41 changes: 35 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Expand Up @@ -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"
Expand Down Expand Up @@ -301,6 +302,7 @@ module = [
"pexpect",
"PIL",
"pluggy",
"prometheus_flask_exporter.*",
"psutil",
"pyld",
"pyshacl",
Expand Down
2 changes: 2 additions & 0 deletions renku/ui/cli/service.py
Expand Up @@ -50,6 +50,8 @@ def run_api(addr="0.0.0.0", port=8080, timeout=600):
"gunicorn",
"renku.ui.service.entrypoint:app",
loading_opt,
"-c",
"gunicorn.conf.py",
"-b",
f"{addr}:{port}",
"--timeout",
Expand Down
5 changes: 5 additions & 0 deletions renku/ui/service/entrypoint.py
Expand Up @@ -22,10 +22,12 @@
import sentry_sdk
from flask import Flask, Response, jsonify, request, url_for
from jwt import InvalidTokenError
from prometheus_flask_exporter.multiprocess import GunicornPrometheusMetrics
from sentry_sdk.integrations.flask import FlaskIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.integrations.rq import RqIntegration

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

app.config["cache"] = cache

if not is_test_session_running():
GunicornPrometheusMetrics(app)

build_routes(app)

@app.route(SERVICE_PREFIX)
Expand Down

0 comments on commit d3eedb5

Please sign in to comment.