Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ COPY app/pyproject.toml app/poetry.lock* /code/

# Allow installing dev dependencies to run tests
ARG INSTALL_DEV=true
RUN bash -c "poetry lock"
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --with dev --no-root ; else poetry install --no-root --no-dev ; fi"

ENV PYTHONPATH=/code
Expand Down
3 changes: 3 additions & 0 deletions backend/app/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from langchain.globals import set_llm_cache
from pydantic import ValidationError
from starlette.middleware.cors import CORSMiddleware
from prometheus_fastapi_instrumentator import Instrumentator

from app.api.deps import get_redis_client, get_redis_client_sync
from app.api.v1.api import api_router as api_router_v1
Expand Down Expand Up @@ -156,3 +157,5 @@ async def root() -> Dict[str, str]:
prefix=settings.API_V1_STR,
)
add_pagination(app)

Instrumentator().instrument(app).expose(app, endpoint="/metrics")
8 changes: 7 additions & 1 deletion backend/metrics.py → backend/app/app/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@
def metrics():
"""
Expose toutes les métriques au format Prometheus.
Gère les erreurs et retourne un message approprié en cas d'échec.
"""
return Response(generate_latest(), media_type=CONTENT_TYPE_LATEST)
try:
metrics_data = generate_latest()
return Response(metrics_data, media_type=CONTENT_TYPE_LATEST)
except Exception as e:
error_message = f"Erreur lors de la récupération des métriques: {str(e)}"
return Response(error_message, media_type="text/plain", status_code=500)
1 change: 1 addition & 0 deletions backend/app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ watchfiles = "^0.18.1"
wheel = "^0.40.0"
isort = "^5.13.2"
greenlet = "^2.0.2"
prometheus-fastapi-instrumentator = "^7.0.2"
python-dotenv = "^1.0.1"

[tool.poetry.group.dev]
Expand Down
2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"next-auth": "^4.24.5",
"next-pwa": "^5.6.0",
"next-themes": "^0.2.1",
"prom-client": "11.5.3",
"plotly.js-dist-min": "^2.27.1",
"prisma": "^4.14.1",
"react": "18.2.0",
"react-avatar": "^5.0.3",
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/pages/api/metrics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import client from "prom-client"
import type { NextApiRequest, NextApiResponse } from "next"

const register = new client.Registry()
client.collectDefaultMetrics({ register })

export default async function handler(_: NextApiRequest, res: NextApiResponse) {
try {
res.setHeader("Content-Type", register.contentType)
const metrics = await register.metrics() // ✅ Suppression de `.then()`, ajout de `await`
res.send(metrics)
} catch (error) {
res.status(500).json({ error: "Failed to fetch metrics", details: error })
}
}
Loading