diff --git a/Dockerfile b/Dockerfile index d34b417..698f8b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # https://pythonspeed.com/articles/base-image-python-docker-images/ # https://testdriven.io/blog/docker-best-practices/ -FROM python:3.10-slim-bullseye +FROM python:3.11-slim-bullseye RUN apt-get update && apt-get install -y build-essential @@ -36,5 +36,5 @@ COPY --chown=app:app src/ /app/src/ EXPOSE 8000 # https://stackoverflow.com/questions/29663459/python-app-does-not-print-anything-when-running-detached-in-docker -CMD ["python", "-m", "uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"] +CMD ["python", "-m", "fastapi", "run", "src/main.py"] diff --git a/fly.toml b/fly.toml index 9f884c8..a350fd3 100644 --- a/fly.toml +++ b/fly.toml @@ -1,29 +1,30 @@ -# fly.toml app configuration file generated for honcho-restless-dew-484 on 2024-01-18T08:20:57-08:00 -# # See https://fly.io/docs/reference/configuration/ for information about how to use this file. -# -app = "honcho" -kill_signal = "SIGINT" -kill_timeout = "5s" +app = 'honcho' +primary_region = 'ewr' +kill_signal = 'SIGINT' +kill_timeout = '5s' + +[build] [processes] - api = "python -m uvicorn src.main:app --host 0.0.0.0 --port 8000" - deriver = "python -m src.deriver" + api = 'python -m fastapi run src/main.py' + deriver = 'python -m src.deriver' [http_service] internal_port = 8000 - auto_stop_machines = false + auto_stop_machines = 'off' auto_start_machines = true min_machines_running = 1 - processes = ["api"] + processes = ['api'] + [http_service.concurrency] - type = "requests" + type = 'requests' hard_limit = 250 soft_limit = 200 [[vm]] - cpu_kind = "shared" + memory = '512mb' + cpu_kind = 'shared' cpus = 1 - memory_mb = 512 - processes = ["api", "deriver"] + processes = ['api', 'deriver'] diff --git a/poetry.lock b/poetry.lock index 3e87778..b5e2271 100644 --- a/poetry.lock +++ b/poetry.lock @@ -710,24 +710,6 @@ docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.link perf = ["ipython"] testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)", "pytest-ruff"] -[[package]] -name = "importlib-resources" -version = "6.4.0" -description = "Read resources from Python packages" -optional = false -python-versions = ">=3.8" -files = [ - {file = "importlib_resources-6.4.0-py3-none-any.whl", hash = "sha256:50d10f043df931902d4194ea07ec57960f66a80449ff867bfe782b4c486ba78c"}, - {file = "importlib_resources-6.4.0.tar.gz", hash = "sha256:cdb2b453b8046ca4e3798eb1d84f3cce1446a0e8e7b5ef4efb600f19fc398145"}, -] - -[package.dependencies] -zipp = {version = ">=3.1.0", markers = "python_version < \"3.10\""} - -[package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-lint"] -testing = ["jaraco.test (>=5.4)", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy", "pytest-ruff (>=0.2.1)", "zipp (>=3.17)"] - [[package]] name = "iniconfig" version = "2.0.0" @@ -781,35 +763,6 @@ MarkupSafe = ">=2.0" [package.extras] i18n = ["Babel (>=2.7)"] -[[package]] -name = "limits" -version = "3.13.0" -description = "Rate limiting utilities" -optional = false -python-versions = ">=3.8" -files = [ - {file = "limits-3.13.0-py3-none-any.whl", hash = "sha256:9767f7233da4255e9904b79908a728e8ec0984c0b086058b4cbbd309aea553f6"}, - {file = "limits-3.13.0.tar.gz", hash = "sha256:6571b0c567bfa175a35fed9f8a954c0c92f1c3200804282f1b8f1de4ad98a953"}, -] - -[package.dependencies] -deprecated = ">=1.2" -importlib-resources = ">=1.3" -packaging = ">=21,<25" -typing-extensions = "*" - -[package.extras] -all = ["aetcd", "coredis (>=3.4.0,<5)", "emcache (>=0.6.1)", "emcache (>=1)", "etcd3", "motor (>=3,<4)", "pymemcache (>3,<5.0.0)", "pymongo (>4.1,<5)", "redis (>3,!=4.5.2,!=4.5.3,<6.0.0)", "redis (>=4.2.0,!=4.5.2,!=4.5.3)"] -async-etcd = ["aetcd"] -async-memcached = ["emcache (>=0.6.1)", "emcache (>=1)"] -async-mongodb = ["motor (>=3,<4)"] -async-redis = ["coredis (>=3.4.0,<5)"] -etcd = ["etcd3"] -memcached = ["pymemcache (>3,<5.0.0)"] -mongodb = ["pymongo (>4.1,<5)"] -redis = ["redis (>3,!=4.5.2,!=4.5.3,<6.0.0)"] -rediscluster = ["redis (>=4.2.0,!=4.5.2,!=4.5.3)"] - [[package]] name = "markdown-it-py" version = "3.0.0" @@ -1787,23 +1740,6 @@ files = [ {file = "shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de"}, ] -[[package]] -name = "slowapi" -version = "0.1.9" -description = "A rate limiting extension for Starlette and Fastapi" -optional = false -python-versions = ">=3.7,<4.0" -files = [ - {file = "slowapi-0.1.9-py3-none-any.whl", hash = "sha256:cfad116cfb84ad9d763ee155c1e5c5cbf00b0d47399a769b227865f5df576e36"}, - {file = "slowapi-0.1.9.tar.gz", hash = "sha256:639192d0f1ca01b1c6d95bf6c71d794c3a9ee189855337b4821f7f457dddad77"}, -] - -[package.dependencies] -limits = ">=2.3" - -[package.extras] -redis = ["redis (>=3.4.1,<4.0.0)"] - [[package]] name = "sniffio" version = "1.3.1" @@ -2399,4 +2335,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "f9a40ce12efcdba7d8455722924e3669e9399102180ea0581cf5e3f4e4300b73" +content-hash = "674952f198658bfdfbc530e537662ef7460632e182769c36bfddc882084a7b14" diff --git a/pyproject.toml b/pyproject.toml index cd6a276..776ed16 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,6 @@ python = "^3.9" fastapi = "^0.111.0" python-dotenv = "^1.0.0" sqlalchemy = "^2.0.30" -slowapi = "^0.1.9" fastapi-pagination = "^0.12.24" pgvector = "^0.2.5" openai = "^1.12.0" diff --git a/src/main.py b/src/main.py index 0cae8d4..5df7e0d 100644 --- a/src/main.py +++ b/src/main.py @@ -34,10 +34,6 @@ ConsoleSpanExporter, SimpleSpanProcessor, ) -from slowapi import Limiter, _rate_limit_exceeded_handler -from slowapi.errors import RateLimitExceeded -from slowapi.middleware import SlowAPIMiddleware -from slowapi.util import get_remote_address from starlette.exceptions import HTTPException as StarletteHTTPException from src.routers import ( @@ -230,18 +226,6 @@ async def lifespan(app: FastAPI): router = APIRouter(prefix="/apps/{app_id}/users/{user_id}") -# Create a Limiter instance -limiter = Limiter(key_func=get_remote_address, default_limits=["100/minute"]) - -# Add SlowAPI middleware to the application -app.state.limiter = limiter -app.add_exception_handler( - exc_class_or_status_code=RateLimitExceeded, - handler=_rate_limit_exceeded_handler, # type: ignore -) -app.add_middleware(SlowAPIMiddleware) - - add_pagination(app) @@ -249,13 +233,11 @@ async def lifespan(app: FastAPI): async def http_exception_handler(request, exc): current_span = trace.get_current_span() if (current_span is not None) and (current_span.is_recording()): - current_span.set_attributes( - { - "http.status_text": str(exc.detail), - "otel.status_description": f"{exc.status_code} / {str(exc.detail)}", - "otel.status_code": "ERROR", - } - ) + current_span.set_attributes({ + "http.status_text": str(exc.detail), + "otel.status_description": f"{exc.status_code} / {str(exc.detail)}", + "otel.status_code": "ERROR", + }) return PlainTextResponse( json.dumps({"detail": str(exc.detail)}), status_code=exc.status_code )