Health
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.
logger = setup_logger(__name__)
module-attribute
¶
HealthCheck
¶
Static 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.
check_python_version() -> bool
staticmethod
¶
Return True if Python version is in the supported range (3.10 to 3.12).
Returns:
| Type | Description |
|---|---|
bool
|
True when 3.10 <= version < 3.13 (LanceDB/sentence-transformers compatibility). |
check_imports() -> dict[str, bool]
staticmethod
¶
Check that critical runtime dependencies can be imported.
Returns:
| Type | Description |
|---|---|
dict[str, bool]
|
Dict of module name -> True if importable (lancedb, torch, sentence_transformers, mcp). |
check_storage() -> dict[str, bool]
staticmethod
¶
Check storage availability.
check_gcs_config() -> dict[str, bool]
staticmethod
¶
Check that GCS env vars and credentials are configured.
Returns:
| Type | Description |
|---|---|
dict[str, bool]
|
Dict with gcs_bucket_configured, gcp_project_configured, |
dict[str, bool]
|
gcs_credentials_file_exists (when GOOGLE_APPLICATION_CREDENTIALS is set). |
get_health_status() -> dict[str, Any]
classmethod
¶
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:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with keys: status ('healthy'|'unhealthy'), python_version, python_ok, |
dict[str, Any]
|
imports, storage, gcs. |
is_healthy() -> bool
classmethod
¶
Quick health check.
Returns:
| Type | Description |
|---|---|
bool
|
True if service is healthy, False otherwise |
health_check_cli() -> None
¶
Print health status to stdout and exit with 0 if healthy, 1 if unhealthy.