Documentation
¶
Overview ¶
Package costbudget holds named monthly budgets scoped to a project, tag or app, and the level-triggered state machine that decides which alert thresholds fired and whether the 100 percent action is in force. It is pure arithmetic: usage, persistence and effects live with the callers.
Index ¶
Constants ¶
const ( ScopeProject = "project" ScopeTag = "tag" ScopeApp = "app" )
Scope kinds a budget can cover.
const MaxThresholds = 8
MaxThresholds bounds the alert levels of one budget.
Variables ¶
var DefaultThresholds = spendcap.DefaultThresholds
DefaultThresholds are the alert levels, in percent of the monthly amount.
var ErrNotFound = errors.New("costbudget: not found")
ErrNotFound is returned when a budget id matches nothing.
Functions ¶
Types ¶
type Budget ¶
type Budget struct {
ID string `json:"id"`
Name string `json:"name"`
Scope string `json:"scope"`
ScopeValue string `json:"scope_value"`
Monthly float64 `json:"monthly"`
Thresholds []int `json:"thresholds"`
Action string `json:"action"`
ThrottleRPS int `json:"throttle_rps"`
GuardMode string `json:"guard_mode"`
}
Budget is one named monthly limit. Action is applied while spend is at or above 100 percent and reuses the spend cap actions, so nothing new can be destructive.
type Result ¶
Result is one Step outcome.
type State ¶
type State struct {
BudgetID string `json:"budget_id"`
Period string `json:"period"`
Highest int `json:"highest"`
Pct float64 `json:"pct"`
Spent float64 `json:"spent"`
Enforced string `json:"enforced"`
EnforcedApps []string `json:"enforced_apps"`
UpdatedAt time.Time `json:"updated_at"`
}
State is what the ticker last decided for a budget in a period.