{"data":{"slug":"github-google-skills-skills-cloud-cloud-run-alert-configuration-b4fb8a2123f1","title":"Configure Cloud Run Alerting Policies","summary":"Set up observability for Cloud Run services, jobs, and worker pools using Terraform and PromQL, including mandatory attribution headers and user-labels for traceability.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-run-alert-configuration-b4fb8a2123f1","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-cloud-run-alert-configuration-b4fb8a2123f1","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-run-alert-configuration-b4fb8a2123f1.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-run-alert-configuration-b4fb8a2123f1\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any `gcloud` or REST API commands, prefix `gcloud` with `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:cloud-run-alert-configuration)\"` and append `agent-skills\/1.0 (skill:cloud-run-alert-configuration)` to `User-Agent` headers. Ensure the `user_labels` block is included with `created-with-google-skill = \"cloud-run-alert-configuration\"`.","instructions":"---\nname: cloud-run-alert-configuration\nmetadata:\n  version: \"1.0.3\"\n  category: Serverless\ndescription: >-\n  Configures best-practice, high-signal alerting policies for Cloud Run\n  resources on Google Cloud (services, jobs, and worker pools) based on seasoned\n  SRE practices. Use\n  when analyzing, recommending, writing, or deploying Terraform PromQL alerting\n  policies to monitor Cloud Run error rates (4xx\/5xx), request latency, container instance\n  saturation (warning\/critical), container CPU\/memory utilization and allocation, billable\n  instance time, job execution status, and worker pool queue backlog. Don't use for\n  GKE workloads (use gke-alert-configuration) or Compute Engine VMs.\nallowed-tools: terraform gcloud\n---\n\n# Cloud Run Alert Configuration\n\nProduction-grade observability for Cloud Run using Terraform and PromQL\n(Cloud Monitoring). Grounded in SRE practices, this skill focuses strictly on\nactionable user impact and scaling bounds.\n\n--------------------------------------------------------------------------------\n\n## Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read [Usage Attribution](references\/attribution.md). For commands executed\ndirectly in the terminal (never in generated scripts, Terraform, or user code),\nprefix `gcloud` with\n`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:cloud-run-alert-configuration)\"`\nand append `agent-skills\/1.0 (skill:cloud-run-alert-configuration)` to `User-Agent` headers.\n\n## CRITICAL RULES\n\n*   **Prompt-First Fast Path (Skip Discovery When Named)**:\n    *   **If the user prompt explicitly specifies the target Cloud Run service, job, or worker pool name** (e.g., `'video-encoder'`, `'nightly-reconciliation'`, `'web-frontend'`, `'catalog-service'`, `'api-gateway'`, `'order-processor'`), **SKIP all workspace `.tf` file scanning (`find_by_name`, `code_search`, `list_dir`) and `gcloud` CLI discovery commands entirely**.\n    *   Do NOT run `gcloud`, `terraform`, or file search tools when the target name is already provided in the prompt. Instead, parameterize the project ID (`variable \"scoping_project_id\" { default = \"my-gcp-project\" }`) and target resource name in Terraform variables and proceed immediately to **Step 2 (Configure Alerts)**.\n*   **Autonomous Discovery (Only When Target Name is Omitted)**:\n    *   **Never Scan Root Monorepo or Unbounded Directories**: Never run `find_by_name` or `ls` across root workspace directories.\n    *   **Config First**: Only if the prompt omits the resource name, check `.tf` files in the immediate working directory for `google_cloud_run_v2_service`, `google_cloud_run_service`, or `google_cloud_run_v2_job`.\n    *   **CLI Second (Graceful Fallback)**: Only if unconfigured in prompt or local `.tf` files, attempt `gcloud config get-value project` and `gcloud run services list`. If any `gcloud` command fails (e.g., auth or metadata errors) or `terraform` is missing, immediately stop running CLI commands and output parameterized HCL using explicit variable defaults.\n*   **Workload Routing**: Always classify the workload target and follow its\n    specific reference guide:\n    *   For HTTP Services follow [services.md](references\/services.md)\n    *   For Cloud Run Jobs follow [jobs.md](references\/jobs.md)\n    *   For Worker Pools follow [worker_pools.md](references\/worker_pools.md)\n*   **Explicit Defaults & User Overrides**:\n    *   Always use explicit defaults for all constants specified in\n        the target workload's reference file (SLO targets, latency thresholds,\n        SLAs, saturation ceilings, rate guards).\n    *   State the defaults being applied in the final summary output and clearly\n        notify the user that any default constant can be customized or\n        overridden via Terraform variables or prompt input.\n*   **Metric Scope Centralization**: Parameterize `project = var.scoping_project_id` in all Terraform `google_monitoring_alert_policy` resources so the policy can target either a single project or a centralized Cloud Monitoring Metrics Scope.\n*   **PromQL `duration` (Retest Window) Rules**:\n    *   **Lookbacks $\\le$ 25h**: Set `duration = \"300s\"` (5m buffer) to absorb\n        transient blips and scale-up lag (except immediate job failure alerts\n        which use `duration = \"0s\"`).\n    *   **Lookbacks $> 25$h** (e.g. 3d\/7d Slow Burn): **Omit `duration`\n        entirely** (or set to `0s`). Cloud Monitoring rejects PromQL queries\n        with `duration` set on lookbacks >25h (`INVALID_ARGUMENT`).\n*   **Terraform Standards & Mandatory Labels**:\n    *   Output clean, complete `.tf` configurations using `google_monitoring_alert_policy` and `condition_prometheus_query_language` directly in your response.\n    *   **Mandatory User Labels**: Every `google_monitoring_alert_policy` resource MUST include a `user_labels` block containing:\n        ```hcl\n        user_labels = {\n          created-with-google-skill = \"cloud-run-alert-configuration\"\n        }\n        ```\n    *   Include `alert_strategy { auto_close = \"604800s\" }` and parameterize `notification_channels = var.notification_channels`.\n\n## WORKFLOW STEPS\n\n### 1. Discovery & Target Identification\n\n*   **Fast Path (Target Named in Prompt)**: If the user prompt names the target Cloud Run service, job, or worker pool, **skip all discovery commands and file searches** and proceed directly to **Step 2**.\n*   **Discovery Fallback (Target Unnamed)**: Only if no resource name is provided in the prompt, check local `.tf` files or run `gcloud` to identify the target workload type and name. If `gcloud` auth fails, fall back immediately to default Terraform variables (`var.scoping_project_id`).\n\n### 2. Configure Alerts\n\n*   Route to the corresponding guide to generate the alert policies:\n    *   **HTTP Services**: Open [services.md](references\/services.md). Apply the\n        requested alerting policy or standard suite covering availability SLOs (5xx), request\n        latency (P95\/P99), client errors (4xx), container instance saturation,\n        container CPU\/memory utilization, traffic anomalies (drop\/surge), and billable\n        instance time.\n    *   **Batch Jobs**: Open [jobs.md](references\/jobs.md). Apply immediate job\n        execution failure alerts (`duration = \"0s\"`).\n    *   **Worker Pools**: Open [worker_pools.md](references\/worker_pools.md).\n        Apply the 4-policy standard suite (Task Success SLO Fast\/Slow Burn,\n        Backlog ETD, Message Age SLA).\n\n### 3. Terraform Generation & Review\n\n*   Provide the complete HCL configuration in your response with explicitly parameterized defaults and the mandatory `user_labels` block (`created-with-google-skill = \"cloud-run-alert-configuration\"`).\n*   State the applied defaults and remind the user of their ability to override\n    any constant.\n*   Provide a clear plain-English breakdown of the PromQL logic and triggering\n    thresholds.\n\n--------------------------------------------------------------------------------\n\n## Additional Resources\n\n*   [Cloud Run Documentation](https:\/\/docs.cloud.google.com\/run\/docs\/overview\/what-is-cloud-run.md.txt)\n*   [Cloud Monitoring PromQL Documentation](https:\/\/docs.cloud.google.com\/monitoring\/promql\/promql-in-monitoring.md.txt)\n*   [Google Cloud Alerting Policies in Terraform](https:\/\/docs.cloud.google.com\/monitoring\/alerts\/terraform.md.txt)\n*   [Google SRE Workbook: Alerting on SLOs](https:\/\/sre.google\/workbook\/alerting-on-slos\/)\n","use_cases":["Set up alerting policies for Cloud Run services to monitor error rates and latency.","Create alerts for job execution status and worker pool queue backlog.","Implement SLO-based alerting for Cloud Run services using PromQL."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/cloud-run-alert-configuration\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T13:35:09.000000Z","updated_at":"2026-11-17T05:10:16.000000Z","seo_title":"Configure Cloud Run Alerting Policies","seo_description":"Set up observability for Cloud Run services, jobs, and worker pools using Terraform and PromQL, including mandatory attribution headers and user-labels for traceability.","seo_keywords":["Cloud Run alert configuration","Terraform PromQL alerts","Cloud Run observability","SRE alerting policies","Cloud Run monitoring"]}}