Documentation
¶
Overview ¶
Package middleware adapts the shared operation engine to HTTP.
Index ¶
- Constants
- Variables
- func InjectCost(r *http.Request)
- type AdaptiveConfig
- type ControllerState
- type CostResolver
- type DecisionState
- type HandlerOption
- type OutcomeStatistics
- type Priority
- type PriorityStatistics
- type ResolutionStatistics
- type Service
- type ServiceConfig
- type ServiceState
- type Statistics
- type TenantConfig
- type TenantPolicy
- type TenantResolver
- type TenantSharingConfig
- type TenantState
Constants ¶
const ( Critical = operation.Critical Background = operation.Background )
const CostHeader = "X-Gatewise-Cost"
Variables ¶
var ErrInvalidCost = errors.New("gatewise: invalid operation metadata")
var ErrInvalidTenantIdentity = errors.New("gatewise: invalid tenant identity")
var ErrUntrustedCostSource = operation.ErrUntrustedCost
var ErrUntrustedTenantSource = errors.New("gatewise: untrusted tenant source")
Functions ¶
func InjectCost ¶ added in v0.7.0
InjectCost removes caller values and propagates only server-resolved metadata. The receiving ingress must trust this immediate peer and authenticate callers.
Types ¶
type AdaptiveConfig ¶
type AdaptiveConfig = operation.AdaptiveConfig
type ControllerState ¶ added in v0.2.0
type ControllerState = operation.ControllerState
type CostResolver ¶ added in v0.7.0
CostResolver must derive logical write cost and keys from authenticated, validated operation plans. It must be local/fast and must not infer database cost from Content-Length. Use request context to avoid parsing bodies twice.
func TrustedCostHeader ¶ added in v0.7.0
func TrustedCostHeader(cidrs []string) (CostResolver, error)
TrustedCostHeader accepts only the fixed reserved wire header from explicitly trusted immediate peers. Ingress must authenticate and overwrite caller values.
type DecisionState ¶ added in v0.6.0
type DecisionState = operation.DecisionState
type HandlerOption ¶
type HandlerOption func(*handlerOptions)
func WithLatencyTarget ¶
func WithLatencyTarget(target time.Duration) HandlerOption
WithLatencyTarget gives this handler its own budget so naturally slower work is not compared directly to fast handlers sharing the same service capacity.
func WithResource ¶ added in v0.6.0
func WithResource(name string) HandlerOption
WithResource selects a server-controlled resource scope, never a caller header. Scoped ceilings still compare the shared Service in-flight count.
type OutcomeStatistics ¶
type OutcomeStatistics = operation.OutcomeStatistics
type PriorityStatistics ¶
type PriorityStatistics = operation.PriorityStatistics
type ResolutionStatistics ¶ added in v0.4.0
type ResolutionStatistics = operation.ResolutionStatistics
type Service ¶
func NewService ¶
func NewService(c ServiceConfig) (*Service, error)
func (*Service) Middleware ¶
type ServiceConfig ¶
type ServiceConfig struct {
Name string
MaxConcurrent, ReservedCritical int
Logger *slog.Logger
Adaptive *AdaptiveConfig
Tenants *TenantConfig
Priorities *prioritypkg.Config
Decisions *decision.Engine
CostResolver CostResolver
}
type ServiceState ¶
type ServiceState = operation.ServiceState
type Statistics ¶
type Statistics = operation.Statistics
type TenantConfig ¶ added in v0.3.0
type TenantConfig struct {
Sharing *TenantSharingConfig
MaxConcurrent int
Limits map[string]int // Optional overrides; copied and hashed at construction.
MaxTracked int // Default 1024 identified tenants, plus two bounded fallback buckets.
IdleTTL time.Duration // Default 5m; only inactive entries expire.
MissingPolicy, OverflowPolicy TenantPolicy // Default reject; shared uses a bounded bucket.
Resolver TenantResolver
}
type TenantPolicy ¶ added in v0.3.0
type TenantPolicy = operation.TenantPolicy
const ( TenantReject TenantPolicy = "reject" )
type TenantResolver ¶ added in v0.3.0
TenantResolver must use an authenticated identity or explicitly trusted metadata. Empty identity invokes MissingPolicy. Errors reject without exposing their text. Keep resolvers local and fast; Gatewise does not authenticate identities.
func TrustedTenantHeader ¶ added in v0.3.0
func TrustedTenantHeader(header string, cidrs []string) (TenantResolver, error)
TrustedTenantHeader trusts only the immediate peer's address, never Forwarded or X-Forwarded-For. Trusted ingress must authenticate and overwrite the header. Requests without the header invoke MissingPolicy; supplied untrusted headers reject.
type TenantSharingConfig ¶ added in v0.5.0
type TenantSharingConfig = operation.TenantSharingConfig
TenantSharingConfig enables lending beyond configured tenant shares. The existing MaxConcurrent/Limits become target shares only when Sharing is set.
type TenantState ¶ added in v0.3.0
type TenantState = operation.TenantState