quota

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const BytesPerGB int64 = 1_000_000_000
View Source
const SchemaName = "quota"

Variables

This section is empty.

Functions

func BytesToGBRoundUp

func BytesToGBRoundUp(value int64) int64

func IsExceeded

func IsExceeded(err error) bool

func KnownDimension

func KnownDimension(d Dimension) bool

func RunMigrations

func RunMigrations(ctx context.Context, pool *pgxpool.Pool, logger Logger) error

Types

type DB

type DB interface {
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}

type Decision

type Decision struct {
	Allowed    bool      `json:"allowed"`
	TeamID     string    `json:"team_id"`
	Dimension  Dimension `json:"dimension"`
	LimitValue int64     `json:"limit_value"`
	Current    int64     `json:"current"`
	Requested  int64     `json:"requested"`
}

func Check

func Check(teamID string, dimension Dimension, current, requested int64, limit *Limit) Decision

func (Decision) Err

func (d Decision) Err() error

type Dimension

type Dimension string
const (
	DimensionActiveSandboxes Dimension = "active_sandboxes"
	DimensionCPU             Dimension = "cpu_millicpu"
	DimensionMemory          Dimension = "memory_mib"
	DimensionVolumeStorageGB Dimension = "volume_storage_gb"
	DimensionSnapshotGB      Dimension = "snapshot_storage_gb"
	DimensionEgress          Dimension = "egress"
	DimensionIngress         Dimension = "ingress"
)

type ExceededError

type ExceededError struct {
	Decision Decision
}

func (*ExceededError) Error

func (e *ExceededError) Error() string

type Limit

type Limit struct {
	TeamID     string    `json:"team_id"`
	Dimension  Dimension `json:"dimension"`
	LimitValue int64     `json:"limit_value"`
}

type Logger

type Logger interface {
	Printf(format string, args ...any)
	Fatalf(format string, args ...any)
}

type Repository

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

func NewRepository

func NewRepository(pool *pgxpool.Pool) *Repository

func NewRepositoryWithDB

func NewRepositoryWithDB(db DB) *Repository

func (*Repository) AdditionalStorageUsageGB

func (r *Repository) AdditionalStorageUsageGB(ctx context.Context, teamID string, dimension Dimension, subjectType string, additionalBytes int64) (int64, error)

func (*Repository) CheckAdditionalStorageUsageGB

func (r *Repository) CheckAdditionalStorageUsageGB(ctx context.Context, teamID string, dimension Dimension, subjectType string, additionalBytes int64) (Decision, error)

func (*Repository) CheckProjectedStorageUsageGB

func (r *Repository) CheckProjectedStorageUsageGB(ctx context.Context, teamID string, dimension Dimension, subjectType, subjectID string, sizeBytes int64) (Decision, error)

func (*Repository) CurrentUsage

func (r *Repository) CurrentUsage(ctx context.Context, teamID string, dimension Dimension) (int64, error)

func (*Repository) DeleteLimit

func (r *Repository) DeleteLimit(ctx context.Context, teamID string, dimension Dimension) error

func (*Repository) GetLimit

func (r *Repository) GetLimit(ctx context.Context, teamID string, dimension Dimension) (*Limit, error)

func (*Repository) ProjectedStorageUsageGB

func (r *Repository) ProjectedStorageUsageGB(ctx context.Context, teamID string, dimension Dimension, subjectType, subjectID string, sizeBytes int64) (int64, error)

func (*Repository) PutLimit

func (r *Repository) PutLimit(ctx context.Context, limit *Limit) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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