Skip to content

feat(pricing): emulate the Price List Query API over a real offer corpus (#401) - #418

Merged
scttfrdmn merged 4 commits into
mainfrom
feat/401-pricelist-api
Jul 31, 2026
Merged

scttfrdmn merged 4 commits into
mainfrom
feat/401-pricelist-api

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Emulates the AWS Price List Query API — GetProducts, DescribeServices,
GetAttributeValues — so a consumer that queries AWS rates at runtime can test
that 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), which
consumes the public offer index to price substrate's own simulated usage.

Stacked on #417 (fix/403-region-from-host), which fixes the region half of
the 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.json offer file (version 20260728131000).
Every SKU, rate code, pricePerUnit string and attribute value was taken from
that 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:

Shape Why it matters
PriceList elements are JSON documents encoded as strings Decoding needs a second unmarshal per element
pricePerUnit/beginRange/endRange are strings ("0.0230000000") A float64 field silently fails to unmarshal
productFamily absent from most products (315 of 381 in the real file) A filter on it misses the majority of SKUs; usagetype is the reliable key
TimedStorage-ByteHrs has three priceDimensions, last endRange: "Inf" Reading the first reports the 50 TB rate as the only rate

Two verified corrections to the issue

Requests-Tier1 is "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 a
decoy alongside the right SKU — in both regional slices of the live file it
returns only TimedStorage-GDA-Staging at "0.0210000000", 21× the $0.00099
archive rate. There is no TimedStorage-GDA-ByteHrs SKU in the S3 offer file at
all, 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. Both
SKUs 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-1
and eu-central-1 (Frankfurt).

Contract details, doc-verified

Filter.Type supports the full enum — TERM_MATCH, EQUALS, CONTAINS,
ANY_OF, NONE_OF — not just TERM_MATCH; ANY_OF/NONE_OF take a
comma-separated Value. MaxResults bounds differ per operation (1–100 for
GetProducts/DescribeServices, 1–10000 for GetAttributeValues), and an
out-of-range value is InvalidParameterException rather than a silent clamp,
because clamping hides the caller's mistake. FormatVersion accepts only
aws_v1. Pagination uses an opaque NextToken; an undecodable token or one
pointing past the end is InvalidNextTokenException — an error a caller otherwise
cannot reach.

An unknown ServiceCode is NotFoundException, not an empty PriceList.
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 is
the 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 — the
fallback 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.com to resolve. Substrate serves every region
from 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.md as 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.* and api.sagemaker.* were affected too — reachable until now only via
their X-Amz-Target namespace. apigateway.* is covered by a test to confirm the
stripped prefix is the label api., not the letters.

Verification

go build, go vet, golangci-lint run ./... 0 issues, make test (race)
green, test/e2e green, make docs-reference-check passes,
make scan-fs 0 findings.

New tests assert the traps structurally rather than asserting a request
succeeded: PriceList elements are checked to be strings (with a failure message
explaining why), every pricePerUnit is checked to be a string, the tiered SKU is
checked to have all three dimensions indexed by beginRange, the Deep Archive
filter is checked to return only the staging SKU, and every value
GetAttributeValues advertises is fed back through a GetProducts filter to
prove it matches at least one product — so the documented discovery path cannot
dead-end.

Closes #401.

…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.
@scttfrdmn scttfrdmn added this to the v0.80.0 milestone Jul 31, 2026
@scttfrdmn scttfrdmn added the type: feature New feature or improvement label Jul 31, 2026
@scttfrdmn
scttfrdmn changed the base branch from fix/403-region-from-host to main July 31, 2026 15:10
# Conflicts:
#	CHANGELOG.md
#	docs/services.md
#	emulator/parser_test.go
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.00000% with 44 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/pricing_plugin.go 92.33% 13 Missing and 11 partials ⚠️
emulator/pricing_query_ctrl.go 66.03% 12 Missing and 6 partials ⚠️
emulator/plugins.go 71.42% 1 Missing and 1 partial ⚠️

📢 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.
@scttfrdmn
scttfrdmn merged commit d12a54f into main Jul 31, 2026
15 checks passed
@scttfrdmn
scttfrdmn deleted the feat/401-pricelist-api branch July 31, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature New feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pricing: emulate the Price List Query API (GetProducts)

1 participant