replace pymysql with mysqlclient as it is "better"; also fix an issue in the ui exporter that had wrong imports

This commit is contained in:
Viktor Barzin 2025-10-18 09:58:55 +00:00
parent 0801aaf200
commit ced9a153bd
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
4 changed files with 46 additions and 20 deletions

View file

@ -18,6 +18,15 @@ from fastapi.middleware.cors import CORSMiddleware
from tasks import listing_tasks
from ui_exporter import export_immoweb
from alembic import command
from alembic.config import Config
from contextlib import asynccontextmanager
from celery.exceptions import TaskRevokedError
from celery_app import app as celery_app
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from api.metrics import metrics_app # Import the Prometheus ASGI app
from opentelemetry.metrics import get_meter
load_dotenv()
logger = logging.getLogger("uvicorn")
@ -35,6 +44,16 @@ logger = logging.getLogger("uvicorn")
# app = FastAPI(lifespan=lifespan)
app = FastAPI()
app.mount("/metrics", metrics_app)
meter = get_meter(__name__)
request_counter = meter.create_counter(
name="custom_request_count",
description="Number of times /hello was called",
)
hist = meter.create_histogram(
name="custom_request_duration",
description="Duration of /hello requests in seconds",
)
# Allow CORS (for React frontend)
@ -48,6 +67,8 @@ app.add_middleware(
@app.get("/api/status")
async def get_status():
request_counter.add(1, {"method": "GET", "path": "/status"})
hist.record(1.5, {"method": "GET", "path": "/status"})
return {"status": "OK"}
@ -125,3 +146,6 @@ async def get_districts(
user: Annotated[User, Depends(get_current_user)],
) -> dict[str, str]:
return districts.get_districts()
FastAPIInstrumentor.instrument_app(app)