Repository navigation
feat(pricing): an AmazonEC2 offer corpus for GetProducts (#894) - #1034
Merged
Merged
Conversation
GetProducts answered NotFoundException for ServiceCode=AmazonEC2, so a consumer that reads on-demand instance rates at runtime to cost its own usage could only be tested against a hand-maintained table — the failure mode the Price List emulation exists to remove, where the original reporter's table was 10x wrong on one S3 rate and 21x wrong on another. Bundle 32 EC2 SKUs extracted from the live us-east-1, us-west-2 and eu-west-1 offer files: nine instance types per Region, seven m5.xlarge variants each one attribute from the nominal row, and the free-tier pseudo-product. No rate is derived from another rate, and the data says why: eu-west-1 is a per-family premium rather than one Region multiplier (p4d ~1.080x, inf2 exactly 1.250x, m5 ~1.115x, t3 ~1.096x), us-west-2 matches us-east-1 on every rate here except p4d.24xlarge (21.9576420000 against 21.9576400000), and eu-west-1 publishes no g6, p5 or trn1 compute product at all. A derived rate would invent one, and a consumer would price a Region it cannot launch in. Three traps were found in the data rather than predicted. The documented seven-filter recipe for "one on-demand rate" returns three SKUs for a Windows m5.xlarge, sharing one usagetype and differing only in licenseModel and operation ($0.376 with a license, $0.192 without one, $0.192 BYOL), so licenseModel is an eighth discriminator. usagetype is not 1:1 with a SKU in EC2's file — four corpus SKUs share BoxUsage:m5.xlarge — which makes the S3 corpus's "reliably present and 1:1" an S3 accident rather than a Price List rule, now scoped to S3 in both the fixture and the docs. And marketoption alone separates a $55.04 p5.48xlarge from a $0.00 Capacity Block one, so a query omitting it can report a free p5. The free-tier product is carried because it falsifies five invariants a parser written against the nominal rows would assume: no instanceType on a Compute Instance product, endRange "750" rather than "Inf", an offerTermCode that is not the global on-demand code, a non-empty termAttributes, and an appliesTo listing 170 SKUs where every other on-demand dimension's is empty. Its regionCode is the empty string, so a Region-scoped query never selects it. Carrying it needed two new pricingCorpusEntry fields, offerTermCode and termAttributes, each defaulting to what AWS emits everywhere else. A PriceList document now reports its own service's offer-file revision in version and publicationDate rather than one global pair, because EC2 and S3 publish on their own schedules and the real API's strings differ accordingly. Two boundaries are stated rather than blurred: the corpus is not EC2's instance-type catalog (#896 — a rate here is not a claim the type can be launched), and it is not exhaustive, so an absent type's empty PriceList reads the same as a Region that genuinely does not publish it.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 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 #894.
GetProductsansweredNotFoundExceptionforServiceCode=AmazonEC2, so a consumer that readson-demand instance rates at runtime to cost its own usage could only be tested against a
hand-maintained table — the failure mode the Price List emulation exists to remove, where the original
reporter's table was 10× wrong on one S3 rate and 21× wrong on another.
What ships
32 EC2 SKUs extracted from the live
us-east-1,us-west-2andeu-west-1offer files (version20260910195514): nine instance types per Region (t3.micro,m5.xlarge,g4dn.xlarge,g5.2xlarge,g6.xlarge,inf2.xlarge,p4d.24xlarge,p5.48xlarge,trn1.32xlarge), sevenm5.xlargevariants each one attribute from the nominal row, and the free-tier pseudo-product. Theissue's exact query — the seven documented filters, then
terms.OnDemand.*.priceDimensions.*.pricePerUnit.USD— now returns one rate for all nine types in thetwo US Regions and for six of the nine in
eu-west-1.No rate is derived from another rate, and the data is why:
eu-west-1is a per-family premium overus-east-1, not one Region multiplier:p4d≈1.080×,inf2exactly 1.250×,m5≈1.115×,t3≈1.096×. A single multiplier would be wrong by up to 15%.us-west-2matchesus-east-1on every rate here exceptp4d.24xlarge—21.9576420000against
21.9576400000.eu-west-1publishes nog6,p5ortrn1compute product at all, so a derived rate wouldinvent one and a consumer would price a Region it cannot launch in.
The extraction streams the three 480 MB files rather than transcribing them, and every rate
independently reproduces the measured notes. The one structural liberty: an instance type's physical
attributes are held once per type rather than per Region, which was verified by measurement — only
location,regionCodeandusagetypevary by Region for a given type.Three traps found in the data rather than predicted
m5.xlargeinus-east-1returns three SKUs, sharing oneusagetypeand differing only inlicenseModelandoperation— $0.376 with a license, $0.192 without one, $0.192 BYOL.licenseModelis an eighthdiscriminator, and a caller taking
PriceList[0]picks one arbitrarily.usagetypeis not 1:1 with a SKU in EC2's file — four corpus SKUs shareBoxUsage:m5.xlarge.The S3 corpus's own preamble calls it "reliably present and 1:1"; that is an S3 accident, not a
Price List rule, and it is now scoped to S3 in both the fixture and
docs/services.md.marketoptionalone separates a $55.04p5.48xlargefrom a $0.00 Capacity Block one, so aquery that omits it can report a free p5 — the worst failure shape for a cost path, because it looks
like a successful lookup.
Also reproduced:
capacitystatusandtenancychange theusagetypetoken (UnusedBox:,DedicatedUsage:) rather than only the price; theusagetypeRegion prefix is not derivable from theRegion code (
us-east-1none,us-west-2USW2-,eu-west-1the legacyEU-); andCompute Instanceexcludes bare metal, a separateproductFamily.Shape changes
The free-tier product falsifies five invariants a parser written against the nominal rows would
assume — no
instanceTypeon aCompute Instanceproduct,endRange"750"rather than"Inf", anofferTermCode(A429C66SYZ) that is not the global on-demand code, a non-emptytermAttributes, andan
appliesTolisting 170 SKUs where every other on-demand dimension's is empty. Carrying it neededtwo new
pricingCorpusEntryfields,offerTermCodeandtermAttributes, each defaulting to what AWSemits everywhere else.
A
PriceListdocument now reports its own service's offer-file revision inversionandpublicationDaterather than one global pair, because EC2 and S3 publish on their own schedules.DescribeServicesreportsAmazonEC2ahead ofAmazonS3with 41 attribute names that are exactly theunion of what the corpus SKUs carry, preserving the registry's invariant that every advertised
attribute is usable as a filter.
What this is not
g5,g6,inf2,p4d,p5andtrn1,none of which
DescribeInstanceTypesreports. The two data sets answer different questions and arenot generated from a shared source; a rate here is not a claim the type can be launched. EC2 instance-type catalog carries no current-generation accelerated types, and RunInstances does not validate against it #896 fixes
the catalog side, and
docs/services.mdstates the boundary so it is a documented divergence.us-east-1alone publishes 107,022 compute-instance products. An absent type'sempty
PriceListreads the same as a Region that genuinely does not publish it. Where the absenceis the observation (the three
eu-west-1types), the real file omits them too.trn2appears at norate in any Region for the same reason.
POST /v1/pricing/offersbeforetranscribing anything — is withdrawn as a blocker: bundled data answers "what does AWS charge", a
seed answers "what does my code do when the rate is X", and this issue reported the first. The seed
is filed as Pricing: no way to seed an offer document, so a rate outside the bundled corpus cannot be tested #1033 with the four open questions it raises.
Tests
Twelve new tests, every one through a real wire call to
GetProducts: the Linux recipe isolates oneSKU at
0.8048000000; the Windows recipe returns three with three distinctlicenseModelvalues, andadding
licenseModelnarrows to one;p5.48xlargewithoutmarketoptionreturns both55.0400000000and
0.0000000000;eu-west-1returns nothing forg6/p5/trn1whileus-east-1returns a rateand
eu-west-1m5.xlargereturns0.2140000000; the threeusagetypeRegion prefixes; thep4d.24xlargedivergence withm5.xlargeas the counter-case; theDedicated/UnusedCapacityReservation/SQL Stdvariants and their
usagetypetokens; theinstanceskucross-reference resolving to the Used SKU; thefree-tier product's five falsified invariants; a
regionCodefilter never selecting the free-tier SKU;per-service offer revisions differing; and
ServiceCodescoping, so the EC2 slice cannot leak into anS3 query.
TestPricingDescribeServicesnow walks every advertised service rather than assumingServices[0]isAmazonS3.Verification
Nine-command gate, all green:
gofmt/go build/go vet,golangci-lint run ./...(0 issues),make test,GOTOOLCHAIN=go1.26.6 make test,GOTOOLCHAIN=go1.26.6 make coverage(85.1% emulator / 84.6% total, holding the baseline),
make docs-reference docs-reference-check docs-versions authz-reference-check,npm --prefix docs run build, and the e2e suite.