Skip to content

cloudthinker-ai/CloudSkills / skills/connections/managing-gcp-cloud-functions-deep

managing-gcp-cloud-functions-deep

Verified

Use when working with Gcp Cloud Functions Deep — deep Google Cloud Functions analysis covering function inventory across generations (1st and 2nd gen), trigger configurations, execution metrics, memory and CPU allocation, VPC connector usage, secret bindings, and build configuration review. Provides insights on cold starts and scaling.

GCP Cloud Functions Deep Management

Comprehensive analysis of Cloud Functions across both 1st gen and 2nd gen deployments.

Phase 1: Discovery

#!/bin/bash
PROJECT="${GOOGLE_CLOUD_PROJECT}"

echo "=== Cloud Functions (2nd Gen) ==="
gcloud functions list --project="$PROJECT" --gen2 \
  --format="table(name.basename(), state, runtime, serviceConfig.availableMemory, serviceConfig.timeoutSeconds, serviceConfig.maxInstanceCount, updateTime)" \
  2>/dev/null | head -20

echo ""
echo "=== Cloud Functions (1st Gen) ==="
gcloud functions list --project="$PROJECT" \
  --format="table(name.basename(), status, runtime, availableMemoryMb, timeout, entryPoint, httpsTrigger.url:label=TRIGGER)" \
  2>/dev/null | head -20

echo ""
echo "=== Trigger Types ==="
gcloud functions list --project="$PROJECT" \
  --format="json" | jq -r '.[] | "\(.name | split("/") | last)\t\(.eventTrigger.eventType // "HTTP")"' \
  | column -t | head -20

echo ""
echo "=== VPC Connectors ==="
gcloud compute networks vpc-access connectors list --project="$PROJECT" \
  --format="table(name, network, ipCidrRange, state, minInstances, maxInstances)" 2>/dev/null

echo ""
echo "=== Runtime Distribution ==="
gcloud functions list --project="$PROJECT" --format="value(runtime)" \
  | sort | uniq -c | sort -rn

Phase 2: Analysis

#!/bin/bash
PROJECT="${GOOGLE_CLOUD_PROJECT}"

echo "=== Function Execution Metrics (7d) ==="
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")

gcloud monitoring time-series list \
  --project="$PROJECT" \
  --filter='metric.type="cloudfunctions.googleapis.com/function/execution_count"' \
  --interval-start-time="$START" --interval-end-time="$END" \
  --format="table(metric.labels.function_name, points[0].value.int64Value:label=EXECUTIONS, metric.labels.status)" \
  2>/dev/null | head -30

echo ""
echo "=== Execution Times ==="
gcloud monitoring time-series list \
  --project="$PROJECT" \
  --filter='metric.type="cloudfunctions.googleapis.com/function/execution_times"' \
  --interval-start-time="$START" --interval-end-time="$END" \
  --format="table(metric.labels.function_name, points[0].value.distributionValue.mean:label=AVG_NS)" \
  2>/dev/null | head -20

echo ""
echo "=== Active Instances ==="
gcloud monitoring time-series list \
  --project="$PROJECT" \
  --filter='metric.type="cloudfunctions.googleapis.com/function/active_instances"' \
  --interval-start-time="$START" --interval-end-time="$END" \
  --format="table(metric.labels.function_name, points[0].value.int64Value:label=MAX_INSTANCES)" \
  2>/dev/null | head -20

echo ""
echo "=== Secret Bindings Audit ==="
for FUNC in $(gcloud functions list --project="$PROJECT" --format="value(name)"); do
  SECRETS=$(gcloud functions describe "$FUNC" --project="$PROJECT" --format="json" \
    | jq -r '.secretEnvironmentVariables[]?.secret // empty' 2>/dev/null)
  [ -n "$SECRETS" ] && echo "$(basename $FUNC): $SECRETS"
done

echo ""
echo "=== Build Configuration ==="
for FUNC in $(gcloud functions list --project="$PROJECT" --format="value(name)"); do
  gcloud functions describe "$FUNC" --project="$PROJECT" --format="json" \
    | jq '{name: (.name | split("/") | last), source: .sourceArchiveUrl, buildWorkerPool: .buildWorkerPool, dockerRegistry: .dockerRegistry}' 2>/dev/null
done | head -30

Output Format

GCP CLOUD FUNCTIONS DEEP ANALYSIS
===================================
Function          Gen  Runtime       Memory  Timeout  Max-Inst  Executions  Errors  Avg-ms
──────────────────────────────────────────────────────────────────────────────────────────────
process-orders    2nd  nodejs20      512MB   60s      10        45200       12      120
auth-validate     2nd  python312     256MB   30s      100       128900      3       45
image-resize      1st  nodejs18      1024MB  120s     5         8900        0       2400

Runtimes: nodejs20(3) python312(2) go122(1)
VPC Connectors: 1 active | Secret Bindings: 2 functions

Safety Rules

  • Read-only: Only use gcloud functions list, describe, and monitoring queries
  • Never deploy or delete functions without explicit user confirmation
  • Secrets: Never output secret values, only report which secrets are bound
  • Quota: Cloud Monitoring API has 6000 read requests per minute per project

Anti-Hallucination Rules

  1. NEVER assume resource names — always discover via CLI/API in Phase 1 before referencing in Phase 2.
  2. NEVER fabricate metric names or dimensions — verify against the service documentation or --help output.
  3. NEVER mix CLI commands between service versions — confirm which version/API you are targeting.
  4. ALWAYS use the discovery → verify → analyze chain — every resource referenced must have been discovered first.
  5. ALWAYS handle empty results gracefully — an empty response is valid data, not an error to retry.

Counter-Rationalizations

ShortcutCounterWhy
"I'll skip discovery and check known resources"Always run Phase 1 discovery firstResource names change, new resources appear — assumed names cause errors
"The user only asked for a quick check"Follow the full discovery → analysis flowQuick checks miss critical issues; structured analysis catches silent failures
"Default configuration is probably fine"Audit configuration explicitlyDefaults often leave logging, security, and optimization features disabled
"Metrics aren't needed for this"Always check relevant metrics when availableAPI/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 errorAssumed permission failures prevent useful investigation; actual errors are informative
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 466kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 466kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 466kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 192kUpdated Claude CodeCodexVerifiedInstall