Repository navigation
feat(metrics): a mount publishes what it is spending at AWS (#226) - #408
Merged
Merged
Conversation
The rates were already right. internal/awsrates holds one S3 rate table, verified against the live Pricing API by an integration test that re-reads 23 rates and fails on any difference — and every path from a rate to a user was severed. The access-pattern report was gated behind a config key no mount could set, internal/cost had zero importers, and metrics.RecordCost had no caller anywhere. objectfs_s3_cost is the path: billable request counts by pricing group, bytes retrieved, three dollar figures, and beside each the rate it was computed at, labelled with the resolved region and the storage tier. Counted in the SDK's Deserialize step, not at the wrapper layer. The eight places this backend records metrics are not one-to-one with billable calls: a 5 GB PutObject is one wrapper call and 641 requests to S3, and a large CopyObject, a parallel ranged read and the capability probes fan out the same way — one of them counted nowhere at all. Every one of those errors flatters. A middleware where the SDK deserializes cannot disagree with what S3 received because it is what S3 received. Per attempt, since the retryer re-enters that step; only with a response, since a connect failure never reached S3; only below 500, because AWS does not bill its own server errors and does bill 4xx. Four pricing groups rather than AWS's two request tiers, because on DEEP_ARCHIVE a PUT is $0.05/1,000 and a LIST is $0.005/1,000 — a factor of ten. An unrecognized operation counts as a write, the most expensive group, so a case this code has never heard of overstates rather than hides. Verified against a recording proxy rather than against the counter's own arithmetic: the tests compare what the tally counted with what the endpoint received, including a multipart write where the count must also exceed the part count, and an injected 500 where the counted total must equal the observed total minus the server errors. Seven mutations were run and each was caught by a test naming the actual defect, including the binary GB divisor at ratio 0.9313. Two things deleted rather than left as a second path to a cost figure: internal/cost — 710 lines plus 540 of tests, a per-tenant calculator with no importer and no configuration path to the tenants or budgets it was built around. Two cost-calculation packages where one is unreachable is the arrangement that produced #209's 10x disagreement. Its drift guard moved to internal/storage/s3 and now asserts every rate reachable through PricingManager is awsrates' own value exactly, for every class the loader accepts — verified by mutation. metrics.RecordCost and CostMetrics — it took prices as float64 dollars, so every rate would have been the call site's rather than awsrates'. Two of its calculations were also wrong past any wiring: cost per GB over 1<<30 where AWS bills decimal GB, and a monthly estimate extrapolated from process uptime, so a mount thirty seconds old reported its first half-minute as the month's rate.
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 #226.
The rates were already right.
internal/awsratesholds 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) — and every path from a rate to a user was severed. The access-pattern report was gated behind a config key no mount could set,internal/costhad zero importers, andmetrics.RecordCosthad no caller anywhere.What lands
objectfs_s3_cost, a gauge family withstatistic,regionandtierlabels, carrying billable request counts by pricing group, bytes retrieved, three dollar figures, and beside each figure the rate it was computed at.Counted in the AWS SDK's Deserialize step, not at the wrapper layer, and that is the substance of it. The eight places this backend records metrics are not one-to-one with billable calls: a 5 GB
PutObjectis one wrapper call and 641 requests to S3 — oneCreateMultipartUpload, 639UploadParts, oneCompleteMultipartUpload. A largeCopyObject, a parallel ranged read, and the capability probes fan out the same way, one of them counted nowhere at all. Every one of those errors is in the direction that flatters. A middleware where the SDK deserializes cannot disagree with what S3 received, because it is what S3 received; it goes in throughclientOptions, so the standard client, the accelerated client and every client the pool factory builds are all counted — a factory that skipped it once sent four operations to real AWS.Three billability decisions, each with a distinct failure mode:
HeadObjectreturning 404 is a charged read. Counting 5xx would inflate the figure during exactly the incident an operator is using it to investigate; dropping 4xx would hide a misconfigured mount retrying a 403.Four pricing groups rather than AWS's two request tiers: writes, lists, reads, free. Lists are separate even though the price list calls both "Tier1", because on DEEP_ARCHIVE a PUT is $0.05/1,000 and a LIST is $0.005/1,000 — a factor of ten, and pricing a traversal at the write rate overstates it worst on the class where the error is largest. An unrecognized operation counts as a write, the most expensive group, so an operation this code has never heard of overstates rather than hides.
What the figures are is stated narrowly: this process's spend since it started, at list prices for the first volume band. Not a bill.
bytes_storedis what this mount uploaded, not the bucket's size — nothing lists the bucket, since that would be a billed request per scrape to publish a metric. Monotonic with no reset, because rate-of-change is the form a useful alert on cost takes. A fresh mount reportsread_requestsof 1:NewBackend's health check is aHeadBucket, AWS bills it, and the tests assert that 1 rather than asserting zero.Verification
The recording proxy is the oracle, not the counter's own arithmetic:
Seven mutations run, all caught, each by a test naming the actual defect:
Listcase removedrequestGroupOf("ListObjectsV2") = 0, want 1>= 500→>= 599CostStats()hoisted out of the publish closureBoth SDK suites pass against the regenerated
sdks/testdata/metrics-scrape.txt: Python 73 passed / 31 subtests, TypeScripttscclean and 66 tests. The fixture pins a non-default region and tier (us-west-2, STANDARD_IA) so an extractor that reads the family as one series per statistic fails there, and the figures reconcile by hand.Two deletions rather than a second path to a cost figure
internal/cost— 710 lines plus 540 of tests:Calculator,Reporter,AlertManager, per-tenant accumulation, ROI reporting, budget alerts. Zero importers, and no configuration path ever existed for the tenants or budgets it was built around; being underinternal/it cannot acquire an out-of-module caller either. Two cost-calculation packages where one is unreachable is precisely the arrangement that produced #209 — the same rate in five places, two disagreeing by a factor of ten. Itspricing_drift_test.gowas the guard against that shape and the half worth keeping moved tointernal/storage/s3, where it now asserts every rate reachable throughPricingManagerisawsrates' own value exactly, for every class the loader accepts — storage, PUT, GET, LIST and retrieval, not storage alone, since a partial regression leaving requests on constants passes a storage-only check. Verified by mutation: a private PUT rate fails it with the ratio named, and a round factor of ten in that ratio is reported as what it is.metrics.RecordCostandCostMetrics— the issue asked to wire it or delete it but not to leave a third unreachable path. It could not usefully be wired: it took request, storage and transfer costs asfloat64dollars, so every price would have been the call site's rather thanawsrates'. Two of its calculations were also wrong past any amount of wiring — cost per GB over1 << 30where AWS bills decimal GB, andEstimatedMonthlyCostextrapolated from process uptime, so a mount thirty seconds old reported its first half-minute as the whole month's rate, most wrong exactly when someone is most likely to read it. The rest ofDetailedPerformanceMetricsstays; #222 assigned its percentiles and fixed its histogram this release, so only the cost half was dead.Items 1 and 2 of the issue — splitting
MonitorAccessPatternsfrom the silent tier override, and correcting the stale race comment atadapter.go— landed earlier this release;SmallObjectsOnStandardis now its own key and the comment states the real reason. The issue's region caveat forinternal/costis moot with the package gone.Gate
go build ./...,gofmt -l .,go vet ./...,golangci-lint runall clean;go test -race ./...passes with no data races. Theinternal/cost 98coverage floor is out of.coverage-floors, with a note that 98% covered and not part of the product is the lessonpkg/api's floor carried.