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

health_check_cli()

Print health status to stdout and exit with 0 if healthy, 1 if unhealthy.

setup_logger(name[, level, simple, json_output])

Create and configure a logger with structured JSON output.

Classes

Any(*args, **kwargs)

Special type indicating an unconstrained type.

HealthCheck()

Static health checks for Python, imports, storage, and GCS config.

Path(*args, **kwargs)

PurePath subclass that can make system calls.

class thoth.shared.health.HealthCheck[source]

Bases: object

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.

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_storage() dict[str, bool][source]

Check storage availability.

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

classmethod is_healthy() bool[source]

Quick health check.

Returns:

True if service is healthy, False otherwise

thoth.shared.health.health_check_cli() None[source]

Print health status to stdout and exit with 0 if healthy, 1 if unhealthy.