Repository navigation
fix(cost): --cost-limit counts public IPv4, EBS IOPS/throughput and late-attached resources; one accounting for enforcement and displays (#51) - #1340
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…esources in --cost-limit; one accounting for enforcement and displays (#51) Enforcement (spored) and every cost display (spored status, spawn status, spawn cost, spawn extend's decideCostLimit) now go through pkg/costmodel.Accrue, so what is shown is what is enforced. - public IPv4 ($0.005/hr per address, VPC pricing page 2026-10-26): auto-assigned over compute time, Elastic IPs (incl. the multi-interface EFA launch EIP) over the wall clock; counted from the instance's actual addresses on every interface - EBS: provisioned IOPS (gp3>3000, io1, io2 tiered) and gp3 throughput - footprint re-measured on every start and every 15 min, recorded rates never decrease (was: measured once at first boot) - EBS no longer dropped from the cap when spawn:launch-time is missing - spored status priced EBS over stopped time only; now wall clock Fixes #51
scttfrdmn
force-pushed
the
fix/51-cost-accounting
branch
from
October 26, 2026 23:52
7f90ce5 to
a57ad7a
Compare
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.
Fixes #51
Every under-count makes
--cost-limitfire late, which leaks cost. This PR closes the under-counts it found and puts enforcement and every display on one accounting function,pkg/costmodel.Accrue. spored'saccumulatedComputeCost,spored status, the not-runningspawn status,spawn cost <instance>, the billable-resources block andspawn extend'sdecideCostLimitall call it.Inventory: what a spawn instance bills, and whether the cap counts it
costLimitPreflightand listed separatelyRate used: enforcement prices compute at the on-demand
spawn:price-per-hour, which can only over-count a spot instance. Displays price compute at the spot price where one was recorded, and the stoppedspawn statusnow also shows "Cost limit: $X counted at the on-demand rate".Static rates are labelled in
pkg/costmodel(RatesAsOf = 2026-10-26). They come from https://aws.amazon.com/vpc/pricing/ ("Hourly charge for In-use Public IPv4 Address $0.005", the same for idle) and https://aws.amazon.com/ebs/pricing/, both fetched 2026-10-26. The VPC page carries no date of its own. The charge has applied since 2024-02-01. They are static because spored enforces from inside the instance with no Price List permission. Where the page was ambiguous I took the higher figure: gp3 throughput at $0.06 per MB/s-month, and io2 above 64k IOPS at the tier-2 rate.Other under-counts fixed
LookupAndTagEBSCostreturned early oncespawn:ebs-hourly-costwas set.MeasureCostFootprintreplaces it and measures on every start and every 15 ticks, off the ticker goroutine and never stacked. The launch EIP is associated after the instance is running, so spored's first look can come before it. A recorded value never decreases: the current footprint is priced over the whole life, so lowering it would forgive cost already incurred.spawn:launch-timetag meant EBS dropped out of the cap: the wall-clock anchor now falls back to IMDS pendingTime.spored statuspriced EBS over stopped/hibernated time only, so a running instance showed none of the EBS the cap counted. It now uses the wall clock since launch, and its cumulative figure matches cost-limit used on an on-demand instance.IPv4 counts come from the instance's own addresses (
costFootprintOf): every interface, every private address's association, deduplicated.IpOwnerId == "amazon"means auto-assigned, anything else is an Elastic IP. New tags:spawn:public-ipv4-countandspawn:elastic-ipv4-count, written by spored with the same self-CreateTagsit already used. DescribeInstances and DescribeVolumes were already granted (#517). No new permission.Over-counts (the less harmful direction, noted, not fixed)
spawn cost/spawn statuson a terminated instance keep accruing wall-clock EBS after termination (display only). Filed as a follow-up.Residual under-counts (not fixed)
spawn upgrade-spored.spawn statusandspawn costsay so when the IPv4 tags are absent.spawn:price-per-hour(unchanged, --cost-limit is enforced against a fabricated rate: an $8 cap on g6e.xlarge does not fire until $74 #533).Gates (each watched failing against a compiling revert)
TestAccrue_EachComponentInEachState: the table above as code, components × {running, stopped, hibernated, terminated}, expectations taken from the doc's billing rules. Fails with IPv4 zeroed, with the EIP on the compute clock, and with EBS on the compute clock.TestVolumeHourly_CountsProvisionedPerformancefails with io2 IOPS dropped.TestCostFootprintOf_PricesEveryAttachedVolumefails with root-only pricing.TestCostFootprintOf_CountsEveryPublicIPv4covers the multi-interface EFA launch EIP, a single interface, an EIP on a secondary private IP, and no address. It fails with secondary associations ignored and with EIPs not counted.TestCountIPv4also fails in the second case.TestCostDisplaysAndExtendShareTheEnforcedAccountingchecks that the stopped status,spawn cost"Est. total",decideCostLimitNeeded/PerHour and the billable IPv4 row all equalAccrueover the enforced footprint. It fails when extend uses the old formula, when the stopped total drops IPv4, and whenspawn costuses its own footprint.TestNoCostRateTagReadOutsideTheModelwalks the module, fails on empty discovery, and matches tag names used as values, not prose. It fails on a directtags["spawn:public-ipv4-count"]read in cmd/.TestAccumulatedCost_IsCostmodelAccruefails when enforcement ignores the IPv4 counts.TestAccumulatedCost_NoLaunchTagFallsBackToPendingTimefails without the fallback.TestCheckAndAct_RemeasuresCostFootprintfails with the tick call disabled.TestMaybeMeasureCostFootprint_NeverStacksfails without the CAS guard. Both use seams, with no timing.TestFootprintTagWrites_NeverLowersfails when a lower value is written.TestStatusCostIsTheEnforcedAccounting(spored status) fails with storage priced over not-running time only.Checks
make check: fmt, vet (all GOOS), staticcheck, golangci-lint (0 issues, 10 modules), hermetic short tests, nested modules and tidy all pass.check-build-tagsfails on the/private/tmppath issue, which also fails on unmodified main.make check-docspasses (docs-gen regenerated for thecosthelp and--cost-limitflag text).semgrep scan --config=auto --error .is clean. No exported pkg/aws or pkg/launcher API change. User data is untouched.