Skip to content

feat(azure/savingsplans): look up the Savings Plan order alias before buying (reuse / create / fail) #624

Open

Description

@IAmJSD

Implement after the Azure deploy pause. Azure deploys are paused, and the platform keeps refusing Azure Savings Plan re-drives until this lands and is adopted, so there is no rush.

Background

LeanerCloud/cloud-commitments-platform#838 asks the owner to choose for Azure Savings Plans: (a) refuse re-drives (automatic retries of a stuck purchase) forever, or (b) add server-side dedupe upstream. This issue records the design for (b).

On main (86907ad), Client.PurchaseCommitment (providers/azure/services/savingsplans/client.go:359) derives the order alias name from the platform's retry token (common.OrderIDFromToken, :383). It then PUTs straight away with BeginCreate (:395). The code comment assumes a second PUT of the same alias returns the first order instead of buying again, but that is unproven. LeanerCloud/cloud-commitments-platform#1305 (merged) only pins today's behavior with a test, and the platform still refuses Azure SP re-drives, so the platform is safe today.

Proposal: look up the alias before buying

Only when opts.IdempotencyToken is set:

  1. GET the order alias by name first.
    • 200 with provisioning state Succeeded: reuse it. Return that order's id with no PUT.
    • 404: create it with BeginCreate, as today.
    • A non-terminal provisioning state, or any other error: fail without buying, with an error that tells the caller to check the portal.
  2. Without a token, behave as today.

Implementation notes:

Acceptance criteria

  • One mock test per branch: 200 Succeeded (assert BeginCreate is never called), 404 (assert BeginCreate is called once), non-terminal state (no BeginCreate, error), other error (no BeginCreate, error).
  • No change to the token-less path.
  • After this is released: a platform go.mod bump, plus a platform PR that drops the Azure SP re-drive refusal (Provider duplicate-purchase proof matrix: Azure Savings Plans has no server-side dedupe cloud-commitments-platform#838).
  • Proving how live Azure answers the alias GET and a repeated PUT needs a real subscription and could buy a real plan. That is for the owners to decide and do, in a sandbox, and is not part of this issue's tests.

Refs LeanerCloud/cloud-commitments-platform#838, LeanerCloud/cloud-commitments-platform#1305, #211.

Filed by IAmJSD's agent at IAmJSD's request (acting owner while the maintainers are away).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions