-
Notifications
You must be signed in to change notification settings - Fork 0
BigQuery datastore backend: real CRUD + Frictionless schemas + lifespan health #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
367de4c
5435e0b
efc9214
5eb5016
7a0b7e5
432de8a
a2a8e0d
6497955
0a1769b
6d871e3
700e322
2bf0577
0876789
f13589c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,59 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from types import SimpleNamespace | ||
|
|
||
| from fastapi import APIRouter | ||
| from starlette.requests import Request | ||
| from starlette.responses import JSONResponse | ||
|
|
||
| from datastore.api.responses import _success_response | ||
| from datastore.core.config import get_config | ||
| from datastore.infrastructure.engines.registry import get_datastore_engine | ||
| from datastore.schemas.responses import StatusResponse, WelcomeResponse | ||
|
|
||
| router = APIRouter(tags=["health"]) | ||
| welcome_router = APIRouter(tags=["health"]) | ||
|
|
||
|
|
||
| probe_router = APIRouter(tags=["health"]) | ||
|
|
||
| @router.get("/", response_model=WelcomeResponse) | ||
|
|
||
| @welcome_router.get("/", response_model=WelcomeResponse) | ||
| def welcome(request: Request): | ||
| return _success_response( | ||
| request, | ||
| WelcomeResponse.Result(message=get_config().APP_MESSAGE), | ||
| ) | ||
|
|
||
| @router.get("/health", response_model=StatusResponse) | ||
|
|
||
| @probe_router.get("/health", response_model=StatusResponse) | ||
| def health(request: Request): | ||
| """Liveness — always 200 while the process is up.""" | ||
| return _success_response(request, StatusResponse.Result(status="ok")) | ||
|
|
||
|
|
||
| @router.get("/ready", response_model=StatusResponse) | ||
| @probe_router.get("/ready", response_model=StatusResponse) | ||
| def ready(request: Request): | ||
| """Readiness — 200 when both rw and ro engines pass `healthcheck()`, | ||
| 503 otherwise. Probes both modes because the credential split means | ||
| one can fail while the other works.""" | ||
| ctx = SimpleNamespace(config=get_config()) | ||
|
|
||
| failing: list[str] = [] | ||
| for mode in ("rw", "ro"): | ||
| try: | ||
| engine = get_datastore_engine(ctx, mode=mode) # type: ignore[arg-type] | ||
| if not engine.healthcheck(): | ||
| failing.append(mode) | ||
| except Exception: | ||
| failing.append(mode) | ||
|
|
||
| if failing: | ||
| return JSONResponse( | ||
| status_code=503, | ||
| content={ | ||
| "help": str(request.url), | ||
| "success": False, | ||
| "result": {"status": "not_ready"}, | ||
| }, | ||
| ) | ||
|
Comment on lines
+50
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep The 503 branch returns an As per coding guidelines " 🤖 Prompt for AI Agents |
||
| return _success_response(request, StatusResponse.Result(status="ready")) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep
.env.examplealigned with the actual settings model.HTTP_MAX_CONNECTIONSandHTTP_MAX_KEEPALIVE_CONNECTIONSare documented here, butdatastore/core/config.pydoes not declare either field, sopydantic-settingswill silently ignore them.INCLUDE_UPDATED_ATwas added toConfigas well, but operators still don't get an example for that toggle here.Also applies to: 26-27
🧰 Tools
🪛 dotenv-linter (4.0.0)
[warning] 15-15: [UnorderedKey] The BIGQUERY_PROJECT key should go before the DATASTORE_ENGINE key
(UnorderedKey)
[warning] 16-16: [UnorderedKey] The BIGQUERY_DATASET key should go before the BIGQUERY_PROJECT key
(UnorderedKey)
[warning] 17-17: [UnorderedKey] The BIGQUERY_CREDENTIALS key should go before the BIGQUERY_DATASET key
(UnorderedKey)
[warning] 18-18: [UnorderedKey] The BIGQUERY_CREDENTIALS_RO key should go before the BIGQUERY_DATASET key
(UnorderedKey)
🤖 Prompt for AI Agents