1
---
2
name: cloud-run-alert-configuration
3
metadata:
4
version: "1.0.3"
5
category: Serverless
6
description: >-
7
Configures best-practice, high-signal alerting policies for Cloud Run
8
resources on Google Cloud (services, jobs, and worker pools) based on seasoned
9
SRE practices. Use
10
when analyzing, recommending, writing, or deploying Terraform PromQL alerting
11
policies to monitor Cloud Run error rates (4xx/5xx), request latency, container instance
12
saturation (warning/critical), container CPU/memory utilization and allocation, billable
13
instance time, job execution status, and worker pool queue backlog. Don't use for
14
GKE workloads (use gke-alert-configuration) or Compute Engine VMs.
15
allowed-tools: terraform gcloud
16
---
17
18
# Cloud Run Alert Configuration
19
20
Production-grade observability for Cloud Run using Terraform and PromQL
21
(Cloud Monitoring). Grounded in SRE practices, this skill focuses strictly on
22
actionable user impact and scaling bounds.
23
24
--------------------------------------------------------------------------------
25
26
## Attribution
27
28
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
29
MUST read [Usage Attribution](references/attribution.md). For commands executed
30
directly in the terminal (never in generated scripts, Terraform, or user code),
31
prefix `gcloud` with
32
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:cloud-run-alert-configuration)"`
33
and append `agent-skills/1.0 (skill:cloud-run-alert-configuration)` to `User-Agent` headers.
34
35
## CRITICAL RULES
36
37
* **Prompt-First Fast Path (Skip Discovery When Named)**:
38
* **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**.
39
* 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)**.
40
* **Autonomous Discovery (Only When Target Name is Omitted)**:
41
* **Never Scan Root Monorepo or Unbounded Directories**: Never run `find_by_name` or `ls` across root workspace directories.
42
* **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`.
43
* **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.
44
* **Workload Routing**: Always classify the workload target and follow its
45
specific reference guide:
46
* For HTTP Services follow [services.md](references/services.md)
47
* For Cloud Run Jobs follow [jobs.md](references/jobs.md)
48
* For Worker Pools follow [worker_pools.md](references/worker_pools.md)
49
* **Explicit Defaults & User Overrides**:
50
* Always use explicit defaults for all constants specified in
51
the target workload's reference file (SLO targets, latency thresholds,
52
SLAs, saturation ceilings, rate guards).
53
* State the defaults being applied in the final summary output and clearly
54
notify the user that any default constant can be customized or
55
overridden via Terraform variables or prompt input.
56
* **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.
57
* **PromQL `duration` (Retest Window) Rules**:
58
* **Lookbacks $\le$ 25h**: Set `duration = "300s"` (5m buffer) to absorb
59
transient blips and scale-up lag (except immediate job failure alerts
60
which use `duration = "0s"`).
61
* **Lookbacks $> 25$h** (e.g. 3d/7d Slow Burn): **Omit `duration`
62
entirely** (or set to `0s`). Cloud Monitoring rejects PromQL queries
63
with `duration` set on lookbacks >25h (`INVALID_ARGUMENT`).
64
* **Terraform Standards & Mandatory Labels**:
65
* Output clean, complete `.tf` configurations using `google_monitoring_alert_policy` and `condition_prometheus_query_language` directly in your response.
66
* **Mandatory User Labels**: Every `google_monitoring_alert_policy` resource MUST include a `user_labels` block containing:
67
```hcl
68
user_labels = {
69
created-with-google-skill = "cloud-run-alert-configuration"
70
}
71
```
72
* Include `alert_strategy { auto_close = "604800s" }` and parameterize `notification_channels = var.notification_channels`.
73
74
## WORKFLOW STEPS
75
76
### 1. Discovery & Target Identification
77
78
* **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**.
79
* **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`).
80
81
### 2. Configure Alerts
82
83
* Route to the corresponding guide to generate the alert policies:
84
* **HTTP Services**: Open [services.md](references/services.md). Apply the
85
requested alerting policy or standard suite covering availability SLOs (5xx), request
86
latency (P95/P99), client errors (4xx), container instance saturation,
87
container CPU/memory utilization, traffic anomalies (drop/surge), and billable
88
instance time.
89
* **Batch Jobs**: Open [jobs.md](references/jobs.md). Apply immediate job
90
execution failure alerts (`duration = "0s"`).
91
* **Worker Pools**: Open [worker_pools.md](references/worker_pools.md).
92
Apply the 4-policy standard suite (Task Success SLO Fast/Slow Burn,
93
Backlog ETD, Message Age SLA).
94
95
### 3. Terraform Generation & Review
96
97
* 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"`).
98
* State the applied defaults and remind the user of their ability to override
99
any constant.
100
* Provide a clear plain-English breakdown of the PromQL logic and triggering
101
thresholds.
102
103
--------------------------------------------------------------------------------
104
105
## Additional Resources
106
107
* [Cloud Run Documentation](https://docs.cloud.google.com/run/docs/overview/what-is-cloud-run.md.txt)
108
* [Cloud Monitoring PromQL Documentation](https://docs.cloud.google.com/monitoring/promql/promql-in-monitoring.md.txt)
109
* [Google Cloud Alerting Policies in Terraform](https://docs.cloud.google.com/monitoring/alerts/terraform.md.txt)
110
* [Google SRE Workbook: Alerting on SLOs](https://sre.google/workbook/alerting-on-slos/)
111