Health probes and observability
Cloud Run uses /health for liveness. If it returns non-200, the container is restarted. Make /health cheap (no DB calls, no dbt invocations) and fast (under 100ms). The only thing it should check is "the Flask process is alive".
Cloud Logging picks up stdout automatically when google.cloud.logging is wired. Log structured (JSON) when possible: it makes filtering by request_id, severity, or service trivial. Use logging.exception for errors so the stack trace lands in Cloud Logging.
from google.cloud import monitoring_v3
client = monitoring_v3.MetricServiceClient()
series = monitoring_v3.TimeSeries()
series.metric.type = f"custom.googleapis.com/dbt/build_duration"
series.resource.type = "cloud_run_revision"
point = series.points.add()
point.value.double_value = duration_seconds
client.create_time_series(name=project_path, time_series=[series])Emit a custom metric to Cloud Monitoring on every build. Track success rate, build duration, and the number of models built.
Cloud Monitoring alerting policies. Build a metric (build success rate, duration). Set a threshold. Connect a notification channel (email, Slack, PagerDuty). Cloud Monitoring fires when the threshold breaches.
Quiz: Quiz
Loading practice…