Documentation
¶
Overview ¶
Package decision combines cached overload observations into bounded admission proposals. It never samples a provider or makes a network call during Evaluate.
Index ¶
- Variables
- func ValidName(s string) bool
- func WithResult(ctx context.Context, r Result) context.Context
- type Assessment
- type Budget
- type BudgetAssessment
- type BudgetSnapshot
- type Collector
- type Config
- type Cost
- type Effect
- type Engine
- func (e *Engine) AcquireResources(target Target, cost Cost, now time.Time) (*Lease, []BudgetAssessment, string)
- func (e *Engine) BudgetSnapshot() []BudgetSnapshot
- func (e *Engine) Evaluate(target Target, baseline int, now time.Time) Evaluation
- func (e *Engine) HasActorRules() bool
- func (e *Engine) HasBudgets() bool
- func (e *Engine) Mode() Mode
- func (e *Engine) NeedsCost(resource string) bool
- func (e *Engine) Publish(name string, o Observation) error
- func (e *Engine) Run(ctx context.Context, collectors []Collector) error
- func (e *Engine) Snapshot() []SignalSnapshot
- func (e *Engine) Unavailable(name string) error
- func (e *Engine) ValidateCollectors(collectors []Collector) error
- type Evaluation
- type HTTPProvider
- type KeyBudget
- type Lease
- type Mode
- type Observation
- type Provider
- type ProviderFunc
- type Result
- type Rule
- type Scope
- type SignalSnapshot
- type Stage
- type Target
Constants ¶
This section is empty.
Variables ¶
var ErrFutureObservation = errors.New("decision: future observation")
var ErrInvalidObservation = errors.New("decision: invalid observation")
var ErrOutOfOrder = errors.New("decision: out-of-order observation")
Functions ¶
Types ¶
type Assessment ¶
type BudgetAssessment ¶ added in v0.7.0
type BudgetSnapshot ¶ added in v0.7.0
type Cost ¶ added in v0.7.0
Cost is server-resolved operation metadata. WriteBytes describes planned logical writes, not HTTP body length, WAL bytes or an inferred database cost. Key is never retained in plaintext, returned in diagnostics or used as a label.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) AcquireResources ¶ added in v0.7.0
func (e *Engine) AcquireResources(target Target, cost Cost, now time.Time) (*Lease, []BudgetAssessment, string)
AcquireResources combines all matching byte/key checks atomically under the engine lock. No partial reservation is retained when enforcement rejects. Observe mode tracks actual occupancy in bounded fallback buckets while recording proposals, including registry overflow; it does not create unbounded keys.
func (*Engine) BudgetSnapshot ¶ added in v0.7.0
func (e *Engine) BudgetSnapshot() []BudgetSnapshot
func (*Engine) HasActorRules ¶
func (*Engine) HasBudgets ¶ added in v0.7.0
HasBudgets reports whether HTTP integration requires trusted operation metadata.
func (*Engine) Run ¶
Run owns background sampling until cancellation. At most one sample per signal can be in flight, including across Run restarts. A provider that ignores its context can leave one worker blocked; it cannot create unbounded replacement workers.
func (*Engine) Snapshot ¶
func (e *Engine) Snapshot() []SignalSnapshot
func (*Engine) Unavailable ¶
Unavailable publishes a current unknown state, never the provider's error text.
func (*Engine) ValidateCollectors ¶
type Evaluation ¶
type Evaluation struct {
Mode Mode
BaselineLimit, ProposedLimit, EffectiveLimit int
SignalCeiling int // Smallest matching raw cap; independent of a moving adaptive baseline.
Action, Reason string
Reject bool // Enforced explicit rejection. A cap is checked atomically later.
Assessments []Assessment
}
type HTTPProvider ¶
type HTTPProvider struct {
// contains filtered or unexported fields
}
func NewHTTPProvider ¶
func NewHTTPProvider(address string) (*HTTPProvider, error)
NewHTTPProvider reads a small observation document from an operator-selected endpoint. It disables redirects/environment proxies and validates TLS normally.
func (*HTTPProvider) Close ¶
func (p *HTTPProvider) Close()
func (*HTTPProvider) Sample ¶
func (p *HTTPProvider) Sample(ctx context.Context) (Observation, error)
type Lease ¶ added in v0.7.0
type Lease struct {
// contains filtered or unexported fields
}
Lease tracks only resource reservations; it is not an operation-level service admission API. Middleware rolls it back on later rejection and releases it at handler completion, including cancellation/panic. Release is idempotent.
type Observation ¶
type Observation struct {
Value float64 `json:"value"`
ObservedAt time.Time `json:"observed_at"`
State string `json:"state"`
}
Observation timestamps describe measurement time, not delivery time. Unknown explicitly invalidates an earlier value. Duplicate timestamps never renew age.
type ProviderFunc ¶
type ProviderFunc func(context.Context) (Observation, error)
func (ProviderFunc) Sample ¶
func (f ProviderFunc) Sample(ctx context.Context) (Observation, error)
type Result ¶
type Result struct {
Kind string
Allowed bool
Priority, Resource, Reason, Stage string
Evaluation Evaluation
Stages []Stage
Budgets []BudgetAssessment
}
type SignalSnapshot ¶
type SignalSnapshot struct {
Assessment
Accepted uint64
Dropped [3]uint64
Failures [4]uint64
Collecting bool
}