diff --git a/api/main.py b/api/main.py index f6a024a..e226678 100644 --- a/api/main.py +++ b/api/main.py @@ -39,7 +39,26 @@ async def lifespan(app: FastAPI): @app.get("/health") -def health(): return {"status": "ok"} +def health(): + return {"status": "ok"} # liveness — am I up? + + +@app.get("/health/ready") +def ready(request: Request): + # readiness — can I actually serve a claim? check deps. + checks = {} + try: + checks["mcp_host"] = bool(request.app.state.host.tools) + except Exception: + checks["mcp_host"] = False + try: + from services.index.store import get_index + get_index().describe_index_stats() + checks["pinecone"] = True + except Exception: + checks["pinecone"] = False + ok = all(checks.values()) + return {"status": "ready" if ok else "degraded", "checks": checks} @app.middleware("http") diff --git a/services/common/log.py b/services/common/log.py new file mode 100644 index 0000000..3b72f01 --- /dev/null +++ b/services/common/log.py @@ -0,0 +1,15 @@ +import logging +import sys + +import structlog + +logging.basicConfig(format="%(message)s", stream=sys.stdout, level=logging.INFO) +structlog.configure(processors=[ + structlog.processors.add_log_level, + structlog.processors.TimeStamper(fmt="iso"), + structlog.processors.JSONRenderer(), # machine-readable JSON lines +]) +log = structlog.get_logger() + +# usage anywhere: +# log.info("claim_decided", claim_id=cid, decision=d, approver=a, latency_ms=ms)