focus

package
v1.0.0-alpha.13 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 15 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

Package focus holds the Costroid FOCUS row, version 0.3, and its writer.

Index

Constants

View Source
const (

	// InstantLayout is the row contract's form of a UTC instant.
	InstantLayout = "2006-01-02T15:04:05Z"

	// RegionGlobal is default routing, which is no distinct region, so a row
	// served there carries a null RegionId.
	RegionGlobal = "global"
)
View Source
const (
	NoteInformational = "informational"
	NoteFallback      = "priced at the catalog fallback tier: the sheet does not name this model, tier and class"
)

Notes more than one writer of rows puts in ChargeDescription.

View Source
const (
	TagSessionID        = "costroid/session_id"
	TagAgent            = "costroid/agent"
	TagAgentVersion     = "costroid/agent_version"
	TagModel            = "costroid/model"
	TagCostSource       = "costroid/cost_source"
	TagCostBasis        = "costroid/cost_basis"
	TagAttributionGrade = "costroid/attribution_grade"
	TagEnforcementGrade = "costroid/enforcement_grade"
	TagRunIdentity      = "costroid/run_identity"
	TagRepo             = "costroid/repo"
	TagPR               = "costroid/pr"
	TagCommitSHA        = "costroid/commit_sha"
	TagWorkflowRunID    = "costroid/workflow_run_id"
	TagAssumedTTL       = "costroid/assumed_ttl"
)

Tag keys of the per-PR convention, version 0.2.

View Source
const MaxScale = 12

MaxScale is the row contract's limit on fractional digits.

Variables

This section is empty.

Functions

func BillingPeriod

func BillingPeriod(at time.Time) (time.Time, time.Time)

BillingPeriod is the UTC month holding an instant.

func ChargePeriod

func ChargePeriod(start, end time.Time) (time.Time, time.Time)

ChargePeriod widens a span to whole UTC seconds. The end is exclusive, so a span inside one second still ends after it starts.

func ResidencyNote

func ResidencyNote(multiplier decimal.Decimal, region string) string

ResidencyNote states a residency multiplier in ChargeDescription.

func RowIdentity

func RowIdentity(requestID string, class TokenClass) string

RowIdentity is the row contract's id: SHA-256 of the provider's request id and the token class. Two writers of one request arrive at one id.

func WriteCSV

func WriteCSV(out io.Writer, lines io.Reader) (int, error)

WriteCSV reads rows as JSON lines and writes them as the row contract's CSV: a header of every column, then one record per row. A null is a blank cell, and Tags is its JSON object, compacted, in the order the line names its keys. It returns the number of rows. A line that is not a row refuses the file, and the caller discards what was written.

Types

type Charge

type Charge struct {
	RowID               string
	Provider            string
	ServiceProviderName string
	Model               string
	Class               TokenClass
	Tokens              int64
	Start, End          time.Time
	Account             string
	Credential          string
	Region              string
	ServiceTier         string
	CatalogVersion      string
	Price               *Price
	Basis               CostBasis
	Tags                map[string]string
	Notes               []string
	OvershootBound      *decimal.Decimal
}

Charge holds the facts of one request's one token class. A nil Price means an informational class, which never carries a cost. Its SkuPriceId takes the shape of the catalog's fallback ids, provider:informational:class.

type CostBasis

type CostBasis string

CostBasis is a value of costroid/cost_basis.

const (
	Measured       CostBasis = "measured"
	ListEquivalent CostBasis = "list_equivalent"
)

The two bases a wrapped run can carry.

type Price

type Price struct {
	SkuPriceID    string
	PricingUnit   string
	ListUnitPrice decimal.Decimal
}

Price is what a row needs from a catalog answer.

type Row

type Row struct {
	BilledCost          decimal.Decimal   `json:"BilledCost"`
	BillingAccountID    string            `json:"BillingAccountId"`
	BillingAccountName  *string           `json:"BillingAccountName"`
	BillingCurrency     string            `json:"BillingCurrency"`
	BillingPeriodEnd    string            `json:"BillingPeriodEnd"`
	BillingPeriodStart  string            `json:"BillingPeriodStart"`
	ChargeCategory      string            `json:"ChargeCategory"`
	ChargeClass         *string           `json:"ChargeClass"`
	ChargeDescription   string            `json:"ChargeDescription"`
	ChargeFrequency     string            `json:"ChargeFrequency"`
	ChargePeriodEnd     string            `json:"ChargePeriodEnd"`
	ChargePeriodStart   string            `json:"ChargePeriodStart"`
	ConsumedQuantity    decimal.Decimal   `json:"ConsumedQuantity"`
	ConsumedUnit        string            `json:"ConsumedUnit"`
	ContractedCost      decimal.Decimal   `json:"ContractedCost"`
	ContractedUnitPrice decimal.Decimal   `json:"ContractedUnitPrice"`
	EffectiveCost       decimal.Decimal   `json:"EffectiveCost"`
	HostProviderName    *string           `json:"HostProviderName"`
	InvoiceIssuerName   string            `json:"InvoiceIssuerName"`
	ListCost            decimal.Decimal   `json:"ListCost"`
	ListUnitPrice       decimal.Decimal   `json:"ListUnitPrice"`
	PricingCategory     string            `json:"PricingCategory"`
	PricingQuantity     decimal.Decimal   `json:"PricingQuantity"`
	PricingUnit         string            `json:"PricingUnit"`
	RegionID            *string           `json:"RegionId"`
	RegionName          *string           `json:"RegionName"`
	ServiceCategory     string            `json:"ServiceCategory"`
	ServiceName         string            `json:"ServiceName"`
	ServiceProviderName string            `json:"ServiceProviderName"`
	ServiceSubcategory  string            `json:"ServiceSubcategory"`
	SkuID               string            `json:"SkuId"`
	SkuMeter            TokenClass        `json:"SkuMeter"`
	SkuPriceID          string            `json:"SkuPriceId"`
	SubAccountID        *string           `json:"SubAccountId"`
	SubAccountName      *string           `json:"SubAccountName"`
	Tags                map[string]string `json:"Tags"`
	CatalogVersion      *string           `json:"x_CostroidCatalogVersion"`
	OvershootBound      *decimal.Decimal  `json:"x_CostroidOvershootBound"`
	RowID               string            `json:"x_CostroidRowId"`
	ServiceTier         *string           `json:"x_CostroidServiceTier"`
}

Row is one model request, or the finest grain an agent reports, for one token class. In JSON lines every column is present and an absent value is null.

func NewRow

func NewRow(c Charge) Row

NewRow builds the row of one charge. Both the CLI and the ingest service write rows through it, so a row reads the same whichever of them priced it.

func (Row) Check

func (r Row) Check() error

Check refuses a row the contract's arithmetic rules out. Rounding to fit is never an option: a figure past the scale limit is an error.

type TokenClass

type TokenClass string

TokenClass is a value of SkuMeter.

const (
	InputUncached       TokenClass = "input_uncached"
	CacheRead           TokenClass = "cache_read"
	CacheWrite5m        TokenClass = "cache_write_5m"
	CacheWrite1h        TokenClass = "cache_write_1h"
	CacheWrite30m       TokenClass = "cache_write_30m"
	CacheWrite12h       TokenClass = "cache_write_12h"
	Output              TokenClass = "output"
	ReasoningOutput     TokenClass = "reasoning_output"
	CachedInputReported TokenClass = "cached_input_reported"
)

The classes a row can carry.

func (TokenClass) Informational

func (c TokenClass) Informational() bool

Informational reports whether a class repeats tokens a billed class counts.

func (TokenClass) Lifetime

func (c TokenClass) Lifetime() string

Lifetime is the value costroid/assumed_ttl takes on a row of this class, and empty for a class that is not a cache write.

type Writer

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

Writer writes rows as JSON lines.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a Writer over w.

func (*Writer) Write

func (w *Writer) Write(row Row) error

Write checks a row and writes it as one line.

Jump to

Keyboard shortcuts

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