Documentation
¶
Index ¶
- type AlertCallback
- type BudgetAction
- type BudgetAlert
- type BudgetConfig
- type BudgetDecision
- type BudgetExceededError
- type BudgetStore
- func (s *BudgetStore) CheckProjectThreshold(team, project string, monthlyLimit int64, thresholdPct float64, ...)
- func (s *BudgetStore) DeductProject(team, project string, tokens int64, monthlyLimit int64) (int64, error)
- func (s *BudgetStore) DeductTeam(team string, tokens int64, dailyLimit int64) (remaining int, err error)
- func (s *BudgetStore) EnsureProject(team, project string) *ProjectUsage
- func (s *BudgetStore) EnsureTeam(name string, dailyLimit int64) *TeamUsage
- func (s *BudgetStore) ProjectMonthlyUsed(team, project string) int64
- func (s *BudgetStore) RefundTeam(team string, tokens int64)
- func (s *BudgetStore) TeamDailyRemaining(team string) int
- func (s *BudgetStore) TeamMonthlyUsed(team string) int64
- type Governor
- type ProjectBudget
- type ProjectUsage
- type TeamBudget
- type TeamUsage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AlertCallback ¶
type AlertCallback func(BudgetAlert)
type BudgetAction ¶
type BudgetAction int
const ( BudgetActionAllow BudgetAction = 0 BudgetActionDowngrade BudgetAction = 1 BudgetActionReject BudgetAction = 2 )
func (BudgetAction) String ¶
func (a BudgetAction) String() string
type BudgetAlert ¶
type BudgetAlert struct {
Team string
Project string
Metric string
Usage int64
Limit int64
Percentage float64
}
func (BudgetAlert) LimitAmount ¶
func (a BudgetAlert) LimitAmount() int64
func (BudgetAlert) MetricName ¶
func (a BudgetAlert) MetricName() string
func (BudgetAlert) PercentageValue ¶
func (a BudgetAlert) PercentageValue() float64
func (BudgetAlert) ProjectName ¶
func (a BudgetAlert) ProjectName() string
func (BudgetAlert) TeamName ¶
func (a BudgetAlert) TeamName() string
func (BudgetAlert) UsageAmount ¶
func (a BudgetAlert) UsageAmount() int64
type BudgetConfig ¶
type BudgetConfig struct {
WebhookURL string `yaml:"webhook_url"`
Teams map[string]TeamBudget `yaml:"teams"`
}
func (*BudgetConfig) Enabled ¶
func (c *BudgetConfig) Enabled() bool
func (*BudgetConfig) Team ¶
func (c *BudgetConfig) Team(name string) *TeamBudget
type BudgetDecision ¶
type BudgetDecision struct {
Action BudgetAction
Message string
Team string
Project string
DailyPct float64
MonthlyPct float64
Err error
}
func EvaluateBudget ¶
func EvaluateBudget(team, project string, store *BudgetStore, config *BudgetConfig, ignoreBudget bool, logger *slog.Logger) BudgetDecision
type BudgetExceededError ¶
func (*BudgetExceededError) Error ¶
func (e *BudgetExceededError) Error() string
type BudgetStore ¶
type BudgetStore struct {
// contains filtered or unexported fields
}
func NewBudgetStore ¶
func NewBudgetStore() *BudgetStore
func (*BudgetStore) CheckProjectThreshold ¶
func (s *BudgetStore) CheckProjectThreshold(team, project string, monthlyLimit int64, thresholdPct float64, callback AlertCallback, logger *slog.Logger)
func (*BudgetStore) DeductProject ¶
func (*BudgetStore) DeductTeam ¶
func (*BudgetStore) EnsureProject ¶
func (s *BudgetStore) EnsureProject(team, project string) *ProjectUsage
func (*BudgetStore) EnsureTeam ¶
func (s *BudgetStore) EnsureTeam(name string, dailyLimit int64) *TeamUsage
func (*BudgetStore) ProjectMonthlyUsed ¶
func (s *BudgetStore) ProjectMonthlyUsed(team, project string) int64
func (*BudgetStore) RefundTeam ¶
func (s *BudgetStore) RefundTeam(team string, tokens int64)
func (*BudgetStore) TeamDailyRemaining ¶
func (s *BudgetStore) TeamDailyRemaining(team string) int
func (*BudgetStore) TeamMonthlyUsed ¶
func (s *BudgetStore) TeamMonthlyUsed(team string) int64
type Governor ¶
type Governor struct {
// contains filtered or unexported fields
}
func NewGovernor ¶
func NewGovernor(store *BudgetStore, config *BudgetConfig, logger *slog.Logger) *Governor
type ProjectBudget ¶
type ProjectUsage ¶
type ProjectUsage struct {
// contains filtered or unexported fields
}
func (*ProjectUsage) MonthlyUsed ¶
func (c *ProjectUsage) MonthlyUsed() int64
type TeamBudget ¶
type TeamBudget struct {
Daily int64 `yaml:"daily"`
Monthly int64 `yaml:"monthly"`
WebhookURL string `yaml:"webhook_url"`
HardCap bool `yaml:"hard_cap"`
SoftCapPct *float64 `yaml:"soft_cap_pct"`
Projects map[string]ProjectBudget `yaml:"projects"`
}
func (*TeamBudget) SoftCapPercentage ¶
func (t *TeamBudget) SoftCapPercentage() float64
Click to show internal directories.
Click to hide internal directories.