policy

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: 3 Imported by: 0

Documentation

Overview

Package policy Orchestration policy rules including circuit breaker.

Index

Constants

View Source
const (
	DefaultFailureThreshold = 5
	DefaultOpenDuration     = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CandidateHealth

type CandidateHealth interface {
	UnhealthyCandidateKeys() map[string]struct{}
}

CandidateHealth supplies routing keys (same string form as routing.AttemptCandidate.Key / routing.Primary.String()) that must be treated as temporarily unhealthy and excluded from failover planning alongside explicit negotiation exclusions.

type CircuitBreaker

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

func NewCircuitBreaker

func NewCircuitBreaker(opts CircuitBreakerOptions) *CircuitBreaker

func (*CircuitBreaker) OnRoutingAttemptOutcome

func (cb *CircuitBreaker) OnRoutingAttemptOutcome(candidateKey string, outcome lipapi.AttemptOutcome)

OnRoutingAttemptOutcome feeds consecutive failure tracking for routing candidate keys. Semantics (including swallowed vs surfaced): see docs/routing-health-circuit-breaker.md.

func (*CircuitBreaker) UnhealthyCandidateKeys

func (cb *CircuitBreaker) UnhealthyCandidateKeys() map[string]struct{}

type CircuitBreakerOptions

type CircuitBreakerOptions struct {
	FailureThreshold int
	OpenDuration     time.Duration
	Now              func() time.Time
	// MaxTrackedKeys caps distinct candidate keys retained in memory; zero uses defaultMaxTrackedCircuitKeys.
	// When full, idle keys (no streak, not blocked) are evicted first, then the lowest-pressure key.
	MaxTrackedKeys int
}

type CircuitBreakerPolicy

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

CircuitBreakerPolicy evaluates and records outcomes against a shared CircuitBreakerState using its own threshold/open-duration/clock. One policy view exists per config generation so request-plane health policy can reload while observation state remains process-shared for compatible backend identities (req 7.4, 9.1; design "Health policy reload").

func NewCircuitBreakerPolicy

func NewCircuitBreakerPolicy(state *CircuitBreakerState, opts CircuitBreakerOptions) *CircuitBreakerPolicy

NewCircuitBreakerPolicy builds a generation-scoped policy view over state. A nil state gets a fresh private store (single-generation compatibility).

func (*CircuitBreakerPolicy) OnRoutingAttemptOutcome

func (p *CircuitBreakerPolicy) OnRoutingAttemptOutcome(candidateKey string, outcome lipapi.AttemptOutcome)

OnRoutingAttemptOutcome feeds consecutive failure tracking using this policy's threshold/open-duration against the shared observation state.

func (*CircuitBreakerPolicy) UnhealthyCandidateKeys

func (p *CircuitBreakerPolicy) UnhealthyCandidateKeys() map[string]struct{}

UnhealthyCandidateKeys implements CandidateHealth over the shared state using this policy's failure threshold.

type CircuitBreakerState

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

CircuitBreakerState is a shared failure/blockedUntil observation store for routing candidate keys, decoupled from any one generation's threshold and open-duration policy. Multiple CircuitBreakerPolicy views may observe and record against the same state while each applies its own generation-scoped threshold/open-duration (design "Health policy reload": reloadable request- plane health policy over compatible process-shared observation state).

func NewCircuitBreakerState

func NewCircuitBreakerState(opts CircuitBreakerStateOptions) *CircuitBreakerState

NewCircuitBreakerState constructs a process-shared observation store.

type CircuitBreakerStateOptions

type CircuitBreakerStateOptions struct {
	// MaxTrackedKeys caps distinct candidate keys retained in memory; zero uses
	// defaultMaxTrackedCircuitKeys.
	MaxTrackedKeys int
}

CircuitBreakerStateOptions configures NewCircuitBreakerState.

type RoutingAttemptOutcomeSink

type RoutingAttemptOutcomeSink interface {
	OnRoutingAttemptOutcome(candidateKey string, outcome lipapi.AttemptOutcome)
}

type StaticUnhealthy

type StaticUnhealthy map[string]struct{}

StaticUnhealthy is a fixed key set (tests or simple operators).

func (StaticUnhealthy) UnhealthyCandidateKeys

func (s StaticUnhealthy) UnhealthyCandidateKeys() map[string]struct{}

UnhealthyCandidateKeys returns a copy of the underlying map when non-nil.

Jump to

Keyboard shortcuts

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