Skip to content

feat(ec2): GetSpotPlacementScores, with a seedable score (#892) - #1031

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/spot-placement-scores-892
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/spot-placement-scores-892

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #892.

GetSpotPlacementScores reached the dispatcher's default arm and answered InvalidAction, so a
consumer that samples a placement score alongside each on-demand probe — the free signal it
correlates against paid fulfillment — could not run that pairing against substrate at all. Neither
branch of it: not the promising one, and not the skip-this-region one.

It now scores the three seeded regions, or their nine zones under SingleAvailabilityZone=true,
reporting the AZ ID (use1-az1) that DescribeAvailabilityZones reports — a score for a zone a
caller cannot then look up is not a usable signal, so a test cross-checks the two operations agree.

The three wire facts, each pinned by a test

Recorded on the issue before implementing, because each would have produced an operation that
accepts nothing the SDK sends.

  • InstanceType.N and RegionName.N are singular, although the CLI flags are
    --instance-types and --region-names. The plural is therefore not a list, because tolerating it
    would let a consumer's wrong request pass here and fail against AWS — the one divergence direction
    that matters. And since RegionName.N publishes a minimum of 0 items, a parser keyed on the
    plural fails silently rather than refusing.
  • MaxResults floors at 10. That is a real Valid Range: line and it is this operation's alone
    — every other paginated EC2 describe in the tree floors at one or five — so the shared
    ec2MaxResults helper is passed this operation's own range rather than
    ec2MinUnpublishedMaxResults, which would have accepted a MaxResults=1 AWS refuses.
  • SpotPlacementScore carries exactly three members: availabilityZoneId, region, score.
    No capacityAvailable, no ARN, no metadata — so there is nothing further to model.

What is validated, and what is validated-then-inert

TargetCapacity is required (MissingParameter when absent) and range-checked against its
published 1–2000000000. It is then unused: substrate models no capacity broker, so how much capacity
a request asks for cannot move a score not computed from capacity. Refusing an out-of-range value is
still the caller-visible half of the parameter, and it is the half a consumer's request builder is
tested against. TargetCapacityUnitType is checked against its published
vcpu | memory-mib | units and is inert for the same reason.

InstanceRequirementsWithMetadata alongside InstanceType.N answers InvalidParameterCombination,
which the page states outright. Attribute-based instance selection is not modeled, so the
requirements are recorded intent — but answering 200 to the combination would let code AWS rejects
pass here.

RegionName.N narrows rather than asserts. Its own text is "the Regions used to narrow down the
list of Regions to be scored", so an unseeded region contributes nothing instead of erroring, which
keeps the answer consistent with DescribeRegions.

Seeding

POST/DELETE /v1/ec2/spot-placement-scores seeds the score for one Availability Zone, one region,
or every region, optionally narrowed to one instance type.

  • The most specific scope carrying a seed decides — zone, then region, then wildcard — so
    seeding one bad zone inside an otherwise-seeded region works rather than being overwritten by the
    coarser seed.
  • Naming both a region and an availabilityZoneId is refused rather than resolved by
    precedence: an AZ ID already fixes its region, which is why AWS reports the ID here, so a seed
    naming a zone in a different region has no reading that is not a guess.
  • Within one scope, a request naming several instance types takes the lowest seeded score, and
    unseeded types are not considered at all. Including them at their default would let the default
    mask a seed; taking the maximum would let a nominal sibling mask the scarce type a test seeded. It
    is also the reading closest to AWS's own, whose score describes fulfilling the whole request
    rather than its easiest member.
  • score is refused outside 1–10 at the endpoint, not asserted as a response invariant. That
    scale is published as prose on the operation ("scored on a scale from 1 to 10") and not as a
    Valid Range: line on SpotPlacementScore.score, so substrate owns the refusal rather than
    claiming a guarantee AWS makes.

The default answer, and why those numbers

Absent a seed, the answer follows the one relationship AWS publishes between a request and its score
— "if you specify one or two instance types … the returned placement score will always be low" —
so one or two types score 3 and everything else scores 7. The #892 repro names exactly one
instance type, so a low score is what a faithful emulator owes that exact command.

The two numbers are substrate's reading, chosen inside the published scale and far enough apart for
a test to distinguish, neither at an endpoint: a 1 would claim there is no capacity anywhere and a 10
that fulfillment is certain, and substrate models nothing that could know either. A request naming
no instance types scores nominally rather than low — naming none is legal and has not met the
documented condition, which is about specifying one or two rather than about specifying few.

Ordering is score descending, then region and zone ID ascending. AWS fixes the primary key by
describing the answer as "the top 10 Regions or Availability Zones"; the tie-break is substrate's,
and it is needed because the page itself says "Different Regions or Availability Zones might return
the same score."
Without it, two runs of one request could order the same scores differently and an
assertion on the first element would be a coin toss. A test asserts two identical requests answer
byte-identically.

Provenance

Neither API_GetSpotPlacementScores nor API_SpotPlacementScore publishes an Examples section or
any sample XML, so the element names come from the two member lists and the item-wrapper nesting
rests on substrate's existing EC2 query-protocol rendering rather than on a citation
. Every
refusal is either a published Valid Range:/Valid Values: line or a documented prose rule, and
the file says which for each. The error codes are from EC2's client-error table rather than from this
page, whose Errors section names only the common types. The default scores are substrate's reading,
argued in the code. DryRun is accepted and inert, as at every EC2 operation substrate routes.

Two consequences recorded rather than left implicit

No nextToken is reachable. The floor of 10 meets a largest-possible answer of nine items
(three seeded regions × three zones), so no legal page size can truncate it. A caller looking for a
pagination loop to exercise here will not find one, and a test asserts the absence so that a future
reader does not take it for a defect. NextToken is still parsed and refused when malformed, as at
every other paginated EC2 describe.

GetSpotPlacementScores has the highest published MaxResults floor in the service, which
docs/services.md now records next to the per-operation range table that already warns the bound
must not be harmonised.

Verification

The nine-command gate passes: gofmt/go build/go vet, golangci-lint, make test, the same
under GOTOOLCHAIN=go1.26.6, make coverage, the four docs/authz reference checks, the docs site
build, and test/e2e. Coverage holds at 85.0% emulator / 84.6% total.

The action reached the dispatcher's default arm and answered InvalidAction, so a
consumer that samples a placement score alongside each on-demand probe could not
run that pairing against substrate at all.

It now scores the three seeded regions, or their nine zones under
SingleAvailabilityZone=true, reporting the AZ ID that DescribeAvailabilityZones
reports. The list parameters are InstanceType.N and RegionName.N, singular, and
the plural is deliberately not a list; MaxResults carries this operation's own
published floor of ten rather than the usual one.

A new control-plane pair, POST/DELETE /v1/ec2/spot-placement-scores, seeds the
score for a zone, a region, or every region, optionally narrowed to one instance
type. The most specific scope carrying a seed decides, and within a scope the
lowest seeded score among the named types wins.
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.26214% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_spot_placement_control.go 85.39% 13 Missing ⚠️
emulator/ec2_spot_placement_scores.go 95.57% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 72bdb7b into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/spot-placement-scores-892 branch September 17, 2026 15:50
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.

EC2: GetSpotPlacementScores support

1 participant