Help us shape the future of Go! Take the 2026 Go Developer Survey

quota

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package quota is the storage quota framework (ADR-0292): one decision point, Checker, that every capped storage write asks before it stores, as every PEP asks the one Cedar PDP (internal/auth). Book implements it over the Sources each store kind registers; None admits everything and is every enforcement point's default.

Index

Constants

View Source
const Unknown int64 = -1

Unknown is the Bytes of a write whose size is known only once it ran, a SQL Execute: it needs room left under the limit, and once stored on a capped subject it starts a measure.

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

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

Book is the Checker over the registered Sources. Usage is the last measure plus the bytes settled since and the bytes reserved in flight, so for a write of known size it never counts less than the store holds.

func NewBook

func NewBook(clk clock.Clock, logger *slog.Logger) *Book

NewBook returns an empty Book; nil logger is slog.Default.

func (*Book) Admit

func (b *Book) Admit(ctx context.Context, r Request) (Settle, error)

Admit implements Checker (ADR-0292 Decisions 3 and 4).

func (*Book) Refresh

func (b *Book) Refresh(ctx context.Context)

Refresh reads every subject's limit and usage again, as Run does each refreshInterval, and drops those unused for idleAfter.

func (*Book) Register

func (b *Book) Register(kind v1.Kind, src Source)

Register sets the Source of kind.

func (*Book) Run

func (b *Book) Run(ctx context.Context)

Run refreshes every subject each refreshInterval until ctx ends, and drops those unused for idleAfter.

type Checker

type Checker interface {
	// Admit reserves r.Bytes, or refuses with fault.InsufficientStorage when the write would pass the limit.
	Admit(ctx context.Context, r Request) (Settle, error)
}

Checker is the quota counterpart of auth.Authorizer: Admit before a write, the returned Settle after it.

var None Checker = none{}

None admits every write.

type Request

type Request struct {
	Subject Subject
	// Bytes is the write's size, or Unknown.
	Bytes int64
	// Replaces is the size the write overwrites, asked only before a refusal; nil is 0. It is credited to the
	// decision, never to the count, since a concurrent delete can make it wrong.
	Replaces func(ctx context.Context) (int64, error)
	// Deletes marks a write that only deletes: always admitted, never measured for; once stored, the subject's next
	// refusal waits on a fresh measure, so the room it made counts at once.
	Deletes bool
}

Request is one write a Checker decides.

type Settle

type Settle func(stored bool)

Settle ends an admitted write: stored turns its reservation into settled bytes, false releases it. Call it once.

type Source

type Source struct {
	Limit   func(ctx context.Context, s Subject) (limit int64, ok bool, err error)
	Measure func(ctx context.Context, s Subject) (int64, error)
}

Source reads one kind's quotas: Limit is a subject's cap (ok=false: none), Measure what it holds.

type Subject

type Subject struct {
	Kind      v1.Kind
	Namespace v1.NamespaceName
	Name      v1.ObjectName
	Prefix    string
}

Subject is what a quota caps: a store, or a prefix of a Bucket.

func (Subject) String

func (s Subject) String() string

Jump to

Keyboard shortcuts

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