Repository navigation
Description
Split from #183, which asks as its step 0 whether cost tracking is a feature of this product. It is not one today, and this is the issue that makes it one — or establishes that it should not be.
The measurement
internal/awsrates now holds one S3 rate table, verified against the live AWS Pricing API by an integration test that re-reads 23 rates and fails on any difference (#220, #225). The rates are correct. Every path from a rate to something a user can see is severed:
internal/awsrates (accurate, single-sourced, live-API checked)
│
├─► s3.PricingManager.GetTierPricing ......... reachable from Backend ✓
│ └─► CostOptimizer.calculateObjectCost
│ └─► RecordAccess ........... returns on its first line
│
├─► internal/cost (Calculator, Reporter, AlertManager)
│ └─► ZERO importers outside itself
│
└─► internal/analytics/model.go ............... reached from internal/cache,
but the Predictor field is never set on the mount path
| output method | non-test callers |
|---|---|
GetTierPricingWithDiscounts |
0 |
GetAccessPatternCount |
0 |
GetCostOptimizationReport |
1 — an example in doc.go |
metrics.RecordCost |
0 anywhere, so CostMetrics is never populated |
cmd/objectfs |
no cost output of any kind |
RecordAccess is called from GetObject on both the serial and parallel read paths — and returns immediately, because MonitorAccessPatterns is false and buildS3Config does not map it.
What blocks it, and what no longer does
internal/adapter/adapter.go:503 gives two reasons for holding MonitorAccessPatterns back. One is now stale and one is not.
Stale: "it writes an unsynchronized map from the read path." That was audit finding M12 and the lock has landed — cost_optimizer.go:45-46 now has mu sync.RWMutex guarding accessPatterns, and the comment above it records that the lock deliberately went first because the fix for the config knob turns the race on. That sequencing worked; the comment in adapter.go was not updated to match, and should be.
Not stale, and the real blocker:
// backend.go:744-746
if b.config.CostOptimization.MonitorAccessPatterns {
effectiveTier = b.costOptimizer.HandleStandardTierOverhead(key, int64(len(data)))// cost_optimizer.go:484-492
func (co *CostOptimizer) HandleStandardTierOverhead(objectKey string, objectSize int64) string {
if objectSize < 128*1024 {
return TierStandard
}So a flag whose name says monitor also silently rewrites the storage class of every object under 128 KiB to Standard, overriding what the user configured. The intent is defensible — the IA classes bill a 128 KB minimum, so a 4 KiB object on STANDARD_IA is charged as 128 KB and Standard is genuinely cheaper — but it is not what "monitor access patterns" says, and a user who set storage_class: STANDARD_IA gets Standard for most of their objects with a Debug-level log line.
One flag doing two unrelated things, one of them observability and the other a silent policy override, is why it cannot simply be mapped.
Scope
- Split the flag.
MonitorAccessPatternsrecords patterns and nothing else. The tier override becomes its own key with a name that says what it does (avoid_ia_minimum_charge, or similar), documented with the arithmetic that justifies it, and defaulting to off — an override of an explicit user choice should be opted into. - Update
adapter.go:503to drop the stale race reason and state the real one. - Expose cost through the Prometheus surface, not through a method nothing calls.
internal/metricsalready publishes cache and operation telemetry; cost belongs beside it, as counters a user can scrape and graph.metrics.RecordCostexists and has no caller — either wire it or delete it, but do not leave a third unreachable path. - Decide
internal/cost's fate. Zero importers, andCalculator/Reporter/AlertManageroverlap whatCostOptimizerdoes. Either it becomes the calculation layer the metrics surface calls, or it goes. Two cost-calculation packages where one is unreachable is the arrangement that produced the 10× disagreement Real AWS Pricing API integration — and the 10x-low Standard PUT rate the static tables disagree on #183 found. - Verify with a real mount. Read and write objects, scrape the endpoint, check the figures against hand-computed values from
internal/awsrates. The unit test that matters is the one asserting a dollar figure as a literal, per the lesson in fix(cost): one rate table, checked against the live AWS Pricing API #220: the old tests passed1024*1024*1024bytes, called it "one GB", and asserted the per-GB rate came back — an expectation that holds under both the right divisor and the wrong one.
Why this comes before the Pricing API
#183 states it: "Getting real prices into a calculator no code calls is the most expensive way to change nothing." Live prices are worth fetching once a figure reaches a user, because then a wrong figure is visible and a right one is useful. Until then the accuracy work has no consumer to be accurate for.
The follow-on API work is tracked separately, carrying #183's verified traps.
Note on region
pm.config.Region is read at exactly one line, to stamp a summary field. Every rate is us-east-1, so region: us-west-2 produces us-east-1 numbers labelled us-west-2 — worse than no number, because the label makes it look checked. internal/awsrates' package doc states plainly that its rates are us-east-1, first volume band, Standard retrieval on the Glacier classes, which makes the table honest but not the summary. Do not publish a region-labelled cost metric until the rates are region-correct — that belongs with the API work. Publish unlabelled, or label them us-east-1 list price, which is what they are.
Activity
feat(metrics): a mount publishes what it is spending at AWS (#226) (#408