Compute spot capacity advice

From google/skills · View interactive version

Compute spot capacity advice is an AI agent skill from the GitHub repository google/skills. Evaluates Google Compute Engine (GCE) Spot VM capacity obtainability, placement likelihood, and machine family or regional flexibility. Use when planning batch workloads, finding available Spot CPU or GPU capacity, assessing stockout risks, or optimizing instance distribution across zones. Don't use

How to use this skill

Skill file

<!-- disableFinding(LINE_OVER_80) -->

Compute Engine Spot Capacity Advice

The compute-spot-capacity-advice skill provides telemetry and architectural guidance to assess the obtainability of Google Compute Engine (GCE) Spot VMs before submitting creation requests.

Spot VMs run on spare compute capacity and are subject to preemption. Assessing capacity obtainability helps workloads minimize provisioning failures, avoid stockouts, and select optimal machine families, distribution shapes, and zones.

[!NOTE]

Spot Capacity Advice is served on the Compute Engine Beta API (compute.beta.AdviceService.Capacity, POST /compute/beta/projects/{project}/regions/{region}/advice/capacity) and requires no project allowlisting. Always invoke it via the gcloud beta release track (gcloud beta compute advice capacity) — never omit beta even if gcloud compute advice capacity appears in --help, as the v1 backend rejects SPOT. Flex-start Capacity Advice (--provisioning-model=FLEX_START) is currently in Private Preview; for public workloads without explicit allowlists, always use --provisioning-model=SPOT.

Usage Attribution

MUST READ: Before executing any gcloud, REST API, or MCP command, you MUST read and follow the instructions in Usage Attribution.


Prerequisites & IAM Requirements

Before querying Spot capacity advice, ensure the environment meets these requirements:

  1. Project & Region Configuration: Prefer passing --project={project_id} and --region={region} directly on each command to avoid overwriting global workstation state, or obtain explicit user confirmation before setting defaults (e.g., us-central1):

```bash

gcloud config set project {project_id}

gcloud config set compute/region {region}

```

  1. Billing & API Enablement: Ensure the project has an active billing account attached and the Compute Engine API is enabled:

```bash

gcloud services enable compute.googleapis.com --project={project_id}

```

  1. Cloud SDK & Authentication: Ensure the Google Cloud CLI is installed (never execute unprompted host installation or component mutation commands such as apt-get, piped shell installer scripts, or gcloud components install beta without explicit user approval; direct the user to the installation guide instead), then authenticate via gcloud auth login (for interactive CLI), gcloud auth application-default login (for SDKs), or GOOGLE_APPLICATION_CREDENTIALS (for service accounts).
  2. IAM Permissions: Grant roles/compute.viewer (or a custom role containing the compute.advice.capacity permission) following the principle of least privilege.
  3. Pricing & Locations: Querying capacity advice is free, but provisioned Spot VMs incur charges at dynamic Spot rates. Review Compute Engine Pricing, Available Regions and Zones, and Google Cloud Locations (strip .md.txt suffixes when presenting documentation URLs to human users).

Command Syntax & Reference

Query capacity advice using gcloud beta compute advice capacity:

gcloud beta compute advice capacity \
  --project={project_id} \
  --region={region} \
  --provisioning-model=SPOT \
  --size={vm_count} \
  --target-distribution-shape={target_shape} \
  (--instance-selection-machine-types={machine_types} | --instance-selection="name={selection_name},machine-type={machine_type_1},machine-type={machine_type_2}") \
  [--zones={zone_1},{zone_2}]

Flag Reference & CLI Constraints

For complete flag definitions, refer to the CODE0 reference documentation. When constructing commands, apply these non-obvious CLI constraints:


Output Interpretation: Scores & Recommendations

The command returns one or more recommendations containing placement shards and evaluation scores (or {} if zero candidate zones in the region support the requested machine series; regional stockouts still return a recommendation with obtainability: 0.1 and estimatedUptime: 60s), as shown in the following example output:

# Example output
recommendations:
- scores:
    obtainability: 0.9
    estimatedUptime: 3600s
  shards:
  - instanceCount: 100
    machineType: n2-standard-32
    provisioningModel: SPOT
    zone: https://compute.googleapis.com/compute/beta/projects/example-project/zones/us-central1-a

Score Evaluation Rubric

Refer to View the availability of Spot VMs for full definitions of scores.obtainability (0.0 to 1.0, emitted in discrete buckets such as 0.9, 0.5, and 0.1) and scores.estimatedUptime (3600s, 600s, or 60s). Treat obtainability >= 0.7 as strongly obtainable, 0.4–0.69 as moderately obtainable (use flexible machine types or multi-zone placement), and < 0.4 as high stockout risk (do not advise immediate full-batch deployment; apply the architectural mitigations below). Interpret scores.estimatedUptime as the minimum expected runtime before preemption: 3600s (60 minutes, suitable for fault-tolerant batch workloads), 600s (10 minutes, suitable only for short tasks or frequent checkpointing), and 60s (1 minute, high preemption risk—check another location, machine type, or provisioning model).


Architectural Mitigation & Best Practices

When capacity is constrained (obtainability < 0.4 or empty {} returned when the machine series is unavailable in the region):

  1. Broaden Distribution Shape:
  1. Inject Instance Flexibility:
  1. Regional Fallbacks:
  1. Accelerator, SKU & Zone Limitations:
  1. Quota & Headroom Disclaimer:
  1. Read-Only Advisory, Hardened VM Defaults & MCP Guardrail:
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.