Documentation
¶
Overview ¶
Package focus holds the Costroid FOCUS row, version 0.3, and its writer.
Index ¶
- Constants
- func BillingPeriod(at time.Time) (time.Time, time.Time)
- func ChargePeriod(start, end time.Time) (time.Time, time.Time)
- func ResidencyNote(multiplier decimal.Decimal, region string) string
- func RowIdentity(requestID string, class TokenClass) string
- func WriteCSV(out io.Writer, lines io.Reader) (int, error)
- type Charge
- type CostBasis
- type Price
- type Row
- type TokenClass
- type Writer
Constants ¶
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" )
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.
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.
const MaxScale = 12
MaxScale is the row contract's limit on fractional digits.
Variables ¶
This section is empty.
Functions ¶
func BillingPeriod ¶
BillingPeriod is the UTC month holding an instant.
func ChargePeriod ¶
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 ¶
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 ¶
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 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.
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.