Documentation
¶
Overview ¶
Package costestimate is a deterministic, pure-Go engine that turns an app's CPU/memory allocation into an ESTIMATED monthly cost under a few generic reference pricing profiles (a plain VM, a managed VM, a metered container PaaS). Not a real bill: it never calls a pricing API or reflects actual hardware cost, only a comparative "what would this cost under typical metered cloud pricing" number.
Index ¶
Constants ¶
const ( BasisDeclared = "declared" BasisObserved = "observed" )
Basis records whether a dimension's size came from a configured resource limit or was inferred from observed usage history, so the caller can say which one a given estimate rests on.
const ( ProviderVM = "vm" ProviderManagedVM = "managed_vm" ProviderMeteredPaaS = "paas" )
Provider keys, also the env var infix (uppercased) for overrides.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Input ¶
type Input struct {
ServiceName string
DeclaredNanoCPUs int64
DeclaredMemoryBytes int64
ObservedCPUPercentSamples []Sample
ObservedMemoryBytesSamples []Sample
}
Input bundles one app's declared resource limits and, when a limit isn't configured, the observed usage samples to fall back to. CPUPercentSamples follows Docker's own 0-100-per-core convention (matching internal/rightsizing.Input's own doc comment): a container fully using 2 cores reads 200.
type MonthlySaving ¶
MonthlySaving is the estimated monthly drop when an app moves from its declared size to a suggested one, under the first provider of table.
func Saving ¶
func Saving(currentMemoryBytes, currentNanoCPUs, suggestedMemoryBytes, suggestedNanoCPUs int64, table RateTable) (MonthlySaving, bool)
Saving prices both sizes with the same rate table and returns the difference. ok is false when no size is declared, the table is empty or the suggestion would not cost less, so callers never show a negative saving.
type Provider ¶
type Provider struct {
Key string
Label string
CPUPerCoreUSD float64
MemoryPerGiBUSD float64
MinimumUSD float64
}
Provider is one reference pricing profile: a flat $/vCPU-core/month and $/GiB-month rate, plus a minimum monthly charge (most real providers bill a floor even for a tiny instance). Key is the stable identifier used in JSON and in APP_COST_ESTIMATE_<KEY>_* env overrides; Label is what a human reads.
type ProviderEstimate ¶
type ProviderEstimate struct {
Key string
Label string
CPUCostUSD float64
MemoryCostUSD float64
TotalUSD float64
MinimumApplied bool
}
ProviderEstimate is one reference provider's resulting monthly cost, split into its CPU and memory components so the UI can show a breakdown rather than just a total.
type RateTable ¶
type RateTable struct {
Providers []Provider
}
RateTable is the full set of reference providers an estimate is computed under. Every number here is illustrative, not fetched from any live pricing source, and is meant to be corrected per-operator via env vars for their own region/provider.
func DefaultRateTable ¶
func DefaultRateTable() RateTable
DefaultRateTable returns the built-in reference rates: a bare unmanaged cloud VM, a managed VM (backups/support bundled in), and a metered container PaaS (Heroku/Render/Railway-shaped pricing, which bundles a real margin over raw compute). These are deliberately round, approximate numbers for 2026-era budget cloud pricing, not any single real provider's rate card. Override any of them with APP_COST_ESTIMATE_<KEY>_CPU_USD, APP_COST_ESTIMATE_<KEY>_MEMORY_USD, APP_COST_ESTIMATE_<KEY>_MINIMUM_USD.
func RateTableFromEnv ¶
func RateTableFromEnv() RateTable
RateTableFromEnv applies APP_COST_ESTIMATE_<KEY>_CPU_USD, APP_COST_ESTIMATE_<KEY>_MEMORY_USD and APP_COST_ESTIMATE_<KEY>_MINIMUM_USD overrides to DefaultRateTable's providers (KEY is the provider's own Key, uppercased: VM, MANAGED_VM, PAAS). A malformed or negative value keeps the default, matching SLOPolicyFromEnv's own "bad input is ignored, not fatal" contract.
type Result ¶
type Result struct {
ServiceName string
VCPUCores float64
MemoryGiB float64
CPUBasis string
MemoryBasis string
Providers []ProviderEstimate
}
Result is Estimate's output: the resolved CPU/memory size this estimate is based on, which basis (declared vs observed) produced each dimension, and one ProviderEstimate per reference provider in table, in table order.
func Estimate ¶
Estimate computes in's estimated monthly cost under every provider in table. The same Input and RateTable always produce the same Result. This is an ESTIMATE only: it reflects the declared or observed resource envelope under illustrative reference rates, never a real invoice from any provider.