Repository navigation
pricing: stop fabricating EC2 prices; make the sweep estimator's pricing source injectable - #50
Merged
Merged
Conversation
… pricing source injectable GetEC2HourlyRate returned a bare float64 and never failed, inventing a price through three silent substitutions: an unknown region borrowed us-east-1's prices, an unknown instance type fell through to a per-family-size estimate, and within that an unknown family used a flat $0.10/vCPU-hr base and an unknown size the xlarge multiplier. For modern accelerators the invented number was 4-12x low and carried err == nil, so nothing downstream could tell it from a real rate: g7e.4xlarge quoted at $0.80 against a real $3.9982, p6-b200.48xlarge at $9.60 against $113.93, and p5e.48xlarge at $9.60 for a type AWS publishes no on-demand price for. GetEC2HourlyRate now returns (float64, error) and matches exactly on (region, instanceType). estimatePriceByFamily is deleted, as are the tests that asserted its output. EC2Pricing is documented as a deliberately small offline subset that is not to be grown into a pricing database, with truffle named as the suite's pricing authority for live rates. EstimateSweepCost now takes a RateResolver so the caller supplies that authority (libs cannot import truffle, which imports libs). Rows it cannot price are recorded in CostEstimate.UnpricedRows, excluded from the totals, and surfaced by Display/DisplayCompact as a FLOOR rather than folded invisibly into a total that reads as complete. Refs #29
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 #29.
The defect
GetEC2HourlyRatereturned a barefloat64and never failed. On a miss it invented a price through three silent substitutions:pricing/ec2.go(before)estimatePriceByFamilybase = 0.10multiplier = 2.0("default to xlarge")Since the table has no GPU family newer than
p4d, every current-generation accelerator took that path. Reproduced against libs v0.49.0 before changing anything:Every one carried
err == nil, so nothing downstream could tell a real rate from an invented one — which is what makes this worse than returning no price at all.After
Changes
pricing/ec2.go—GetEC2HourlyRate(region, instanceType) (float64, error), exact match only.estimatePriceByFamilydeleted.EC2Pricingis now documented as a deliberately small offline subset that must not be grown into a pricing database (a hand-maintained price table is stale the day it is written, and invisibly so), naming truffle as the suite's pricing authority and stating outright that no GPU family newer thanp4dis covered.pricing/estimator.go—EstimateSweepCost(params, rate RateResolver). libs cannot import truffle (truffle imports libs), so the caller supplies the pricing authority;nilgivesStaticRateResolver, which is the old offline behaviour made honest.CostEstimategainsPricedRows,UnpricedRows("type@region", deduped and sorted) andPartial(). An unpriceable row is excluded and named, never valued at a guess and never silently at $0 inside a total that reads as complete — andDisplay()/DisplayCompact()label such a total as a FLOOR.A mixed sweep is deliberately not an error: it still reports what it knows, provided it also reports what it doesn't.
Tests
TestEstimatePriceByFamilydeleted — it asserted the fabrication outright ("Unknown family (uses default)" → 0.2 // 0.10 * 2.0), so it was locking in the bug.TestGetEC2HourlyRateErrorsRatherThanGuessing— the regression guard. Each case carries the value the old code actually returned (measured, not assumed) and fails if that value ever comes back.TestEstimateSweepCostUsesInjectedResolver— proves the seam is used rather than the static table being consulted behind the caller's back (the stub returns$10/hr, unlike any table value).TestEstimateSweepCostPartialWhenUnpriceable— mixed sweep: only the priceable row counts toward compute, the unpriceable one is deduplicated and named,Partial()is true, and both display forms disclose the shortfall.TestEstimateSweepCostcases passniland are asserted not partial, since every type they use is in the table.gofmt,go vet ./...,go build ./...,go test ./...all clean.Consumers
Only
EstimateSweepCostcalledGetEC2HourlyRatein-repo. truffle deliberately avoids it and readsEC2Pricingdirectly through its own exact-or-errorstaticOnDemandPricer(truffle#114), so truffle and lagotto are unaffected. spawn's sweep preview is the one live consumer and is updated in a follow-up PR once this is tagged.Breaking an exported symbol → MINOR per
CLAUDE.md(pre-1.0): suggest v0.50.0. The break is the point — it forces callers to confront "I can't price this" instead of receiving a plausible wrong number. Known external consumer:scttfrdmn/cultivar, which reported this.