decodeqos

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// RetryAfterSeconds is the Retry-After header value for decode admission 429 responses.
	RetryAfterSeconds = "1"
	// AdmissionRejectedWireMessage is the stable client-safe message for decode admission saturation.
	AdmissionRejectedWireMessage = "decode admission capacity exceeded"
)

Variables

View Source
var (
	// ErrOverweight is returned when weight exceeds the limiter's max inflight byte budget.
	ErrOverweight = errors.New("decodeqos: weight exceeds inflight byte budget")
	// ErrInvalidWeight is returned when weight is negative.
	ErrInvalidWeight = errors.New("decodeqos: negative weight")
)

Functions

func Guard

func Guard(release func(), fn func() error) error

Guard runs fn while holding an admission release and always releases exactly once (including when fn panics). Use around protocol adapter Decode only.

func HTTPStatus

func HTTPStatus(ok bool, err error) (status int, retryAfter bool)

HTTPStatus maps TryAcquire outcome to an HTTP status code. Zero means admission succeeded.

func TryAdmit

func TryAdmit(ctx context.Context, a TryAcquirer, weight int64) (release func(), ok bool, err error)

TryAdmit calls TryAcquire when a is non-nil; nil means unlimited (custom/manual mounts).

Types

type Admission

type Admission interface {
	TryAcquire(ctx context.Context, weight int64) (release func(), ok bool, err error)
	Acquire(ctx context.Context, weight int64) (release func(), err error)
}

Admission bounds concurrent frontend protocol decode/materialization work and weighted in-flight decode bytes while decode is active.

type Decision

type Decision struct {
	Status     int
	RetryAfter bool
	Message    string
}

Decision is the shared admission-reject outcome for frontend handlers. Status 0 means admission succeeded (no reject response).

func Decide

func Decide(ok bool, err error) Decision

Decide maps TryAcquire outcome to status, Retry-After flag, and stable wire message.

type Limiter

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

Limiter bounds concurrent frontend protocol decode/materialization and weighted in-flight decode bytes while decode is active. Body ReadAll and JSON preflight run before admission.

func New

func New(maxConcurrent int, maxInflightBytes int64) *Limiter

New returns nil when maxConcurrent <= 0 or maxInflightBytes <= 0 so callers can keep zero-value behavior unlimited. Standard distribution wiring always passes positive finite values.

func (*Limiter) Acquire

func (l *Limiter) Acquire(ctx context.Context, weight int64) (func(), error)

Acquire waits until decode capacity is available or ctx is canceled.

func (*Limiter) TryAcquire

func (l *Limiter) TryAcquire(ctx context.Context, weight int64) (func(), bool, error)

TryAcquire attempts to reserve decode capacity without waiting behind saturated work.

type TryAcquirer

type TryAcquirer interface {
	TryAcquire(ctx context.Context, weight int64) (release func(), ok bool, err error)
}

TryAcquirer is the minimal admission surface used by frontend handlers.

Jump to

Keyboard shortcuts

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