GCP Cloud Run Deep Management
Comprehensive analysis of Cloud Run services, revisions, traffic routing, and performance.
Phase 1: Discovery
#!/bin/bash
PROJECT="${GOOGLE_CLOUD_PROJECT}"
echo "=== Cloud Run Services ==="
gcloud run services list --project="$PROJECT" \
--format="table(name, region, status.url, status.conditions[0].status:label=READY, metadata.annotations.'run.googleapis.com/launch-stage':label=STAGE)" \
2>/dev/null | head -20
echo ""
echo "=== Service Details ==="
for SVC in $(gcloud run services list --project="$PROJECT" --format="value(name)" 2>/dev/null); do
REGION=$(gcloud run services list --project="$PROJECT" --format="value(region)" --filter="name=${SVC}" 2>/dev/null)
gcloud run services describe "$SVC" --project="$PROJECT" --region="$REGION" --format="json" \
| jq '{name: .metadata.name, image: .spec.template.spec.containers[0].image, cpu: .spec.template.spec.containers[0].resources.limits.cpu, memory: .spec.template.spec.containers[0].resources.limits.memory, concurrency: .spec.template.spec.containerConcurrency, timeout: .spec.template.metadata.annotations["run.googleapis.com/execution-environment"], minInstances: .spec.template.metadata.annotations["autoscaling.knative.dev/minScale"], maxInstances: .spec.template.metadata.annotations["autoscaling.knative.dev/maxScale"]}' 2>/dev/null
done | head -30
echo ""
echo "=== Traffic Splitting ==="
for SVC in $(gcloud run services list --project="$PROJECT" --format="value(name)" 2>/dev/null); do
REGION=$(gcloud run services list --project="$PROJECT" --format="value(region)" --filter="name=${SVC}" 2>/dev/null)
gcloud run services describe "$SVC" --project="$PROJECT" --region="$REGION" \
--format="json" | jq ".status.traffic[] | {revision: .revisionName, percent: .percent, tag: .tag}" 2>/dev/null
done
echo ""
echo "=== Domain Mappings ==="
gcloud run domain-mappings list --project="$PROJECT" \
--format="table(name, routeName, status.conditions[0].status:label=READY)" 2>/dev/null
echo ""
echo "=== Revisions ==="
for SVC in $(gcloud run services list --project="$PROJECT" --format="value(name)" 2>/dev/null); do
REGION=$(gcloud run services list --project="$PROJECT" --format="value(region)" --filter="name=${SVC}" 2>/dev/null)
gcloud run revisions list --service="$SVC" --project="$PROJECT" --region="$REGION" \
--format="table(name, active, status.conditions[0].status:label=READY, metadata.creationTimestamp)" \
2>/dev/null | head -5
done
Phase 2: Analysis
#!/bin/bash
PROJECT="${GOOGLE_CLOUD_PROJECT}"
END=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
START=$(date -u -d "7 days ago" +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null || date -u -v-7d +"%Y-%m-%dT%H:%M:%SZ")
echo "=== Request Count & Latency ==="
gcloud monitoring time-series list \
--project="$PROJECT" \
--filter='metric.type="run.googleapis.com/request_count"' \
--interval-start-time="$START" --interval-end-time="$END" \
--format="table(resource.labels.service_name, metric.labels.response_code_class, points[0].value.int64Value:label=REQUESTS)" \
2>/dev/null | head -20
echo ""
echo "=== Request Latencies ==="
gcloud monitoring time-series list \
--project="$PROJECT" \
--filter='metric.type="run.googleapis.com/request_latencies"' \
--interval-start-time="$START" --interval-end-time="$END" \
--format="table(resource.labels.service_name, points[0].value.distributionValue.mean:label=AVG_MS)" \
2>/dev/null | head -20
echo ""
echo "=== Instance Count ==="
gcloud monitoring time-series list \
--project="$PROJECT" \
--filter='metric.type="run.googleapis.com/container/instance_count"' \
--interval-start-time="$START" --interval-end-time="$END" \
--format="table(resource.labels.service_name, metric.labels.state, points[0].value.int64Value:label=COUNT)" \
2>/dev/null | head -20
echo ""
echo "=== CPU & Memory Utilization ==="
gcloud monitoring time-series list \
--project="$PROJECT" \
--filter='metric.type="run.googleapis.com/container/cpu/utilizations"' \
--interval-start-time="$START" --interval-end-time="$END" \
--format="table(resource.labels.service_name, points[0].value.distributionValue.mean:label=CPU_UTIL)" \
2>/dev/null | head -20
echo ""
echo "=== VPC Connectors ==="
for SVC in $(gcloud run services list --project="$PROJECT" --format="value(name)" 2>/dev/null); do
REGION=$(gcloud run services list --project="$PROJECT" --format="value(region)" --filter="name=${SVC}" 2>/dev/null)
VPC=$(gcloud run services describe "$SVC" --project="$PROJECT" --region="$REGION" --format="json" \
| jq -r '.spec.template.metadata.annotations["run.googleapis.com/vpc-access-connector"] // "none"' 2>/dev/null)
echo "${SVC}: ${VPC}"
done
Output Format
GCP CLOUD RUN DEEP ANALYSIS
==============================
Service Region CPU Memory Min/Max Requests P50-ms P99-ms
──────────────────────────────────────────────────────────────────────────────────
order-api us-central1 1 512Mi 1/10 125000 45 230
auth-service us-central1 2 1Gi 2/50 890000 12 85
batch-worker us-east1 1 2Gi 0/5 8900 2400 5000
Traffic: 3 services with 100% on latest | 1 canary at 10%
VPC Connectors: 2/3 services connected | Domain Mappings: 2
Safety Rules
- Read-only: Only use
gcloud run services list, describe, revisions list, and monitoring queries
- Never deploy, update traffic, or delete services without confirmation
- Secrets: Never output secret environment variable values
- Quota: Cloud Monitoring API quota is 6000 read requests per minute
Anti-Hallucination Rules
- NEVER assume resource names — always discover via CLI/API in Phase 1 before referencing in Phase 2.
- NEVER fabricate metric names or dimensions — verify against the service documentation or
--help output.
- NEVER mix CLI commands between service versions — confirm which version/API you are targeting.
- ALWAYS use the discovery → verify → analyze chain — every resource referenced must have been discovered first.
- ALWAYS handle empty results gracefully — an empty response is valid data, not an error to retry.
Counter-Rationalizations
| Shortcut |
Counter |
Why |
| "I'll skip discovery and check known resources" |
Always run Phase 1 discovery first |
Resource names change, new resources appear — assumed names cause errors |
| "The user only asked for a quick check" |
Follow the full discovery → analysis flow |
Quick checks miss critical issues; structured analysis catches silent failures |
| "Default configuration is probably fine" |
Audit configuration explicitly |
Defaults often leave logging, security, and optimization features disabled |
| "Metrics aren't needed for this" |
Always check relevant metrics when available |
API/CLI responses show current state; metrics reveal trends and intermittent issues |
| "I don't have access to that" |
Try the command and report the actual error |
Assumed permission failures prevent useful investigation; actual errors are informative |
1---2name: managing-gcp-cloud-run-deep3description: |4 Use when working with Gcp Cloud Run Deep — deep Google Cloud Run analysis5 covering service inventory, revision management, traffic splitting,6 autoscaling configuration, request latency metrics, container resource limits,7 domain mappings, and VPC connector usage. Use for comprehensive Cloud Run8 optimization and health assessment.9connection_type: gcp10preload: false11metadata:12 source: https://skillmd.com/skills/cloudthinker-ai/managing-gcp-cloud-run-deep13---1415# GCP Cloud Run Deep Management1617Comprehensive analysis of Cloud Run services, revisions, traffic routing, and performance.1819## Phase 1: Discovery2021```bash22#!/bin/bash23PROJECT="${GOOGLE_CLOUD_PROJECT}"2425echo "=== Cloud Run Services ==="26gcloud run services list --project="$PROJECT" \27 --format="table(name, region, status.url, status.conditions[0].status:label=READY, metadata.annotations.'run.googleapis.com/launch-stage':label=STAGE)" \28 2>/dev/null | head -202930echo ""31echo "=== Service Details ==="32for SVC in $(gcloud run services list --project="$PROJECT" --format="value(name)" 2>/dev/null); do33 REGION=$(gcloud run services list --project="$PROJECT" --format="value(region)" --filter="name=${SVC}" 2>/dev/null)34 gcloud run services describe "$SVC" --project="$PROJECT" --region="$REGION" --format="json" \35 | jq '{name: .metadata.name, image: .spec.template.spec.containers[0].image, cpu: .spec.template.spec.containers[0].resources.limits.cpu, memory: .spec.template.spec.containers[0].resources.limits.memory, concurrency: .spec.template.spec.containerConcurrency, timeout: .spec.template.metadata.annotations["run.googleapis.com/execution-environment"], minInstances: .spec.template.metadata.annotations["autoscaling.knative.dev/minScale"], maxInstances: .spec.template.metadata.annotations["autoscaling.knative.dev/maxScale"]}' 2>/dev/null36done | head -303738echo ""39echo "=== Traffic Splitting ==="40for SVC in $(gcloud run services list --project="$PROJECT" --format="value(name)" 2>/dev/null); do41 REGION=$(gcloud run services list --project="$PROJECT" --format="value(region)" --filter="name=${SVC}" 2>/dev/null)42 gcloud run services describe "$SVC" --project="$PROJECT" --region="$REGION" \43 --format="json" | jq ".status.traffic[] | {revision: .revisionName, percent: .percent, tag: .tag}" 2>/dev/null44done4546echo ""47echo "=== Domain Mappings ==="48gcloud run domain-mappings list --project="$PROJECT" \49 --format="table(name, routeName, status.conditions[0].status:label=READY)" 2>/dev/null5051echo ""52echo "=== Revisions ==="53for SVC in $(gcloud run services list --project="$PROJECT" --format="value(name)" 2>/dev/null); do54 REGION=$(gcloud run services list --project="$PROJECT" --format="value(region)" --filter="name=${SVC}" 2>/dev/null)55 gcloud run revisions list --service="$SVC" --project="$PROJECT" --region="$REGION" \56 --format="table(name, active, status.conditions[0].status:label=READY, metadata.creationTimestamp)" \57 2>/dev/null | head -558done59```6061## Phase 2: Analysis6263```bash64#!/bin/bash65PROJECT="${GOOGLE_CLOUD_PROJECT}"66END=$(date -u +"%Y-%m-%dT%H:%M:%SZ")67START=$(date -u -d "7 days ago" +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null || date -u -v-7d +"%Y-%m-%dT%H:%M:%SZ")6869echo "=== Request Count & Latency ==="70gcloud monitoring time-series list \71 --project="$PROJECT" \72 --filter='metric.type="run.googleapis.com/request_count"' \73 --interval-start-time="$START" --interval-end-time="$END" \74 --format="table(resource.labels.service_name, metric.labels.response_code_class, points[0].value.int64Value:label=REQUESTS)" \75 2>/dev/null | head -207677echo ""78echo "=== Request Latencies ==="79gcloud monitoring time-series list \80 --project="$PROJECT" \81 --filter='metric.type="run.googleapis.com/request_latencies"' \82 --interval-start-time="$START" --interval-end-time="$END" \83 --format="table(resource.labels.service_name, points[0].value.distributionValue.mean:label=AVG_MS)" \84 2>/dev/null | head -208586echo ""87echo "=== Instance Count ==="88gcloud monitoring time-series list \89 --project="$PROJECT" \90 --filter='metric.type="run.googleapis.com/container/instance_count"' \91 --interval-start-time="$START" --interval-end-time="$END" \92 --format="table(resource.labels.service_name, metric.labels.state, points[0].value.int64Value:label=COUNT)" \93 2>/dev/null | head -209495echo ""96echo "=== CPU & Memory Utilization ==="97gcloud monitoring time-series list \98 --project="$PROJECT" \99 --filter='metric.type="run.googleapis.com/container/cpu/utilizations"' \100 --interval-start-time="$START" --interval-end-time="$END" \101 --format="table(resource.labels.service_name, points[0].value.distributionValue.mean:label=CPU_UTIL)" \102 2>/dev/null | head -20103104echo ""105echo "=== VPC Connectors ==="106for SVC in $(gcloud run services list --project="$PROJECT" --format="value(name)" 2>/dev/null); do107 REGION=$(gcloud run services list --project="$PROJECT" --format="value(region)" --filter="name=${SVC}" 2>/dev/null)108 VPC=$(gcloud run services describe "$SVC" --project="$PROJECT" --region="$REGION" --format="json" \109 | jq -r '.spec.template.metadata.annotations["run.googleapis.com/vpc-access-connector"] // "none"' 2>/dev/null)110 echo "${SVC}: ${VPC}"111done112```113114## Output Format115116```117GCP CLOUD RUN DEEP ANALYSIS118==============================119Service Region CPU Memory Min/Max Requests P50-ms P99-ms120──────────────────────────────────────────────────────────────────────────────────121order-api us-central1 1 512Mi 1/10 125000 45 230122auth-service us-central1 2 1Gi 2/50 890000 12 85123batch-worker us-east1 1 2Gi 0/5 8900 2400 5000124125Traffic: 3 services with 100% on latest | 1 canary at 10%126VPC Connectors: 2/3 services connected | Domain Mappings: 2127```128129## Safety Rules130131- **Read-only**: Only use `gcloud run services list`, `describe`, `revisions list`, and monitoring queries132- **Never deploy, update traffic**, or delete services without confirmation133- **Secrets**: Never output secret environment variable values134- **Quota**: Cloud Monitoring API quota is 6000 read requests per minute135136## Anti-Hallucination Rules1371381. **NEVER assume resource names** — always discover via CLI/API in Phase 1 before referencing in Phase 2.1392. **NEVER fabricate metric names or dimensions** — verify against the service documentation or `--help` output.1403. **NEVER mix CLI commands between service versions** — confirm which version/API you are targeting.1414. **ALWAYS use the discovery → verify → analyze chain** — every resource referenced must have been discovered first.1425. **ALWAYS handle empty results gracefully** — an empty response is valid data, not an error to retry.143144## Counter-Rationalizations145146| Shortcut | Counter | Why |147|----------|---------|-----|148| "I'll skip discovery and check known resources" | Always run Phase 1 discovery first | Resource names change, new resources appear — assumed names cause errors |149| "The user only asked for a quick check" | Follow the full discovery → analysis flow | Quick checks miss critical issues; structured analysis catches silent failures |150| "Default configuration is probably fine" | Audit configuration explicitly | Defaults often leave logging, security, and optimization features disabled |151| "Metrics aren't needed for this" | Always check relevant metrics when available | API/CLI responses show current state; metrics reveal trends and intermittent issues |152| "I don't have access to that" | Try the command and report the actual error | Assumed permission failures prevent useful investigation; actual errors are informative |153