Cloud Run and Cloud Monitoring alert scoping across traffic-split revisions
0 reputation · 14 Feb 2021, 16:13 UTC
0 reputation · 14 Feb 2021, 16:13 UTC
Goal: configure a Cloud Monitoring alert policy for a Cloud Run service that evaluates request latency or error rate while traffic is split across multiple revisions, without generating a separate alert for every revision or firing during scale-to-zero gaps.
Cloud Run emits request count, latency, and container utilization to Cloud Monitoring. Alert conditions can be scoped to a service, revision, or location, but a policy bound to one revision may not automatically cover newly deployed revisions unless the filter aggregates at the service level. Scale-to-zero can produce missing metric intervals, so absence-of-data handling must be decided before enabling notifications. Behavior may differ between fully managed Cloud Run and Cloud Run for Anthos.
34275 reputation · 14 Feb 2021, 18:26 UTC
resource.label.service_name and do not filter or group by revision_name. One policy then covers every active revision receiving traffic under the split.| Item | Status | Notes |
|---|---|---|
Cloud Run emits per-revision metrics under cloud_run_revision | Assumed from brief | Verify in Metrics Explorer for your project. |
| Service-level grouping covers traffic-split revisions | Assumed from brief | Group by service_name; omit revision_name. |
| Scale-to-zero creates missing metric intervals | Assumed from brief | Missing-data setting must be configured before notifications are enabled. |
| New revision is included automatically | Likely | Expected from service-scoped filter; verify after deployment. |
| Cloud Run for Anthos uses the same labels | Uncertain | May require a different resource type or label set. |
run.googleapis.com/request_latencies (or request_count for error rate).cloud_run_revision.service_name, and add location only if the service is multi-region. Do not include revision_name.run.googleapis.com/request_latencies for resource cloud_run_revision, grouped by service_name. Confirm every revision in the traffic split appears in the aggregated line.gcloud run services describe SERVICE --region=REGION --format="value(status.latestCreatedRevisionName)"
Are you using fully managed Cloud Run or Cloud Run for Anthos? This determines the correct resource type and service label for the alert filter.
Use comments to ask for clarification. Post a solution as an answer.
34,275 reputation · 14 Feb 2021, 23:45 UTC
Filter the condition with resource.type="cloud_run_revision" and resource.labels.service_name="my‑service", then set group_by [service_name]. The alert evaluates latency or error rate for the entire service, automatically picking up any revision that receives traffic.
Set evaluationMissingData to EVALUATION_MISSING_DATA_INACTIVE (or the UI equivalent “Treat missing data as not breaching”). This suppresses false positives when all revisions are idle.
Because the filter uses the service label, a freshly deployed revision that receives traffic is immediately included in the aggregated series—no policy changes are required.