Repository navigation
feat(ec2): GetSpotPlacementScores, with a seedable score (#892) - #1031
Merged
Merged
Conversation
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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #892.
GetSpotPlacementScoresreached the dispatcher's default arm and answeredInvalidAction, so aconsumer 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) thatDescribeAvailabilityZonesreports — a score for a zone acaller 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.NandRegionName.Nare singular, although the CLI flags are--instance-typesand--region-names. The plural is therefore not a list, because tolerating itwould let a consumer's wrong request pass here and fail against AWS — the one divergence direction
that matters. And since
RegionName.Npublishes a minimum of 0 items, a parser keyed on theplural fails silently rather than refusing.
MaxResultsfloors at 10. That is a realValid 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
ec2MaxResultshelper is passed this operation's own range rather thanec2MinUnpublishedMaxResults, which would have accepted aMaxResults=1AWS refuses.SpotPlacementScorecarries 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
TargetCapacityis required (MissingParameterwhen absent) and range-checked against itspublished 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.
TargetCapacityUnitTypeis checked against its publishedvcpu | memory-mib | unitsand is inert for the same reason.InstanceRequirementsWithMetadataalongsideInstanceType.NanswersInvalidParameterCombination,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.Nnarrows rather than asserts. Its own text is "the Regions used to narrow down thelist 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-scoresseeds the score for one Availability Zone, one region,or every region, optionally narrowed to one instance type.
seeding one bad zone inside an otherwise-seeded region works rather than being overwritten by the
coarser seed.
regionand anavailabilityZoneIdis refused rather than resolved byprecedence: 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.
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.
scoreis refused outside 1–10 at the endpoint, not asserted as a response invariant. Thatscale is published as prose on the operation ("scored on a scale from 1 to 10") and not as a
Valid Range:line onSpotPlacementScore.score, so substrate owns the refusal rather thanclaiming 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_GetSpotPlacementScoresnorAPI_SpotPlacementScorepublishes an Examples section orany sample XML, so the element names come from the two member lists and the
item-wrapper nestingrests 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, andthe 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.
DryRunis accepted and inert, as at every EC2 operation substrate routes.Two consequences recorded rather than left implicit
No
nextTokenis 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.
NextTokenis still parsed and refused when malformed, as atevery other paginated EC2 describe.
GetSpotPlacementScoreshas the highest publishedMaxResultsfloor in the service, whichdocs/services.mdnow records next to the per-operation range table that already warns the boundmust not be harmonised.
Verification
The nine-command gate passes:
gofmt/go build/go vet,golangci-lint,make test, the sameunder
GOTOOLCHAIN=go1.26.6,make coverage, the four docs/authz reference checks, the docs sitebuild, and
test/e2e. Coverage holds at 85.0% emulator / 84.6% total.