Skip to content

fix(ec2): refuse an unmodelled instance type, and make the offerings filter work (#485) - #496

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/485-ec2-instance-types
Aug 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/485-ec2-instance-types

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #485

All three of #485's items, in one PR because they depend on each other: refusing a
type the catalog lacks is only honest once the catalog holds whole families.

1. DescribeInstanceTypes refuses an unknown type

An unknown type was answered with HTTP 200 and an empty list. Real us-east-1
raises InvalidInstanceType / 400. This is the #391 shape again — an empty list is
indistinguishable from "the type exists but matched nothing", so a consumer
validating a user-supplied instance type has an unreachable error branch.

Every unknown type in the request is collected into one bracketed list, in request
order, and one bad type fails the whole request: InstanceType.N is an assertion
that the supplied types exist, so a partial answer would let a caller checking only
the result set miss the bad input.

Provenance is split. The code is from EC2's client-error table. The message is
verbatim from the single real-us-east-1 capture in #485, so the brackets and
plural phrasing are observed; the ", " separator for a multi-type list is not
corroborated and is substrate's choice.

2. The offerings instance-type filter now works

It had never worked. The handler built its filter from an InstanceType.N
parameter the operation does not have — the reference lists exactly DryRun,
Filter.N, LocationType, MaxResults, NextToken, and botocore rejects
InstanceTypes outright. So the filter map was always empty and every query
returned the whole catalog in every zone: "is m5.xlarge offered here?" answered
yes for any input. The pattern was copied from DescribeInstanceTypes, where the
parameter does exist.

Both documented filter names now apply, with EC2's documented wildcards (* zero
or more, ? zero or one, \ escapes), case-sensitive values, all
Filter.N.Value.M as an OR and separate Filter.N ANDed. path.Match is unusable
here: its ? matches exactly one character.

Any other filter name is refused, not ignored — silently dropping a filter is
how this went unnoticed for four releases. That includes location-type, which
#485's aside believed was a filter name; it is not, and a test pins the rejection.
LocationType is honoured as the top-level parameter it is: availability-zone
(default) and region. availability-zone-id and outpost are real AWS values
substrate does not model and are refused with a message naming substrate — treating
either as availability-zone would return zone names under a locationType
claiming they are IDs or Outpost ARNs.

An unmatched filter is 0 offerings at HTTP 200, deliberately the opposite of
InstanceType.N and confirmed by #485's real-AWS diff of both. A filter narrows a
result set; InstanceType.N asserts existence. Both halves are pinned so neither
can later be "tidied" into consistency with the other.

3. The catalog covers whole families

8 types → 57. The old catalog split families mid-way (c5.xlarge in, c5.large
out), which was incidental to #234's consumer and becomes a correctness problem the
moment an absent type is refused. t3, t3a, m5, m5a, c5, c5a, r5 are
complete — note c5's ladder differs from c5a's (9xlarge/18xlarge vs
8xlarge/16xlarge) — plus the three accelerated sizes. All ten types #485 names
are present; five were not. Bare metal is excluded, pinned by a test.

Spot prices are generated from the same per-family table as the specs, so the
old parallel-map hazard is gone (DescribeSpotPriceHistory silently dropped any
type absent from the price map). The eight prices #234 shipped are preserved
verbatim so no recorded fixture moves. The three zone-name sites share one list, so
filtering an offerings query by a zone DescribeAvailabilityZones just reported
cannot return empty.

Verification

gofmt, go build, go vet, golangci-lint run ./... (0 issues), make test
(race), make docs-reference docs-reference-check docs-versions, VitePress build,
go test -C test/e2e ./... — all clean.

Mutation tested: 27 mutations, 27 caught, 0 survived. Including both directions
the plan called for — returning empty instead of InvalidInstanceType, and
raising on an unmatched offerings filter — plus counting ? as exactly-one,
case-insensitive matching, byte-vs-rune, a mid-family catalog split, bare metal
re-added, a moved seeded price, and the offerings zone list diverging from
DescribeAvailabilityZones.

End to end against substrate server: 57 types; 171 = 57×3 offerings unfiltered;
LocationType=region → 57 at one location; m5.xlarge → 3; zz9.bogus → 0 at
200; zz9.nonexistent → 400 InvalidInstanceType; location-type → 400;
outpost → 400 naming substrate; t3.micro price still 0.0042.

Follow-up filed

#495 — DescribeInstanceTypes ignores Filter.N entirely. The operation documents
~60 filter names, nearly all over fields the seeded catalog does not carry;
applying the answerable handful and dropping the rest would be this same
silent-narrowing defect. Marked with a TODO(#495) rather than half-done.

…filter work (#485)

Three defects, all in the instance-type operations.

DescribeInstanceTypes answered an unknown type with HTTP 200 and an empty list
where real us-east-1 raises InvalidInstanceType, so a consumer validating a
user-supplied type got no signal and their validation branch was unreachable.
InstanceType.N asserts the types exist, so every unknown one is collected into a
single bracketed list in request order and one bad type fails the whole request.
The code is documented; the message is verbatim from the capture in #485, whose
list separator is substrate's choice.

DescribeInstanceTypeOfferings' instance-type filter had never worked: it read an
InstanceType.N parameter the operation does not have, so the filter map was
always empty and every query returned the whole catalog in every zone. Both
documented filter names now apply, with EC2's wildcards (* zero-or-more, ? zero-
or-one, \ to escape), case-sensitive values, Value.M as an OR and Filter.N ANDed.
Any other name is refused rather than ignored -- including location-type, which
is not a filter. LocationType is honoured as the parameter it is;
availability-zone-id and outpost are refused with a message naming substrate
instead of being answered with zone names under a contradictory locationType.

An unmatched filter stays an empty answer at HTTP 200, deliberately opposite to
InstanceType.N and confirmed by #485's diff of both. Both halves are pinned so
neither can later be tidied into consistency with the other.

The catalog is widened from 8 types to 57 whole families, which is what makes
refusing an absent type honest: stopping at c5.xlarge would answer
InvalidInstanceType for c5.large. Spot prices are generated from the same table
as the specs, so the type-in-catalog-but-not-in-price-map hazard is gone, and the
eight prices #234 shipped are preserved verbatim. The three zone-name sites now
share one list.
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.29730% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_instancetypes.go 96.10% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 64912ef into main Aug 2, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/485-ec2-instance-types branch August 2, 2026 21:58
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: DescribeInstanceTypes returns empty instead of InvalidInstanceType, and DescribeInstanceTypeOfferings ignores the instance-type filter

1 participant