Repository navigation
feat(pricing): emulate the Price List Query API over a real offer corpus (#401) - #418
Merged
Merged
Conversation
…sts (#403) extractRegionFromHost returned "pricing" for api.pricing.us-east-1.amazonaws.com. With ".amazonaws.com" stripped, parts is [api, pricing, us-east-1]: the s3 loop does not fire, parts[1] is not "execute-api", so it fell through to the "<service>.<region>" assumption and returned parts[1] — the second label of a three-label host. The reported symptom is one host layout, but the shape of the bug is the whole function failing open: it returned whichever label sat where a region usually sits, so a caller could not tell a parse failure from a real region. Every candidate is now checked against the shape of a region code — two-letter geography, one or two lowercase words, trailing ordinal — covering the four-segment partition forms (us-gov-west-1) as well as the ordinary ones. A layout that does not match yields "", which routes the request through the fallbacks extractRegion already had: the SigV4 credential scope, then defaultRegion. Two hosts that look like they should now fail keep working, and deliberately so: my-lb-1234.us-east-1.elb.amazonaws.com and my-domain.us-east-1.es.amazonaws.com carry a genuine region in the second label, and the shape check passes it. Refs #401, whose acceptance criteria include this fix.
…pus (#401) Adds a `pricing` plugin serving GetProducts, DescribeServices and GetAttributeValues over `api.pricing.{region}` and `X-Amz-Target: AWSPriceListService.{Op}`. This is the server side of pricing — for consumers that query AWS rates at runtime — and is the inverse of the existing cost-tracking provider, which consumes the public offer index to price substrate's own simulated usage. The offer corpus is seven Amazon S3 SKUs copied verbatim from the live AmazonS3/current/us-east-1 offer file (version 20260728131000). It is small on purpose: each SKU reproduces a response shape callers get wrong, and a tidied-up fixture would let a consumer's parser pass its tests and then misbehave against the real API. - PriceList elements are JSON documents encoded as strings, not objects. - pricePerUnit, beginRange and endRange are strings with trailing zeros. - productFamily is absent from most products — 315 of the 381 in the real file omit it — so a filter on it misses the majority of SKUs, while usagetype reaches every one. - TimedStorage-ByteHrs carries three priceDimensions, the last with endRange "Inf"; reading only the first reports the 50 TB rate as the only rate. Two of those shapes are the reporter's own bugs, now reproducible: their static table had Requests-Tier1 10x low (it is "0.0000050000" per request with unit Requests — $0.005 per 1,000, so dividing by 1,000 again is 1,000x off), and filtering productFamily=Storage with volumeType="Glacier Deep Archive" returns *only* TimedStorage-GDA-Staging at $0.021/GB-Mo, 21x the $0.00099 archive rate. Verified against the live offer file: no TimedStorage-GDA-ByteHrs SKU exists in it at all, so that filter cannot return the rate a caller expects; the nearest $0.00099 SKU is Intelligent-Tiering's TimedStorage-INT-DAA-ByteHrs. Filter.Type covers the full documented enum (TERM_MATCH, EQUALS, CONTAINS, ANY_OF, NONE_OF), not just TERM_MATCH. MaxResults bounds are per-operation (1-100 for GetProducts/DescribeServices, 1-10000 for GetAttributeValues) and an out-of-range value is InvalidParameterException rather than a silent clamp. An unknown ServiceCode is NotFoundException rather than an empty PriceList that would read as "AWS has no such price" — a false alarm is visible, a false empty is not. Failures are seedable via POST/DELETE /v1/pricing/query-failures, keyed by operation or the "*" wildcard. Pricing is the kind of dependency whose failure should degrade a caller rather than stop it, and that property is only testable if the failure can be produced on demand. The seed endpoint rejects any code outside the seven the API documents, because a typo'd code would seed an error no SDK catch branch matches: the fallback path would go untested while the seed appeared to work. AWS hosts this API in exactly three regions — us-east-1, ap-south-1 and eu-central-1 (the issue named two). Substrate serves every region from one endpoint, so it cannot reproduce a hostname that fails to resolve; a request signed for any other region is rejected with SubstrateInvalidPricingEndpoint, deliberately not an AWS code, and documented as a divergence rather than parity. Also fixes the service half of the api.<service>.<region> host layout, the companion to the region fix in #403: the first label yielded a service literally named "api", so these endpoints could not route to any plugin. api.ecr.* and api.sagemaker.* were affected too, having been reachable only via X-Amz-Target. Refs #401.
# Conflicts: # CHANGELOG.md # docs/services.md # emulator/parser_test.go
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
The merge took this branch's coverage matrix, which predates #415's correction of RAM's protocol from JSON to REST/JSON. Regenerated from the plugin registry, which is what docs-reference-check compares against.
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.
Emulates the AWS Price List Query API —
GetProducts,DescribeServices,GetAttributeValues— so a consumer that queries AWS rates at runtime can testthat path without network access.
This is the server side of pricing. It is the inverse of substrate's existing
cost-tracking provider (
AWSPricingProvider,/v1/pricing/lookup), whichconsumes the public offer index to price substrate's own simulated usage.
Stacked on #417 (
fix/403-region-from-host), which fixes the region half ofthe same host layout. Both touch
parser.go. Please merge #417 first.The corpus is real, on purpose
Seven Amazon S3 SKUs copied verbatim from the live
AmazonS3/current/us-east-1/index.jsonoffer file (version20260728131000).Every SKU, rate code,
pricePerUnitstring and attribute value was taken fromthat file — nothing is invented, because the point of the fixture is to reproduce
the shapes that surprise a caller. A tidied-up corpus would let a consumer's
parser pass its tests and then misbehave against the real API.
Each entry earns its place by exhibiting one trap:
PriceListelements are JSON documents encoded as stringspricePerUnit/beginRange/endRangeare strings ("0.0230000000")float64field silently fails to unmarshalproductFamilyabsent from most products (315 of 381 in the real file)usagetypeis the reliable keyTimedStorage-ByteHrshas threepriceDimensions, lastendRange: "Inf"Two verified corrections to the issue
Requests-Tier1is"0.0000050000"per request,unit: Requests— that is$0.005 per 1,000. The static table in the issue had
0.0005, which is 10× low;and because the unit is per-request, dividing by 1,000 again is a 1,000× error.
The Deep Archive filter is worse than reported. Filtering
productFamily=Storage+volumeType="Glacier Deep Archive"does not return adecoy alongside the right SKU — in both regional slices of the live file it
returns only
TimedStorage-GDA-Stagingat"0.0210000000", 21× the $0.00099archive rate. There is no
TimedStorage-GDA-ByteHrsSKU in the S3 offer file atall, so that filter cannot return the rate a caller expects. The only $0.00099
rate in the file is Intelligent-Tiering's
TimedStorage-INT-DAA-ByteHrs. BothSKUs are in the corpus so a test can assert it reached the right one, not just the
right number.
And the endpoint count: three, not two. AWS lists
us-east-1,ap-south-1and
eu-central-1(Frankfurt).Contract details, doc-verified
Filter.Typesupports the full enum —TERM_MATCH,EQUALS,CONTAINS,ANY_OF,NONE_OF— not justTERM_MATCH;ANY_OF/NONE_OFtake acomma-separated
Value.MaxResultsbounds differ per operation (1–100 forGetProducts/DescribeServices, 1–10000 forGetAttributeValues), and anout-of-range value is
InvalidParameterExceptionrather than a silent clamp,because clamping hides the caller's mistake.
FormatVersionaccepts onlyaws_v1. Pagination uses an opaqueNextToken; an undecodable token or onepointing past the end is
InvalidNextTokenException— an error a caller otherwisecannot reach.
An unknown
ServiceCodeisNotFoundException, not an emptyPriceList.Substrate's corpus is far smaller than AWS's catalog, and an empty result would
read as "AWS has no such price". A false alarm is visible; a false empty is not.
Seedable failure
POST/DELETE /v1/pricing/query-failures, keyed by operation or"*". This isthe acceptance criterion about pricing degrading without taking I/O down: that
property is only testable if the failure can be produced on demand, otherwise the
fallback branch is unreachable and a green suite says nothing about it.
The endpoint rejects any code outside the seven the API documents. A typo'd code
(
ThrotlingException) would seed an error no SDK catch branch matches — thefallback path would go untested while the seed itself appeared to work, which is
precisely the failure mode this whole issue batch exists to kill.
One deliberate divergence
AWS hosts this API in three regions and nowhere else; there is no
api.pricing.eu-west-1.amazonaws.comto resolve. Substrate serves every regionfrom one endpoint, so it cannot reproduce a name that fails to resolve. A request
signed for any other region is rejected with
SubstrateInvalidPricingEndpoint(400) — deliberately not an AWS code, so it cannot be mistaken for one, and
documented in
docs/services.mdas a divergence rather than presented as parity.Answering such a request instead would mean pricing against an endpoint that does
not exist.
Also: the service half of the
api.host fix#403/#417 fixed the region parsed from
api.pricing.us-east-1.amazonaws.com.The service had the same bug from the other end: the first label yielded a
service literally named
api, so the request could not route to any plugin.api.ecr.*andapi.sagemaker.*were affected too — reachable until now only viatheir
X-Amz-Targetnamespace.apigateway.*is covered by a test to confirm thestripped prefix is the label
api., not the letters.Verification
go build,go vet,golangci-lint run ./...0 issues,make test(race)green,
test/e2egreen,make docs-reference-checkpasses,make scan-fs0 findings.New tests assert the traps structurally rather than asserting a request
succeeded:
PriceListelements are checked to be strings (with a failure messageexplaining why), every
pricePerUnitis checked to be a string, the tiered SKU ischecked to have all three dimensions indexed by
beginRange, the Deep Archivefilter is checked to return only the staging SKU, and every value
GetAttributeValuesadvertises is fed back through aGetProductsfilter toprove it matches at least one product — so the documented discovery path cannot
dead-end.
Closes #401.