diff --git a/infrastructure/backend/.env.template b/infrastructure/backend/.env.template index a9a2480..d5afaff 100644 --- a/infrastructure/backend/.env.template +++ b/infrastructure/backend/.env.template @@ -1,4 +1,4 @@ -DJANGO_SECRET_KEY=secretees +DJANGO_SECRET_KEY=very_insecure_key DJANGO_DEBUG=False DJANGO_ALLOWED_HOSTS=* DJANGO_CSRF_TRUSTED_ORIGINS=http://localhost,http://127.0.0.1 diff --git a/services/backend/config/settings.py b/services/backend/config/settings.py index a1d1102..3e02f5f 100644 --- a/services/backend/config/settings.py +++ b/services/backend/config/settings.py @@ -53,7 +53,7 @@ REDIS_URI = env("REDIS_URI", default="redis://localhost:6379") CACHES = { "default": { - "BACKEND": "django.core.cache.backends.redis.RedisCache", + "BACKEND": "django_prometheus.cache.backends.redis.RedisCache", "LOCATION": REDIS_URI, "TIMEOUT": None, "KEY_PREFIX": "backend", @@ -80,6 +80,9 @@ CELERY_TASK_TRACK_STARTED = True # Database DB_URI = env.db_url("DJANGO_DB_URI", default="sqlite:///db.sqlite3") +DB_URI["ENGINE"] = DB_URI["ENGINE"].replace( + "django.db.backends", "django_prometheus.db.backends" +) DATABASES = {"default": {**DB_URI, "CONN_MAX_AGE": 50}} @@ -284,12 +287,14 @@ INTERNAL_IPS = env( ) MIDDLEWARE = [ + "django_prometheus.middleware.PrometheusBeforeMiddleware", "django_guid.middleware.guid_middleware", "corsheaders.middleware.CorsMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", + "django_prometheus.middleware.PrometheusAfterMiddleware", ] SIGNING_BACKEND = "django.core.signing.TimestampSigner" @@ -442,6 +447,7 @@ INSTALLED_APPS = [ "corsheaders", "django_extensions", "django_guid", + "django_prometheus", "ninja", "minio_storage", # Internal apps @@ -594,3 +600,27 @@ DEBUG_TOOLBAR_CONFIG = {"SHOW_COLLAPSED": True, "UPDATE_ON_FETCH": True} if DEBUG and DEBUG_TOOLBAR_ENABLED: INSTALLED_APPS.append("debug_toolbar") MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware") + + +# Prometheus + +PROMETHEUS_LATENCY_BUCKETS = ( + 0.005, + 0.01, + 0.025, + 0.05, + 0.075, + 0.1, + 0.25, + 0.5, + 0.75, + 1.0, + 2.5, + 5.0, + 7.5, + 10.0, + 25.0, + 50.0, + 75.0, + float("inf"), +) diff --git a/services/backend/config/urls.py b/services/backend/config/urls.py index f553970..de80844 100644 --- a/services/backend/config/urls.py +++ b/services/backend/config/urls.py @@ -16,6 +16,8 @@ urlpatterns = [ path("admin/", admin.site.urls), # API urls path("", include("api.urls")), + # Prometheus urls + path("", include("django_prometheus.urls")), ] diff --git a/services/backend/pyproject.toml b/services/backend/pyproject.toml index 14b0da1..7fb3c8a 100644 --- a/services/backend/pyproject.toml +++ b/services/backend/pyproject.toml @@ -9,6 +9,8 @@ dependencies = [ "django-health-check>=3.18.3,<4.0.0", "django-minio-storage>=0.5.7,<0.6.0", "django-ninja>=1.3.0,<2.0.0", + "django-prometheus>=2.4.1,<3.0.0", + "django-redis>=6.0.0,<7.0.0", "django-stubs-ext>=5.1.3,<6.0.0", "gunicorn>=23.0.0,<24.0.0", "httpx>=0.28.1,<0.29.0",