Repository navigation
Description
Summary
Storage pricing is hardcoded to us-east-1 rates in two separate places, and the config fields
that exist to make it region-aware are ignored. Cost estimates are wrong for every other
region.
Background
internal/cost/pricing.go carries literal us-east-1 rates (0.023, 0.0125, 0.004, 0.0036,
0.00099 $/GB/month). The same numbers are duplicated in StorageTierInfo.CostPerGBMonth in
internal/storage/s3/tiers.go:
TierStandard: {
// ...
CostPerGBMonth: 0.023, // Approximate USD
},Two copies drift independently, and neither is correct outside us-east-1 — regional S3 pricing
varies materially (some regions are 20-30% higher). Cost-optimization decisions and tier
recommendations are made from these numbers.
Meanwhile s3.PricingConfig already declares the fields needed to fix this:
UsePricingAPI bool `yaml:"use_pricing_api"`
Region string `yaml:"region"`Neither is honored anywhere. Region defaults to "us-east-1", which is at least an honest
description of current behavior.
Implementation
- Establish one source of truth for per-tier storage rates and have the other site reference
it rather than restating the numbers.StorageTierInfoshould keep tier characteristics
(minimums, embargoes, latency); pricing belongs in the cost package. - Make lookups region-aware, keyed on
PricingConfig.Region, falling back to us-east-1 with a
logged warning when a region has no table entry. - Honor
UsePricingAPIas opt-in: when true, fetch from the AWS Pricing API and cache;
when false (default), use the static table. Keep the static path working with no
credentials and no network — cost estimation must not become a hard dependency on another
AWS service. - Have
CostOptimizationandGetRecommendationsread through the same accessor.
Document that static rates are approximate and dated, since they will drift regardless.
Acceptance Criteria
- Per-tier storage rates are defined once; no duplicated literals
- Cost calculations use
PricingConfig.Region - An unknown region falls back to us-east-1 with a warning rather than returning zero
-
UsePricingAPI: false(default) needs no credentials and no network -
UsePricingAPI: truefetches and caches live pricing - Tier recommendations reflect region-specific rates
-
go test -race ./internal/cost/... ./internal/storage/s3/...passes
Dependencies
None.
Activity
scttfrdmn commentedon Jul 30, 2026
Correction: the framing is partly wrong — the config is honored, the extractors are stubs
Two claims in this issue do not hold, and the real defect is elsewhere.
UsePricingAPIandRegionare both honored.PricingManager.getBasePricing(internal/storage/s3/pricing_manager.go:81) branches on the flag:and
fetchFromPricingAPIinterpolates the configured region into the endpoint (pricing_manager.go:100). So "nothing honors them" is incorrect — the plumbing is there.The actual defect is that the extractors are stubs. After fetching the AWS pricing index — a document on the order of 100 MB — the parse is discarded:
(
pricing_manager.go:193-201)So enabling
UsePricingAPIdownloads ~100 MB over HTTP and returns two hardcoded us-east-1 constants — strictly worse than leaving it off, which returns the same numbers for free. Note also that0.023is returned for every tier, so with the API enabled all tiers price identically, which is worse than theStorageTiersdefaults it bypasses.internal/costis 100% dead code. Grep forobjectfs/internal/costacross all Go files returns zero importers. The issue proposes consolidating it withpricing_manager.go, but there is nothing depending on it to preserve. That makes deletion the cheaper option and turns this into a decision rather than a refactor:internal/costand keeppricing_manager.goas the single source. Least code, no migration.internal/costcontains logic worth keeping thatpricing_manager.golacks — needs a read-through to establish, not assumed.Suggested adjustment
terms.OnDemand->priceDimensionstraversal, ~100 MB fetch needing caching and a disk-backed TTL). GivenUsePricingAPIdefaults tofalseand the staticStorageTiersnumbers are adequate for cost estimation, removing the half-built API path and documenting the rates as approximations is the better trade unless accurate live pricing is a stated requirement.internal/costdelete-vs-consolidate as part of this.StorageTierInfo.CostPerGBMonth(tiers.go) andgetDefaultPricing, and should have one home regardless of which route is taken.scttfrdmn commentedon Jul 30, 2026
Two amendments to this issue
1. The Pricing API path is removed, not implemented — acceptance criteria 5 is withdrawn
Criterion "
UsePricingAPI: truefetches and caches live pricing" assumed the existing integration was a working foundation. It was not. ReadingfetchFromPricingAPIandparsePricingData:parsePricingDatamatched products onproduct.Attributes["storageClass"] == "General Purpose"/"Infrequent Access"— human-readable names produced bymapTierToStorageClassthat do not appear in the Pricing API payload under that attribute. The loop never matched.So
UsePricingAPI: truedownloaded a multi-megabyte JSON index over HTTP, decoded it, and then returned0.023/0.01per GB — the same constants the static table already provides, minus the latency and the failure mode. The parsing work the comment defers to was never done.Removed rather than left in place, so nobody mistakes it for a partial implementation to finish:
fetchFromPricingAPI,parsePricingData,mapTierToStorageClass,extractStorageCost,extractRetrievalCost,getBasePricing, and theAWSPricingResponse/AWSProducttypes.GetTierPricingnow callsgetDefaultPricingdirectly.RefreshPricingis a documented no-op anduse_pricing_apilogs a deprecation warning at startup. Real Pricing API support, if wanted, should be filed fresh — it is a feature, not a bug fix, and it belongs behindpricingv2.GetProductswith a propertermswalk rather than the raw offer-file URL.The remaining scope of this issue — one source of truth for rates, region-aware lookups, us-east-1 fallback with a warning — is unchanged and still wanted.
2. Correcting myself on
internal/cost: it should be kept, not deletedI earlier recommended deleting
internal/coston the grounds that it has zero importers and duplicates the rate table inpricing_manager.go. That recommendation was wrong, and it was based on an incomplete reading of the package. The zero-importer finding is accurate; the conclusion I drew from it is not.The duplication is confined to the rate literals. Everything else in those ~1,200 lines has no counterpart anywhere in the repo:
pricing_manager.go?Calculator.CalculateReporter.RecordOp/Report/ReportAllTenantRecordAlertManager+BudgetRule+AlertCostReportpricing_manager.goanswers "what does a GB cost in this tier";internal/costanswers "what has this tenant spent, and are they over budget". Deleting it would delete the only implementation of #65 and leave the rate table with no consumer at all.It is unwired, not redundant — the fix is to wire it up, which is the deduplication half of this issue.
In the meantime I added
internal/cost/pricing_drift_test.go, a tripwire that fails when the rates ininternal/cost/pricing.godiverge fromStorageTierInfo.CostPerGBMonth, and that fails if a new tier is added to one table and not the other. It does not fix the duplication — it just stops the two copies drifting silently before this issue is worked, and it gives the consolidation a ready-made regression check.scttfrdmn commentedon Aug 2, 2026
Moved to v0.11.0. Re-verified against
mainate969ff7rather than assumed — still fully open:internal/storage/s3/pricing_manager.go:39-40defaultsRegiontous-east-1:266is the only read ofpm.config.Regionin the file, and it is a label on a summary structSo region remains decorative:
region: us-west-2yields us-east-1 numbers labelled us-west-2.One additional finding while checking, which belongs on this issue because it is the same table:
pricing_manager.go:126has Standard PUT at0.0005per 1000 requests.internal/cost/pricing.go:47hasPutRequest: 0.000005with the comment// $0.005 / 1000. The real AWS rate is $0.005/1000, sopricing_manager.gois 10× low on Standard PUT.And
internal/cost/pricing.go:48carries this comment:They do not match. That comment is load-bearing — it is why nobody reconciled the two tables — and
pricing_drift_test.go:34cannot catch the disagreement because it compares onlyStoragePerGBMonth. Whatever fixes region-awareness should collapse these tables to one source and extend the drift test past the storage rate.scttfrdmn commentedon Aug 3, 2026
Fixed in 7c70dc0 on
v0.11.0-cli-subcommands.What was wrong.
pricing_config.regionwas read at one line in the repository, and only to label a summary. Every rate came from a package-level table built atinit, which cannot see a configuration, so every cost ObjectFS reported was us-east-1's no matter what the operator configured.region: sa-east-1produced us-east-1 numbers labelled sa-east-1, and Standard storage in sa-east-1 is 76% above us-east-1.The acceptance criterion. An unknown region falls back to us-east-1 with a warning rather than returning zero —
awsrates.ForRegionreturns the fallback rate plus a bool, and bothNewPricingManagerandNewTierValidatorwarn once at construction naming the region asked for and the region used. Warning once rather than per lookup becauseGetTierPricingis reachable fromGetObjectviaRecordAccess, so it is on the read path.Rates are now generated, not written. 36 regions × 8 storage classes × 6 rates in
internal/awsrates/rates_generated.go, produced by the newinternal/awsrates/offerfilepackage from AWS's public per-region price list offer files. Those need no credentials, sogo generate ./internal/awsrates/...refreshes every number in one command anyone can run. Not the Pricing API: it needs credentials, and its Go client forces smithy-go ≥1.26.0 under the S3 client on the data path.A second defect this found. Glacier PUT was reading
Requests-Tier3, which is the restore price — 67% too high.usagetypealone is not a key for a rate;Requests-GLACIER-Tier1has 15 SKUs at 2 prices, separated by theoperationattribute. The test that existed to catch exactly this agreed with it: it transcribed the queries a second time and namedRequests-Tier3for Glacier PUT itself. It also shelled out toaws pricing get-products, so it skipped without a configured profile — including in CI, and a drift check that skips is not a drift check. It now fetches the same offer files over plain HTTPS, drives its queries fromofferfile.Queries()instead of a second copy, and compares the whole committed table across five regions spanning every band AWS publishes.StorageTierInfo.CostPerGBMonthis removed, not corrected. A rate on a package-level struct cannot know which region produced it, and that field was the mechanism by which the region became decorative. Filling it from the configured region would put a region-specific number on a value shared process-wide by every manager — the same defect with an extra step. The compiler found the callers.Verification. 12 mutations across
lookup, theawsratesregion accessors,PricingManager.StorageRate, and the generator's skip/refuse-to-write rules; all 12 caught. A 13th on the generated table itself (0.0405→0.0406) is caught by the live drift test, which passed against AWS with no credentials across 5 regions × 8 classes × 6 fields.internal/awsratesis at 100% coverage, the generator command at 74.4%, all three floors recorded in.coverage-floors. Full gate set green: build,gofmt,go test -racewith zero failures, coverage gate 34/34,golangci-lint --new-from-merge-base=origin/mainat 0 issues.Deliberately not in scope.
internal/costandinternal/analyticsstay region-blind, now stated in code rather than left silent: nothing imports either package, so a region argument there would have no caller to be wrong for, and the region belongs in a constructor that a package-level var cannot have.v0.11.0: subcommands, a security gate, and prices that know their region