Documentation
¶
Overview ¶
Package focusfile reads a FOCUS cost file that a step of the customer's own CI wrote, such as an infrastructure estimator's output, and turns each of its rows into one Costroid row with the basis estimate.
The file is the customer's. Its figure, currency, charge period, resource and service are kept. Its tags are not, and the pull request's join keys come from the CI system, never from the file.
Index ¶
Constants ¶
const ( // MaxBytes bounds the file: 4 MiB holds tens of thousands of resource rows. MaxBytes = 4 << 20 // DefaultSource is the costroid/cost_source of a row when the caller names // none. DefaultSource = "infrastructure" // Basis is the costroid/cost_basis of every row this package writes. Basis = "estimate" // MaxText is the row contract's limit on a text column. MaxText = 512 )
MaxUnavailableBytes bounds the note a reader takes. The note Write makes is under 100 bytes.
const ReasonNoFile = "no_file"
ReasonNoFile is why an optional estimate is not available: the file was not there.
Variables ¶
var ( ErrTooLarge = fmt.Errorf("the file is over %d bytes: write one row per resource, for this pull request alone", MaxBytes) ErrNoHeader = errors.New("the file is empty: write a header line of FOCUS column names, then one row per resource") ErrNotCSV = errors.New("the file is not CSV: write comma-separated values, every row with as many cells as the header") ErrColumnTwice = errors.New("the header names this column twice, and nothing says which one holds the value: name it once") ErrNoCostColumn = errors.New("the header names no cost column: write the estimate in ListCost") ErrAmbiguousCost = errors.New("the header has no ListCost and more than one of these, which mean different things: write the estimate in ListCost") ErrMissingColumn = errors.New("the header lacks this column, which every row needs") ErrNoAmount = errors.New("the row has no amount: write the estimate as a decimal, such as 25.488") ErrNotDecimal = errors.New("not a plain decimal: write digits with at most one point, such as 25.488, with no sign, exponent, grouping or space, and at most 26 digits before the point") ErrNegative = errors.New("negative: the row contract holds amounts of 0 and above, so a saving cannot be one row. Write what the resources will cost, not the change") ErrScale = errors.New("more than 12 digits after the point, which the row contract holds: round it where the estimator computes it") ErrNoCurrency = errors.New("not a currency: write the ISO 4217 code of the row's amount, three upper-case letters such as EUR") ErrNoPeriod = errors.New("the row has no charge period: write the start and the end of the period the amount covers") ErrInstant = errors.New("not a FOCUS date and time: write UTC to the second, such as 2026-12-01T00:00:00Z") ErrPeriodOrder = errors.New("the period ends at or before it starts: ChargePeriodEnd is exclusive and after ChargePeriodStart") ErrNotUsage = errors.New("the row contract holds Usage charges alone: leave purchases, taxes, credits and adjustments out of the file") ErrChargeClass = errors.New("the row contract holds no correction: leave ChargeClass empty and write the corrected amount") ErrTooLong = fmt.Errorf("longer than %d characters, which the row contract holds", MaxText) )
The refusals. Each says what is wrong and what to write instead.
var CostColumns = []string{columnListCost, columnEffectiveCost, columnContractedCost, columnBilledCost}
CostColumns are the columns a figure is read from, in the order they are preferred. ListCost is where the row contract puts an estimate. Without it, the file must hold exactly one of the other three, because each means a different thing and nothing says which is the estimate.
Functions ¶
func CheckSource ¶
CheckSource holds a source name to its rule: 1 to 64 lower-case letters, digits and single hyphens, opening and closing with a letter or a digit.
func ReadFigure ¶
ReadFigure reads an estimate's figure as the file states it: a plain decimal of at most 26 integer digits and 12 fractional digits, never negative. The error is one of the refusals.
Types ¶
type Estimate ¶
type Estimate struct {
Figure decimal.Decimal
Currency string
Start, End time.Time
Description string
BillingAccount, BillingAccountName string
SubAccount, SubAccountName string
Provider, Host, InvoiceIssuer string
ServiceName, ServiceCategory, ServiceSubcategory string
SkuID, SkuMeter, SkuPriceID string
Region, RegionName string
Tags map[string]string
RowID string
}
Estimate is what one estimate row states. Row fills what the row contract requires and the estimate leaves empty, so the file's reader and the ledger write an estimate's row the same way.
type File ¶
type File struct {
Rows []focus.Row
// CostColumn is the column every figure was read from.
CostColumn string
// TaggedRows counts the rows whose Tags the reader dropped.
TaggedRows int
}
File is what Read made of a file.
type Options ¶
type Options struct {
// Source is costroid/cost_source, DefaultSource when empty.
Source string
// Tags are the CI system's join keys: repository, pull request, commit,
// run and visibility. The file never sets them.
Tags map[string]string
// BillingAccount fills BillingAccountId on a row whose file states none.
BillingAccount string
}
Options are what the caller adds to every row.
type Refusal ¶
Refusal is a file Read refused: the line and the column at fault, the value it holds, and why. Line 0 is the file as a whole, and line 1 its header.
type Unavailable ¶
type Unavailable struct {
}
Unavailable is the note ingest-run --optional leaves beside the rows when the estimate it was given is not there, so the report can say so. The agent's job writes it, so a reader takes a reason from the closed list and a source that passes CheckSource, and nothing else.
func NotAvailable ¶
func NotAvailable(source string) Unavailable
NotAvailable is the note for a source whose file was not there.
func ParseUnavailable ¶
func ParseUnavailable(data []byte) (Unavailable, error)
ParseUnavailable reads a note and holds it to the closed list.
func (Unavailable) Sentence ¶
func (u Unavailable) Sentence() string
Sentence is the words for the note's reason.