budget

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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

type BudgetExceededError struct {
	Team    string
	Project string
	Daily   bool
	Monthly bool
	HardCap bool
}

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 (s *BudgetStore) DeductProject(team, project string, tokens int64, monthlyLimit int64) (int64, error)

func (*BudgetStore) DeductTeam

func (s *BudgetStore) DeductTeam(team string, tokens int64, dailyLimit int64) (remaining int, err error)

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

func (*Governor) Deduct

func (g *Governor) Deduct(team, project string, tokens int64) error

func (*Governor) Enabled

func (g *Governor) Enabled() bool

type ProjectBudget

type ProjectBudget struct {
	Daily   int64 `yaml:"daily"`
	Monthly int64 `yaml:"monthly"`
}

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

type TeamUsage

type TeamUsage struct {
	// contains filtered or unexported fields
}

func (*TeamUsage) MonthlyUsed

func (c *TeamUsage) MonthlyUsed() int64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL