- Updated `ready.py` to include a health check for the new `products_nav_history` endpoint, ensuring system readiness. - Enhanced the `ProductNavChartPanel` component to visualize historical NAV data with various charting options, including line and column charts. - Introduced new utility functions for filtering and aggregating NAV data, improving data handling in the frontend. - Updated tests to verify the inclusion of the new `products_nav_history` check in the API response. - Improved documentation to reflect recent changes and the new testing baseline of 833 passed tests, indicating enhanced stability. This update significantly improves the product API by providing access to historical NAV data and enhancing user insights through visualizations.
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
"""启动自检:Redis + 关键路由是否挂载(前端 Topbar 条用)。"""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, FastAPI, Request
|
|
|
|
from app.config.settings import settings
|
|
|
|
router = APIRouter(tags=["platform"])
|
|
|
|
|
|
def build_ready_payload(app: FastAPI, trace_id: str) -> dict:
|
|
checks: dict[str, bool | str] = {}
|
|
|
|
try:
|
|
from app.service.risk import redis_gateway
|
|
|
|
gw = redis_gateway.get_gateway()
|
|
gw.ping()
|
|
checks["redis"] = True
|
|
except Exception as exc: # noqa: BLE001
|
|
checks["redis"] = False
|
|
checks["redis_error"] = str(exc)[:120]
|
|
|
|
paths = set(app.openapi().get("paths", {}).keys())
|
|
checks["chat_close_all"] = "/api/chat/sessions/close-all" in paths
|
|
checks["chat_sessions"] = "/api/chat/sessions" in paths
|
|
checks["analyst_chat"] = "/api/analyst/chat" in paths
|
|
checks["products_nav_history"] = "/api/products/{product_id}/nav/history" in paths
|
|
|
|
critical = [
|
|
checks["chat_close_all"],
|
|
checks["chat_sessions"],
|
|
checks["analyst_chat"],
|
|
checks["products_nav_history"],
|
|
]
|
|
routes_ok = all(critical)
|
|
redis_ok = checks.get("redis") is True
|
|
ok = routes_ok
|
|
return {
|
|
"ok": ok,
|
|
"degraded": routes_ok and not redis_ok,
|
|
"env": settings.app_env,
|
|
"trace_id": trace_id,
|
|
"checks": checks,
|
|
}
|
|
|
|
|
|
@router.get("/api/ready")
|
|
def ready(request: Request):
|
|
trace_id = getattr(request.state, "trace_id", "unknown")
|
|
return build_ready_payload(request.app, trace_id)
|