Skip to content

feat(compute): instance group managers, resize requests, accelerator types and regional bulkInsert - #115

Open
Joey Lin (jlinpw) wants to merge 6 commits into
parallelworks:canaryfrom
jlinpw:feat/compute-groups-accelerators
Open

Joey Lin (jlinpw) wants to merge 6 commits into
parallelworks:canaryfrom
jlinpw:feat/compute-groups-accelerators

Conversation

@jlinpw

Copy link
Copy Markdown

Summary

Extends the gcp/compute stand-in so code that manages groups of VMs, GPU nodes and failed resources can be tested through the official Go client instead of a hand-written fake. Five additions, plus one to fault:

Fault messages (fault). Fault.Message and Fault.WithMessage(...) set the human-readable message of the error a fault answers with, so a test can reproduce the exact wording a caller tells failures apart by (for example "pd-ssd disk type cannot be used by g4-standard-6 machine type."). Every stand-in uses it through Fault.ErrorMessage(); without a message the error still reads squall: injected fault (...).

Zonal instance group managers. list, aggregatedList (previously always empty), get, insert, delete, createInstances, deleteInstances, listManagedInstances, setInstanceTemplate.

  • A group references an instance template that must exist; deleting a template a group uses fails with 400 resourceInUseByAnotherResource.
  • createInstances makes real instances from the template, visible to instances.get/list, with created-by and instance-template metadata. Its operation finishes at once while the instances are created in the background, so WithSettleAfter holds them in progress and listManagedInstances reports them CREATING (or DELETING after deleteInstances).
  • An instance the template can't make stays a member, CREATING with no instance and the error in lastAttempt. Naming an instance or member that exists fails with 409 alreadyExists.
  • targetSize is the number of members. Deleting a group deletes its instances and resize requests.

Instance group manager resize requests. list, get, insert, cancel, delete.

  • ACCEPTED, then CREATING, then SUCCEEDED, before the insert returns unless WithSettleAfter holds it (with a negative count it stays ACCEPTED until Settle).
  • A request naming an instance that exists, or one another ACCEPTED request names, fails in its operation with 400.
  • Only an ACCEPTED request can be cancelled and only a SUCCEEDED, FAILED or CANCELLED one deleted; otherwise 412 conditionNotMet, saying the request "has reached a final state" when it has.
  • Capacity never runs out on its own: Server.FailResizeRequest ends a request FAILED and removes what it made, and Server.FailResizeAttempt records a failed attempt in lastAttempt while it waits.

Accelerator types and regional bulkInsert.

  • acceleratorTypes: aggregatedList, list, get. Every zone offers nvidia-l4 and nvidia-tesla-t4 unless WithAcceleratorTypes(zone, names...) says otherwise.
  • regionInstances.bulkInsert shares the zonal handler, so name patterns, conflicts, minCount and perLocationStatus behave the same. It places instances in the first zone, in name order, that locationPolicy doesn't deny, or spreads them with targetShape: BALANCED.

Instance suspend and resume. RUNNING to SUSPENDING to SUSPENDED, and back through STAGING to RUNNING. Calling either on an instance already in the target state does nothing; from any other state the operation fails with RESOURCE_NOT_READY.

FAILED disks. Server.PutDisk sets up a disk, READY or FAILED, as Compute Engine leaves one whose creation failed (a fault that fails an insert's operation creates nothing, so this can't be reached through the API). A FAILED disk can be read, listed and deleted but not attached or snapshotted. PutDisk rejects what an insert would.

All new methods have permissions under WithPolicy, and their fault Resources are documented. The package documentation lists where the stand-in differs from the real API, including:

  • Groups are zonal only; versions, autohealing, target pools and stateful policies are rejected, and instanceLifecyclePolicy, resourcePolicies, updatePolicy, targetSizePolicy and namedPorts are recorded unchecked.
  • A cancelled resize request stays CANCELLED until deleted, and requestedRunDuration is recorded, not enforced.
  • The regional bulkInsert ignores location constraints and doesn't weigh machine types, accelerators or capacity; its names must be free in every zone of the region. The zonal bulkInsert still ignores locationPolicy.
  • The 409 wording for a createInstances conflict and the 412 wording for cancelling a CREATING request or deleting an active one are inferred.

Testing

  • sdktest/gcp/compute: groups_test.go, accelerators_test.go, region_instances_test.go, suspend_test.go and disks_test.go go through cloud.google.com/go/compute/apiv1 (instance group managers, resize requests, accelerator types, region instances, instances and disks clients). addresses_test.go checks a fault's message reaches the caller both when a call is rejected and when its operation fails.
  • fault/fault_test.go covers ErrorMessage and String with a message.
  • make check passes (on Go 1.27.4; 1.27.3's standard library has GO-2026-6859, which govulncheck reports regardless of this change).
  • make bench against canary, benchstat over 10 runs each:
                  │    canary    │             this PR             │
                  │    sec/op    │   sec/op     vs base            │
InsertGetDelete-8   12.13µ ± 5%   11.88µ ± 4%  -2.00% (p=0.035 n=10)
ListFiltered-8      132.3µ ± 2%   131.8µ ± 1%       ~ (p=0.796 n=10)

Bytes and allocations per op are unchanged.

Checklist

  • make check passes
  • New methods are tested through the official client library
  • Package documentation says where the stand-in differs from the real API

…uspend and resume

acceleratorTypes answers aggregatedList, list and get from a per-zone catalog that WithAcceleratorTypes sets. regionInstances.bulkInsert places instances in the region's zones by its locationPolicy and shares the zonal bulkInsert's naming, conflict and minCount rules. instances.suspend and resume move a running instance through SUSPENDING to SUSPENDED and back.
Zonal instance group managers: insert, get, list, aggregatedList, delete,
createInstances, deleteInstances, listManagedInstances and
setInstanceTemplate. A group creates real instances from its template, which
instances.get and list see, and reports them with their instanceStatus and
currentAction; deleting a group deletes its instances, and a template a group
uses cannot be deleted.

Resize requests: insert, get, list, cancel and delete, moving from ACCEPTED
through CREATING to SUCCEEDED as WithSettleAfter and Settle allow, with the
412 the API gives a cancel or delete in the wrong state.
Server.FailResizeRequest and Server.FailResizeAttempt end a request in
FAILED or record a failed attempt on one still waiting, as want of quota or
capacity does.
# Conflicts:
#	gcp/compute/instances.go
#	gcp/compute/server.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant