prices

package
v0.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

The price book: AWS's on-demand list prices of what a nap stops, from the Price List API, cached per region and item, and Spot prices and discounts. Ports createPriceBook of fleet/src/prices.ts.

The Price List answer's parsing. Ports onDemand of fleet/src/prices.ts.

Ports of the price book: the Price List API, EC2's Spot price history and the price cache. Ports fleet/src/prices.ts (PricingPort, SpotPort, PriceCache) and api/src/spot.ts (the Spot port's shape). Adapters over the AWS SDK live elsewhere; this package imports none.

A period's estimated savings: each ASLEEP phase's hours within the baseline times the hourly list prices of what its nap stopped. What cannot be priced is listed with its hours, never counted as nothing saved. Ports fleet/src/savings.ts.

The Spot price of a type. Ports spotAverage of fleet/src/prices.ts (the Spot port's adapter, api/src/spot.ts createSpotPort, is built over the AWS SDK elsewhere).

Index

Constants

View Source
const FargateSpotShare = 0.3

FargateSpotShare is AWS's largest announced Fargate Spot discount (up to 70% off), as AWS publishes no Fargate Spot price: the smallest saving.

Variables

View Source
var DormetoCost = Cost{Manager: 5, Router: 0.26, Workload: 0.13}

DormetoCost is Dormeto's estimated cost a month (vision docs/architecture/costs.md): the manager, a router per account and region with workloads, each workload; the savings job and the estimate before install net it off.

Functions

func BaselineHours

func BaselineHours(from, to string, b Baseline) (float64, error)

BaselineHours is the hours of [from, to] the baseline would have run. A period that is not valid is 0 hours; a time zone that is not an IANA name is an error (Node's Intl throws a RangeError), where the period is not empty.

Types

type Baseline

type Baseline struct {
	Kind     string `json:"kind"` // "always" or "business-hours"
	TimeZone string `json:"timeZone,omitempty"`
}

Baseline is when the workload would have run anyway: always, or weekdays 08:00 to 20:00 in a time zone.

type Book

type Book struct {
	// contains filtered or unexported fields
}

Book prices the items a nap stops.

func NewBook

func NewBook(pricing PricingPort, spot SpotPort, cache Cache, now func() time.Time) *Book

NewBook makes a price book over the ports. spot may be nil (no Spot prices); now nil is the clock.

func (*Book) Hourly

func (b *Book) Hourly(ctx context.Context, region string, item stopped.Item, d Discounts) (*float64, error)

Hourly is the USD an hour of an item, in its region, net: a Spot price, or the list price less its family's discount; nil when it cannot be priced. An error is the price cache's (a failed API call prices nothing instead).

type Cache

type Cache interface {
	GetPrice(key string) (*Price, error)
	PutPrice(key string, usd *float64, days int) error
}

Cache keeps a price per key, nil USD when the API has none, for days. GetPrice returns nil for a key not cached (or expired).

type Cost

type Cost struct {
	Manager  float64 `json:"manager"`
	Router   float64 `json:"router"`
	Workload float64 `json:"workload"`
}

Cost is Dormeto's estimated cost a month by part.

type Discounts

type Discounts struct {
	Compute   float64 `json:"compute"`
	Databases float64 `json:"databases"`
}

Discounts are percentages off the list prices for commitments: compute (EC2, Fargate), databases (RDS, Aurora). Never off Spot.

type Filter

type Filter struct {
	Type  string `json:"Type"`
	Field string `json:"Field"`
	Value string `json:"Value"`
}

Filter is a Price List filter.

type GetProductsInput

type GetProductsInput struct {
	ServiceCode string   `json:"ServiceCode"`
	Filters     []Filter `json:"Filters"`
	MaxResults  int      `json:"MaxResults,omitempty"`
}

GetProductsInput is the Price List API's GetProducts input.

type GetProductsOutput

type GetProductsOutput struct {
	PriceList []json.RawMessage `json:"PriceList,omitempty"`
}

GetProductsOutput is its answer: each product as a JSON string (or an object).

type Phase

type Phase struct {
	State   string         `json:"state"`
	From    string         `json:"from"`
	To      string         `json:"to"`
	Stopped []stopped.Item `json:"stopped,omitempty"`
}

Phase is a period of one state of a workload's history (fleet/src/history.ts), with what its nap stopped. Stopped nil is a phase not described; an empty one stops nothing.

type Price

type Price struct {
	USD *float64 `json:"usd"`
}

Price is a cached price: USD nil when the API has none (a null).

type PricedItem

type PricedItem struct {
	Item   stopped.Item `json:"item"`
	Hourly float64      `json:"hourly"`
	Hours  float64      `json:"hours"`
	USD    float64      `json:"usd"`
}

PricedItem is an item with its hourly price and the hours it was stopped.

type PricingPort

type PricingPort interface {
	GetProducts(ctx context.Context, in GetProductsInput) (GetProductsOutput, error)
}

PricingPort is the Price List API (GetProducts).

type Savings

type Savings struct {
	USD      float64      `json:"usd"`
	Hours    float64      `json:"hours"` // asleep hours within the baseline
	Items    []PricedItem `json:"items"`
	Unpriced []Unpriced   `json:"unpriced"`
}

Savings is a period's estimated savings.

func SavingsOf

func SavingsOf(ctx context.Context, phases []Phase, hourly func(context.Context, stopped.Item) (*float64, error), baseline Baseline) (Savings, error)

SavingsOf prices each ASLEEP phase's hours within the baseline by what it stopped, through hourly (nil: not priced).

type SpotHistoryInput

type SpotHistoryInput struct {
	InstanceTypes       []string  `json:"InstanceTypes"`
	ProductDescriptions []string  `json:"ProductDescriptions"`
	StartTime           time.Time `json:"StartTime"`
}

SpotHistoryInput is DescribeSpotPriceHistory's input as the price book asks.

func (SpotHistoryInput) MarshalJSON

func (in SpotHistoryInput) MarshalJSON() ([]byte, error)

MarshalJSON writes StartTime as Node's toISOString does (2026-10-12T08:00:00.000Z), the form recorded inputs are compared in.

type SpotHistoryOutput

type SpotHistoryOutput struct {
	SpotPriceHistory []SpotPrice `json:"SpotPriceHistory,omitempty"`
}

SpotHistoryOutput is DescribeSpotPriceHistory's answer.

type SpotPort

type SpotPort interface {
	History(ctx context.Context, region string, in SpotHistoryInput) (SpotHistoryOutput, error)
}

SpotPort is EC2's Spot price history in a region (from the manager's account).

type SpotPrice

type SpotPrice struct {
	AvailabilityZone string     `json:"AvailabilityZone,omitempty"`
	SpotPrice        string     `json:"SpotPrice,omitempty"`
	Timestamp        *time.Time `json:"Timestamp,omitempty"`
}

SpotPrice is one entry of the Spot price history.

type Unpriced

type Unpriced struct {
	Reason string        `json:"reason"`
	Item   *stopped.Item `json:"item,omitempty"`
	Hours  float64       `json:"hours"`
}

Unpriced is what could not be priced, with its hours.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL