Documentation
¶
Overview ¶
Package focus holds the Costroid FOCUS row, version 0.3, and its writer.
Index ¶
- Constants
- Variables
- func BillingPeriod(at time.Time) (time.Time, time.Time)
- func ChargePeriod(start, end time.Time) (time.Time, time.Time)
- func CheckNamedTag(tag, value string) error
- func CheckRepoVisibility(value string) error
- func EachLine(source io.Reader, read func(line []byte) error) error
- func IsRepoVisibility(value string) bool
- func ReadsLikeKey(value string) bool
- func ResidencyNote(multiplier decimal.Decimal, region string) string
- func RowIdentity(requestID string, class TokenClass) string
- func Shaped(out io.Writer, shape Shape) io.Writer
- func WriteCSV(out io.Writer, lines io.Reader) (int, error)
- type Charge
- type CostBasis
- type LineError
- type Price
- type Profile
- type Row
- type Shape
- type Tags
- 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 ( TagWorkItem = "costroid/work_item" TagArm = "costroid/arm" TagTeam = "costroid/team" )
Tag keys version 0.3 of the convention adds. A caller names each one, and no writer of rows sets one on its own.
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 ( VisibilityPublic = "public" VisibilityPrivate = "private" VisibilityInternal = "internal" )
The values costroid/repo_visibility takes, and no other.
const ColumnMeasuredCost = "x_CostroidMeasuredCost"
ColumnMeasuredCost is the column a strict row carries the default profile's EffectiveCost in, byte for byte.
const MaxDataLength = 128
MaxDataLength caps any string that came from a pull request.
const MaxLineBytes = 1 << 20
MaxLineBytes bounds one line of a rows file.
const MaxScale = 12
MaxScale is the row contract's limit on fractional digits.
const TagRepoVisibility = "costroid/repo_visibility"
TagRepoVisibility is the key version 0.4 of the convention adds: who can read the repository a row's run belongs to, as the CI system states it. No writer of rows asks a host for it, and a row whose CI system did not state it leaves the tag out.
Variables ¶
var DataPattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._:/+_-]*$`)
DataPattern is the character allowlist every string from a pull request passes. It holds no character that can close a code span, open a tag or start a mention.
var ErrKeyShaped = errors.New("takes a label, never a key: this value reads like a key")
ErrKeyShaped is a named tag's value that reads like a provider key.
var ErrLongLine = fmt.Errorf("the line is past %d bytes", MaxLineBytes)
ErrLongLine is the fault of a line past MaxLineBytes.
var NamedTags = map[string]string{ "work_item": TagWorkItem, "arm": TagArm, "team": TagTeam, }
NamedTags are the tags a caller names, by the key --tag takes for each.
var Profiles = []Profile{ProfileDefault, ProfileStrict}
Profiles are the profiles in the order help names them.
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 CheckNamedTag ¶
CheckNamedTag holds the value of one of NamedTags to its rule. The error says what the tag takes and never repeats the value.
func CheckRepoVisibility ¶
CheckRepoVisibility holds a value of costroid/repo_visibility to the rule IsRepoVisibility states. The error says what the tag takes and never repeats the value.
func EachLine ¶
EachLine calls read with each line of a rows file in order. The line is valid only until read returns. Lines count from one, and an empty line is counted and skipped. The first error read returns stops the file and comes back as a *LineError, as does a line past MaxLineBytes. An error of source itself comes back as it is.
func IsRepoVisibility ¶
IsRepoVisibility reports whether value is one of the three values of costroid/repo_visibility. A value outside them never reaches a row.
func ReadsLikeKey ¶
ReadsLikeKey reports whether a value opens as every provider key this product reads does. A value that does never reaches a row.
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 Shaped ¶
Shaped returns a writer that takes rows as Writer writes them, whole JSON lines, and writes each to out with the shape applied. A shape that changes nothing returns out itself, so a default row reaches out as Writer wrote it.
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 LineError ¶
LineError names the line that stopped a read and why: the caller's refusal of it, or ErrLongLine.
type Profile ¶
type Profile string
Profile is how a row states the figure Costroid measured.
const ( // ProfileDefault keeps the figure in EffectiveCost, where Costroid // Platform reads it. ProfileDefault Profile = "default" // ProfileStrict writes EffectiveCost as 0, as BilledCost always is, and // moves the figure to x_CostroidMeasuredCost, so a reader that merges the // rows with the provider's own FOCUS data counts the cost once. ProfileStrict Profile = "strict" )
The profiles a row can be written in.
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 Shape ¶
Shape is what a caller adds to every row a command writes: the tags it names and the profile.
type Tags ¶
type Tags map[string]json.RawMessage
Tags is a row's Tags column, each value as its line states it. A user tag may hold any JSON value; the convention's own tags are strings.
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.