thoth.shared.health¶
Health check logic for Cloud Run and local deployments.
This module provides checks for Python version, critical imports (LanceDB, sentence-transformers, MCP), storage writability, and GCS configuration. Used by the /health endpoint and monitoring to report service readiness.
Functions
Print health status to stdout and exit with 0 if healthy, 1 if unhealthy. |
|
|
Create and configure a logger with structured JSON output. |
Classes
|
Special type indicating an unconstrained type. |
Static health checks for Python, imports, storage, and GCS config. |
|
|
PurePath subclass that can make system calls. |
- class thoth.shared.health.HealthCheck[source]¶
Bases:
objectStatic health checks for Python, imports, storage, and GCS config.
Used by the HTTP health endpoint to return a single status dict; each check returns a bool or a dict of sub-checks. Overall status is healthy only when Python version and critical imports (lancedb, mcp) pass.
- static check_python_version() → bool[source]¶
Return True if Python version is in the supported range (3.10 to 3.12).
- Returns:
True when 3.10 <= version < 3.13 (LanceDB/sentence-transformers compatibility).
- static check_imports() → dict[str, bool][source]¶
Check that critical runtime dependencies can be imported.
- Returns:
Dict of module name -> True if importable (lancedb, torch, sentence_transformers, mcp).
- static check_gcs_config() → dict[str, bool][source]¶
Check that GCS env vars and credentials are configured.
- Returns:
Dict with gcs_bucket_configured, gcp_project_configured, gcs_credentials_file_exists (when GOOGLE_APPLICATION_CREDENTIALS is set).
- classmethod get_health_status() → dict[str, Any][source]¶
Return a full health status dict for the /health endpoint.
Aggregates Python version, import checks (lancedb, torch, sentence_transformers, mcp), storage writability, and GCS config. Overall status is ‘healthy’ only when Python version and critical imports (lancedb, mcp) all pass.
- Returns:
status (‘healthy’|’unhealthy’), python_version, python_ok, imports, storage, gcs.
- Return type:
Dict with keys