Skip to content

Pricing: emulate the Price List Query API (GetProducts) #401

Closed

Description

@scttfrdmn

Summary

Substrate has pricing providers (emulator/pricing.go, pricing_control.go) that consume AWS
pricing to attribute cost to simulated usage — but it does not emulate the Price List Query API
itself. There's no handler for api.pricing.<region>.amazonaws.com and no GetProducts /
DescribeServices / GetAttributeValues operation, so a client whose job is to call the Pricing
API has nothing to talk to.

Verified against 103c843 (v0.76.0):

$ grep -rn "GetProducts\|AWSPriceListService" --include="*.go" . | grep -v _test | grep -v ecs
(no matches)

Note this is the inverse direction from AWSPricingProvider, which fetches the public offer index
to price substrate's own simulated usage. I'm asking for the server side.

Why this matters to me

objectfs makes storage-tier recommendations, which means it
needs real rates. Today it ships a hardcoded table, and an audit found the table is wrong in ways
nobody noticed for four releases:

  • USW2-Requests-Tier1 is $0.005 per 1,000 PUTs; the table says 0.0005 — 10× low.
  • Storage rates are duplicated across four separate places in the codebase, which had already
    drifted apart from each other.
  • The drift test that exists compares only the storage-per-GB field, so it sails past the request-cost
    error.
  • The configured region is read at exactly one line, for a summary string — so region: us-west-2
    produces us-east-1 numbers labelled us-west-2.

So I'm replacing it with the real API. Which means I need to test against a mock, because these calls
are reachable from the filesystem read path (GetObject → RecordAccess → calculateObjectCost) and
a pricing failure must never be able to fail a filesystem operation. That property — pricing degrades,
I/O does not
— is only testable if I can make pricing fail on demand.

What I need

GetProducts on the AWSPriceListService target, and ideally DescribeServices /
GetAttributeValues.

The fidelity details are the entire point of the request. A clean, tidy mock would let my code
pass tests and then fail against real AWS. Each of these is something I verified against the live API
and got surprised by:

  1. PriceList is []string, not a list of objects. Each element is a raw JSON document as a
    string
    , which the caller must unmarshal separately. This is the single most surprising part of the
    API shape and the easiest thing for a mock to "clean up" into being wrong.

  2. pricePerUnit values are strings, e.g. "0.0230000000" — not numbers. Trailing zeros and all.

  3. productFamily is absent from most products. In the S3 offer file, 315 of 381 products
    omit it. Any mock where every product has one will teach me to filter on a field that usually isn't
    there. usagetype is the only attribute I found to be reliably 1:1 and stable, and my
    implementation is going to key on it — so please include realistically messy usagetype values
    (USW2-Requests-Tier1, USW2-TimedStorage-ByteHrs, Requests-Tier1, …).

  4. At least one SKU with multiple priceDimensions, including a tiered one whose last dimension
    has "endRange": "Inf". Tiered pricing is where a naive "take the first dimension" parser silently
    reports the wrong number.

  5. The Deep Archive trap. Filtering productFamily=Storage + volumeType='Glacier Deep Archive'
    returns a staging SKU priced at ~21× the real rate. I hit this. A mock containing only the
    "obvious" SKU per tier would hide it; including a decoy staging SKU would make my filter's
    specificity a tested property instead of a hope.

  6. Region behaviour. us-west-2 is not a Pricing API endpoint — only us-east-1 and
    ap-south-1 are. The SDK's EndpointResolverV2 will happily template any well-formed region into
    a hostname and hand you an opaque DNS failure rather than a validation error. If substrate rejects
    non-endpoint regions with something legible, that's strictly better than what AWS does, and it's a
    test I'd write.

Related: a bug in extractRegionFromHost

emulator/parser.go:411. For api.pricing.us-east-1.amazonaws.com it returns "pricing", not
"us-east-1".

After stripping .amazonaws.com, parts = ["api", "pricing", "us-east-1"]. There's no s3 token, so
the S3 loop doesn't fire; it isn't execute-api; so it falls through to the
"<service>.<region>" assumption at :441-444 and returns parts[1] — which is the second label of
a three-label host
.

This is independent of everything above and presumably affects any other service using an
api.<service>.<region> hostname. Suggested shape: when len(parts) >= 3 && parts[0] == "api",
return parts[2]. More generally, a region looks like xx-yyyy-N, so validating the candidate
against that pattern before returning it would make the whole function fail closed instead of
returning a service name as a region.

Happy to split that into its own issue if you'd prefer it tracked separately — say the word.

Priority

Lowest of the batch. objectfs can ship v0.10.1 with a corrected static table and the public offer-file
URL as an unauthenticated fallback; native GetProducts emulation is what I'd want before making the
API the primary source. #396 (Range GET) is the one that's actually blocking me.

Acceptance

A GetProducts handler returning a small hand-built S3 offer fixture that exhibits all six
characteristics above, and a fix + test for extractRegionFromHost on api.pricing.us-east-1.amazonaws.com.

Activity

  1. added
    type: feature
    area: costs
    priority: low
    on Jul 30, 2026
  2. added this to the v0.80.0 milestone on Jul 31, 2026
  3. changed the title [-]Pricing: emulate the Price List Query API (GetProducts); plus extractRegionFromHost returns "pricing" for api.pricing.<region>[/-] [+]Pricing: emulate the Price List Query API (GetProducts)[/+] on Jul 31, 2026
  4. scttfrdmn commented on Jul 31, 2026

    @scttfrdmn
    OwnerAuthor

    Split as you offered — the extractRegionFromHost bug is now #403, and this issue
    is narrowed to the Price List Query API emulation. I confirmed the parser diagnosis
    exactly as you described it (emulator/parser.go:441-444 returns parts[1], the
    second label of a three-label host), and added one thing to #403: the function fails
    open, returning a confident wrong answer rather than "", so validating the
    candidate against the xx-yyyy-N region shape guards the whole class rather than
    just the api. prefix. #403 is on v0.79.0.

    This issue is on v0.80.0. The six fidelity characteristics are the reason —
    PriceList as []string of raw JSON documents, string-typed pricePerUnit,
    productFamily absent from most products, multi-dimension tiered SKUs with
    "endRange": "Inf", the Deep Archive staging decoy, and the us-east-1/ap-south-1
    endpoint restriction — none of which a hand-waved fixture would exercise. That is a
    corpus to build carefully, not quickly, and you noted this is your lowest priority.

    Two notes on the design while it is fresh:

    • Seedable failure is the part that matters most for your stated property. You
      want "pricing degrades, I/O does not" to be testable, which means GetProducts
      needs to fail on demand. That is exactly the seed pattern in CLAUDE.md — a
      control-plane endpoint (POST/DELETE /v1/pricing/...) keyed by service or "*"
      — rather than anything nondeterministic. I will build that alongside the handler,
      not as a follow-up.
    • Rejecting non-endpoint regions legibly, as you suggest, is strictly better
      than AWS's opaque DNS failure, and I agree it should be substrate's behaviour.
      Worth being explicit that this is a deliberate divergence from AWS, so it will be
      documented as such rather than presented as parity.
  5. scttfrdmn commented on Jul 31, 2026

    @scttfrdmn
    OwnerAuthor

    Implemented in #418. Two corrections to the issue, both verified against the live offer files rather than from memory — worth flagging because each one changes what your code should do.

    The Price List API has three endpoints, not two. AWS lists us-east-1, ap-south-1, and eu-central-1 (Frankfurt). If you have region-gating logic that allows two, Frankfurt is being sent somewhere it doesn't need to go.

    The Deep Archive trap is worse than you described. You reported a decoy SKU appearing alongside the right one. I downloaded the real S3 offer files (us-west-2 and us-east-1, version 20260728131000) and filtering productFamily=Storage + volumeType="Glacier Deep Archive" returns only the staging SKU — AGJFYM869JVU9PK4 / EXB3YJ6YV5CRH4JN, at "0.0210000000". There is no correct SKU alongside it to pick instead.

    There is no TimedStorage-GDA-ByteHrs SKU in the S3 offer file at all. The only 0.00099 rate anywhere in it is TimedStorage-INT-DAA-ByteHrs — Intelligent-Tiering's Deep Archive Access tier, not Glacier Deep Archive. So that filter is 21× wrong with no correct alternative in view: code that picks "the one result" gets the staging rate and looks like it worked. Both SKUs are in the fixture so you can assert your code reaches the right one, not merely that it produced a plausible number.

    Two things I confirmed exactly as you reported them: 381 products, 315 missing productFamily, and TimedStorage-ByteHrs carrying three priceDimensions with endRange 51200 / 512000 / Inf.

    One where your table was off: Requests-Tier1 is "0.0000050000", i.e. $0.005 per 1,000. Your table had 0.0005, 10× low. The unit is Requests — per-request, not per-thousand — so dividing by 1,000 a second time is a 1,000× error on top.

    On the two acceptance criteria:

    Seedable failure is POST/DELETE /v1/pricing/query-failures, keyed by operation or "*". Your "pricing degrades, I/O does not" property is only testable if the failure is producible on demand; otherwise the fallback branch is unreachable. The endpoint rejects any code outside the seven the API documents, because a typo'd code would seed an error your except clause never matches — the fallback would go untested while the seed appeared to work.

    Rejecting non-endpoint regions is SubstrateInvalidPricingEndpoint (400). Deliberately not an AWS code: real AWS fails DNS resolution before a request is sent, and substrate serves every region from one endpoint so it can't reproduce a name that doesn't resolve. Documented in docs/services.md as a divergence rather than presented as parity.

    The region-parsing half you offered to split out shipped separately as #403 → #417, which #418 stacks on. #418 adds the service half: api.pricing.us-east-1.amazonaws.com had resolved to a service literally named api, so it couldn't route to any plugin. That also unblocked api.ecr.* and api.sagemaker.* host-based routing.

  6. added a commit that references this issue on Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: costspriority: lowtype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions