Skip to content

feat(azure): flag adopted reservation orders on idempotent re-drives - #265

Merged
cristim merged 2 commits into
mainfrom
feat/existing-commitment-azure
Oct 6, 2026
Merged

cristim merged 2 commits into
mainfrom
feat/existing-commitment-azure

Conversation

@cristim

@cristim cristim commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Refs #211

Final provider step. DoIdempotentPurchaseTwoStep (providers/azure/services/internal/reservations/purchase.go) returned the adopted order's id with no signal; it now returns (orderID, existing, err). existing is true only on the two adopt paths (pre-loop token lookup, and the in-loop re-check from #1774); the lookup already skips terminal-failed orders and empty names. The raw DoPurchaseTwoStep keeps its signature. Each of the 7 call sites (compute, database, cache, cosmosdb, search, synapse, managedredis) gains one line: result.ExistingCommitment = existing.

Tests: helper tests assert the flag for fresh, failed lookup, re-drive, in-loop adoption, genuine retry and refused re-check. Each service has existing_commitment_test.go driving the real PurchaseCommitment: fresh false, 500 false, re-drive true with the adopted CommitmentID and zero POSTs, terminal-failed tagged order not adopted. Dropping the plumbing line in any service, or forcing the helper's adopt return to false, fails a test.

Not covered: Azure savings plans (savingsplans/client.go PUTs a deterministic SavingsPlanOrderAlias; it is unverified whether the PUT returns 200 for an existing and 201 for a new resource. The SDK create accepts either, and reading the initial response would need azcore runtime.WithCaptureResponse because the poller hides it; left as a possible follow-up, and it avoids files touched by open #207). Not detectable client-side: AWS savings plans (native ClientToken), GCP (best effort, noted on #211). Follow-ups on #211 (EC2 class details, NewAuditRecord dropping the flag) are separate.

Avoids files in open PRs #218, #207, #205 (new test files rather than editing compute/client_test.go).

DoIdempotentPurchaseTwoStep and purchaseTwoStepGuarded now also return whether
an order already tagged with the idempotency token was adopted (the pre-loop
lookup or the in-loop re-check) instead of purchased. The seven reservation
services (compute, database, cache, cosmosdb, search, synapse, managedredis)
copy it into PurchaseResult.ExistingCommitment.

Refs #211
@cristim cristim added priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged urgency/this-quarter Within the quarter impact/few Limited audience effort/m Days type/feat New capability labels Oct 6, 2026
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-go/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 8afaa0d4-3a2f-4ceb-9110-3ca1bc6beadc
📥 Commits

Reviewing files that changed from the base of the PR and between 70f3e1d and 764c532.

📒 Files selected for processing (16)
  • providers/azure/services/cache/client.go
  • providers/azure/services/cache/existing_commitment_test.go
  • providers/azure/services/compute/client.go
  • providers/azure/services/compute/existing_commitment_test.go
  • providers/azure/services/cosmosdb/client.go
  • providers/azure/services/cosmosdb/existing_commitment_test.go
  • providers/azure/services/database/client.go
  • providers/azure/services/database/existing_commitment_test.go
  • providers/azure/services/internal/reservations/purchase.go
  • providers/azure/services/internal/reservations/purchase_test.go
  • providers/azure/services/managedredis/client.go
  • providers/azure/services/managedredis/existing_commitment_test.go
  • providers/azure/services/search/client.go
  • providers/azure/services/search/existing_commitment_test.go
  • providers/azure/services/synapse/client.go
  • providers/azure/services/synapse/existing_commitment_test.go

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.


📝 Walkthrough

Walkthrough

Azure’s idempotent purchase helper now reports whether it adopted an existing reservation order. Seven Azure service clients copy that status to PurchaseResult.ExistingCommitment. Tests cover fresh purchases, failures, adopted orders, and failed-order rejection.

Changes

Azure reservation adoption and result reporting

Layer / File(s) Summary
Reservation adoption status
providers/azure/services/internal/reservations/purchase.go, providers/azure/services/internal/reservations/purchase_test.go
The idempotent purchase helper returns an existing flag for adopted orders and leaves it false for fresh purchases and errors. Tests assert the flag across initial lookup and retry outcomes.
Azure purchase result propagation
providers/azure/services/{cache,compute,cosmosdb,database,managedredis,search,synapse}/client.go, providers/azure/services/{cache,compute,cosmosdb,database,managedredis,search,synapse}/existing_commitment_test.go
Each service client stores the helper’s flag in PurchaseResult.ExistingCommitment after success. Tests cover fresh purchases, failures, successful adoption, and failed tagged orders.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 764c5

The Azure reservation change appears ready to merge after normal checks; no concrete blocking issue was identified.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning #211 requires every provider path that adopts an existing commitment to set ExistingCommitment and have a provider test. This PR adds the signal and tests for Azure reservation services. AWS EC2 alr… Implement and test ExistingCommitment for GCP's existing-commitment adoption path. Also cover applicable AWS Savings Plans adoption paths so every provider path that adopts an existing commitment returns the flag and has a test.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 16 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The seven Azure service changes pass the adoption flag through PurchaseCommitment, and their new tests verify fresh purchases and existing-order adoption. The reservation helper changes and tests su…
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: flagging adopted Azure reservation orders during idempotent re-drives.
Full details: Linked Issues check

Explanation

#211 requires every provider path that adopts an existing commitment to set ExistingCommitment and have a provider test. This PR adds the signal and tests for Azure reservation services. AWS EC2 already sets result.ExistingCommitment = true on adoption in providers/aws/services/ec2/client.go. The PR states that GCP is not covered, although #211 identifies GCP's existing-commitment adoption as a gap. The PR also lists AWS Savings Plans as uncovered; this leaves the all-provider requirement unmet for applicable idempotent adoption paths.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@cristim
cristim merged commit de5d161 into main Oct 6, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/m Days impact/few Limited audience priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged type/feat New capability urgency/this-quarter Within the quarter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant