Skip to content

Commit

Permalink
v0.6.3
Browse files Browse the repository at this point in the history
configure root_path from fast_api via env vars
  • Loading branch information
SCHWMAX committed Nov 27, 2024
1 parent 9855913 commit 4e0a8d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
sha$${{ github.sha }}
sha$${{ env.SHORT_COMMIT }}
date$${{ env.CURRENT_DATE }}
v0.6.2
v0.6.3
- name: Login to Docker Hub
uses: docker/login-action@v3
Expand Down
11 changes: 9 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
# Setup logging
logger = setup_logging(__name__)


# lifespan
@asynccontextmanager
async def lifespan(app: FastAPI):
Expand Down Expand Up @@ -84,7 +83,15 @@ async def lifespan(app: FastAPI):
}

# setup of fastAPI server
app = default_fastapi_setup(title, summary, description, license_info, contact, lifespan=lifespan)
app = default_fastapi_setup(
title,
summary,
description,
license_info,
contact,
lifespan=lifespan,
root_path=default_from_env(["FASTAPI_ROOT_PATH", "ROOT_PATH"], None)
)
# set up /metrics endpoint for prometheus
EXECUTION_COUNTER, EXCEPTION_COUNTER, EXECUTION_TIMING = setup_prometheus_metrics(
app,
Expand Down
21 changes: 15 additions & 6 deletions utils_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,19 @@ def default_fastapi_setup(
license_info: Union[str, Dict[str, Any]] = None,
contact: Union[str, Dict[str, Any]] = None,
lifespan=None,
root_path=None
):
if license_info is None:
license_info = {
"name": "MIT License",
"url": "https://github.com/max-scw/MinimalImageInference/blob/main/LICENSE",
}

if contact is None:
contact = {
"name": "max-scw",
"url": "https://github.com/max-scw/",
}

app = FastAPI(
title=title,
Expand All @@ -48,7 +60,8 @@ def default_fastapi_setup(
contact=contact,
license_info=license_info,
lifespan=lifespan,
docs_url=None
docs_url=None,
root_path=root_path if root_path else None
)

# ----- home
Expand Down Expand Up @@ -85,8 +98,6 @@ def setup_prometheus_metrics(
entrypoints_to_track: list
) -> Tuple[Dict[str, Counter], Dict[str, Counter], Dict[str, Gauge]]:
# set up /metrics endpoint for prometheus
# metrics_app = make_asgi_app()
# app.mount("/metrics", metrics_app)
@app.get("/metrics")
async def metrics(token = AccessToken):
return Response(generate_latest(), media_type="text/plain")
Expand All @@ -97,7 +108,7 @@ async def metrics(token = AccessToken):
name = ep.strip("/").replace("/", "_").replace("-", "")
execution_counter[ep] = Counter(
name=name,
documentation=f"Counts how often the entry point {ep} is called."
documentation=f"Counts how often the entry point {ep} was called."
)
exception_counter[ep] = Counter(
name=name + "_exception",
Expand All @@ -108,5 +119,3 @@ async def metrics(token = AccessToken):
documentation=f"Latest execution time of the entry point {ep}."
)
return execution_counter, exception_counter, execution_timing


0 comments on commit 4e0a8d8

Please sign in to comment.