feat(purchases): make GCP Compute commitment creation idempotent#666
Conversation
GCP Compute CUD creation named commitments cud-<unix-second> and ignored opts.IdempotencyToken, so a re-drive of the same execution (issue #639's recovery sweep) would create a SECOND committed-use discount: a financial double-purchase. Thread opts.IdempotencyToken into RegionCommitments.Insert via two deterministic mechanisms so the same token can never buy twice: - RequestId: GCP's native server-side idempotency key on Insert, which the API documents as preventing duplicate commitments. It must be a valid non-zero UUID, so we format the SHA-256 token into a canonical UUID with the existing common.IdempotencyGUID helper (the same derivation PR #653 used for the Azure reservationOrderID). The same token always yields the same RequestId, so the second Insert is a server-side no-op. - Name: also derived from the token (cud-<first-32-hex>, RFC1035-valid) as defense in depth. Commitment names are unique per project+region, so a re-drive that somehow reached Insert collides on the name and GCP rejects it with ALREADY_EXISTS rather than creating a duplicate. An empty token preserves the prior non-idempotent timestamp-based name (the CLI path, which has no owning execution). The token is masked in logs via common.MaskToken (never logged verbatim), matching PR #652. Adds a re-drive regression test mirroring the AWS/Azure ones: the same token on a second PurchaseCommitment yields an identical RequestId and commitment name, plus an empty-token test confirming the CLI path stays non-idempotent. Scope is computeengine only; CloudSQL/Storage/Memorystore were made advisory-only in #649 and are untouched. Closes #654 refs #641
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughGCP Compute commitment creation is refactored to use the provided ChangesIdempotent GCP Compute Commitment Creation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Closes #654. Refs #641 (final executor slice, after AWS #652 and Azure #653).
GCP Compute CUD creation previously named commitments cud- and ignored opts.IdempotencyToken, so a re-drive could create a second committed-use discount (financial double-purchase). Now both GCP idempotency levers are derived deterministically from the token:
Empty token preserves the prior timestamp-based behaviour (CLI path). Token masked in logs via common.MaskToken (matching #652). Scope: computeengine only; CloudSQL/Storage/Memorystore stay advisory-only per #649.
Regression tests: same token on a 2nd call yields identical RequestId + name (no double-buy); empty-token CLI path stays non-idempotent. Full computeengine suite green (39 tests). A small adjacent refactor extracted buildInsertRequest to keep PurchaseCommitment under the gocyclo-10 pre-commit limit.
Once merged, #641 closes and #639 (idempotent auto-re-drive) unblocks.
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests