Documentation
¶
Index ¶
- type CircuitBreakerConfig
- type CircuitBreakerMiddleware
- func (cbm *CircuitBreakerMiddleware) ForceClose()
- func (cbm *CircuitBreakerMiddleware) ForceOpen()
- func (cbm *CircuitBreakerMiddleware) GetState() CircuitState
- func (cbm *CircuitBreakerMiddleware) GetStats() *CircuitBreakerStats
- func (cbm *CircuitBreakerMiddleware) Handler() func(http.Handler) http.Handler
- func (cbm *CircuitBreakerMiddleware) Reset()
- type CircuitBreakerStats
- type CircuitState
- type HealthBasedCircuitBreaker
- type HealthBasedCircuitBreakerConfig
- type HealthMiddleware
- type HealthMiddlewareConfig
- type LivenessMiddleware
- type LivenessMiddlewareConfig
- type ReadinessMiddleware
- type ReadinessMiddlewareConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircuitBreakerConfig ¶
type CircuitBreakerConfig struct {
// Failure threshold to open circuit
FailureThreshold int `yaml:"failure_threshold" json:"failure_threshold"`
// Success threshold to close circuit from half-open
SuccessThreshold int `yaml:"success_threshold" json:"success_threshold"`
// Timeout before transitioning from open to half-open
Timeout time.Duration `yaml:"timeout" json:"timeout"`
// Maximum number of concurrent requests in half-open state
MaxConcurrentRequests int `yaml:"max_concurrent_requests" json:"max_concurrent_requests"`
// Health statuses that should trigger circuit opening
TriggerStatuses []health.HealthStatus `yaml:"trigger_statuses" json:"trigger_statuses"`
// Enable health-based circuit breaking
EnableHealthBased bool `yaml:"enable_health_based" json:"enable_health_based"`
// Health check interval for circuit decisions
HealthCheckInterval time.Duration `yaml:"health_check_interval" json:"health_check_interval"`
// Force open circuit if health is unhealthy
ForceOpenOnUnhealthy bool `yaml:"force_open_on_unhealthy" json:"force_open_on_unhealthy"`
// Force close circuit if health is healthy
ForceCloseOnHealthy bool `yaml:"force_close_on_healthy" json:"force_close_on_healthy"`
// Enable request-based circuit breaking
EnableRequestBased bool `yaml:"enable_request_based" json:"enable_request_based"`
// Time window for failure counting
FailureWindow time.Duration `yaml:"failure_window" json:"failure_window"`
// Minimum number of requests before considering circuit opening
MinimumRequests int `yaml:"minimum_requests" json:"minimum_requests"`
// Error rate threshold (0.0 to 1.0)
ErrorRateThreshold float64 `yaml:"error_rate_threshold" json:"error_rate_threshold"`
// Skip circuit breaker for specific paths
SkipPaths []string `yaml:"skip_paths" json:"skip_paths"`
// Skip circuit breaker for specific methods
SkipMethods []string `yaml:"skip_methods" json:"skip_methods"`
// Custom response for circuit open
OpenResponse string `yaml:"open_response" json:"open_response"`
// Include circuit state in headers
IncludeStateHeaders bool `yaml:"include_state_headers" json:"include_state_headers"`
// State header name
StateHeaderName string `yaml:"state_header_name" json:"state_header_name"`
// Enable detailed metrics
EnableMetrics bool `yaml:"enable_metrics" json:"enable_metrics"`
// Enable state change notifications
EnableNotifications bool `yaml:"enable_notifications" json:"enable_notifications"`
}
CircuitBreakerConfig contains configuration for circuit breaker
func DefaultCircuitBreakerConfig ¶
func DefaultCircuitBreakerConfig() *CircuitBreakerConfig
DefaultCircuitBreakerConfig returns default configuration
type CircuitBreakerMiddleware ¶
type CircuitBreakerMiddleware struct {
// contains filtered or unexported fields
}
CircuitBreakerMiddleware provides circuit breaker functionality based on health status
func CreateCircuitBreakerMiddleware ¶
func CreateCircuitBreakerMiddleware(healthService health.HealthService, logger logger.Logger, metrics shared.Metrics) *CircuitBreakerMiddleware
CreateCircuitBreakerMiddleware creates a circuit breaker middleware with default configuration
func NewCircuitBreakerMiddleware ¶
func NewCircuitBreakerMiddleware(healthService health.HealthService, config *CircuitBreakerConfig, logger logger.Logger, metrics shared.Metrics) *CircuitBreakerMiddleware
NewCircuitBreakerMiddleware creates a new circuit breaker middleware
func (*CircuitBreakerMiddleware) ForceClose ¶
func (cbm *CircuitBreakerMiddleware) ForceClose()
ForceClose forces the circuit breaker to closed state
func (*CircuitBreakerMiddleware) ForceOpen ¶
func (cbm *CircuitBreakerMiddleware) ForceOpen()
ForceOpen forces the circuit breaker to open state
func (*CircuitBreakerMiddleware) GetState ¶
func (cbm *CircuitBreakerMiddleware) GetState() CircuitState
GetState returns the current circuit state
func (*CircuitBreakerMiddleware) GetStats ¶
func (cbm *CircuitBreakerMiddleware) GetStats() *CircuitBreakerStats
GetStats returns circuit breaker statistics
func (*CircuitBreakerMiddleware) Handler ¶
func (cbm *CircuitBreakerMiddleware) Handler() func(http.Handler) http.Handler
Handler returns the circuit breaker middleware handler function
func (*CircuitBreakerMiddleware) Reset ¶
func (cbm *CircuitBreakerMiddleware) Reset()
Reset resets the circuit breaker to closed state
type CircuitBreakerStats ¶
type CircuitBreakerStats struct {
State CircuitState `json:"state"`
TotalRequests int64 `json:"total_requests"`
SuccessfulRequests int64 `json:"successful_requests"`
FailedRequests int64 `json:"failed_requests"`
RejectedRequests int64 `json:"rejected_requests"`
CurrentFailures int `json:"current_failures"`
CurrentSuccesses int `json:"current_successes"`
LastFailure time.Time `json:"last_failure"`
LastSuccess time.Time `json:"last_success"`
LastTransition time.Time `json:"last_transition"`
}
CircuitBreakerStats contains circuit breaker statistics
type CircuitState ¶
type CircuitState int
CircuitState represents the state of the circuit breaker
const ( CircuitStateClosed CircuitState = iota CircuitStateOpen CircuitStateHalfOpen )
func (CircuitState) String ¶
func (cs CircuitState) String() string
String returns the string representation of the circuit state
type HealthBasedCircuitBreaker ¶
type HealthBasedCircuitBreaker struct {
// contains filtered or unexported fields
}
HealthBasedCircuitBreaker provides a simpler health-only circuit breaker
func CreateHealthBasedCircuitBreaker ¶
func CreateHealthBasedCircuitBreaker(healthService health.HealthService, logger logger.Logger, metrics shared.Metrics) *HealthBasedCircuitBreaker
CreateHealthBasedCircuitBreaker creates a health-based circuit breaker with default configuration
func NewHealthBasedCircuitBreaker ¶
func NewHealthBasedCircuitBreaker(healthService health.HealthService, config *HealthBasedCircuitBreakerConfig, logger logger.Logger, metrics shared.Metrics) *HealthBasedCircuitBreaker
NewHealthBasedCircuitBreaker creates a new health-based circuit breaker
func (*HealthBasedCircuitBreaker) GetState ¶
func (hcb *HealthBasedCircuitBreaker) GetState() CircuitState
GetState returns the current circuit state
type HealthBasedCircuitBreakerConfig ¶
type HealthBasedCircuitBreakerConfig struct {
// Health statuses that trigger circuit opening
TriggerStatuses []health.HealthStatus `yaml:"trigger_statuses" json:"trigger_statuses"`
// Health check interval
CheckInterval time.Duration `yaml:"check_interval" json:"check_interval"`
// Close circuit when health recovers
AutoClose bool `yaml:"auto_close" json:"auto_close"`
// Timeout before checking health for recovery
RecoveryTimeout time.Duration `yaml:"recovery_timeout" json:"recovery_timeout"`
// Skip paths
SkipPaths []string `yaml:"skip_paths" json:"skip_paths"`
// Response message
OpenResponse string `yaml:"open_response" json:"open_response"`
}
HealthBasedCircuitBreakerConfig contains configuration for health-based circuit breaker
func DefaultHealthBasedCircuitBreakerConfig ¶
func DefaultHealthBasedCircuitBreakerConfig() *HealthBasedCircuitBreakerConfig
DefaultHealthBasedCircuitBreakerConfig returns default configuration
type HealthMiddleware ¶
type HealthMiddleware struct {
// contains filtered or unexported fields
}
HealthMiddleware provides health check middleware functionality
func CreateHealthMiddleware ¶
func CreateHealthMiddleware(healthService health.HealthService, logger logger.Logger, metrics shared.Metrics) *HealthMiddleware
CreateHealthMiddleware creates a health middleware with default configuration
func NewHealthMiddleware ¶
func NewHealthMiddleware(healthService health.HealthService, config *HealthMiddlewareConfig, logger logger.Logger, metrics shared.Metrics) *HealthMiddleware
NewHealthMiddleware creates a new health middleware
type HealthMiddlewareConfig ¶
type HealthMiddlewareConfig struct {
// Skip health checks for specific paths
SkipPaths []string `yaml:"skip_paths" json:"skip_paths"`
// Skip health checks for specific methods
SkipMethods []string `yaml:"skip_methods" json:"skip_methods"`
// Skip health checks for specific headers
SkipHeaders map[string]string `yaml:"skip_headers" json:"skip_headers"`
// Perform health check on every request
CheckOnEveryRequest bool `yaml:"check_on_every_request" json:"check_on_every_request"`
// Minimum interval between health checks
CheckInterval time.Duration `yaml:"check_interval" json:"check_interval"`
// Return 503 if unhealthy
FailOnUnhealthy bool `yaml:"fail_on_unhealthy" json:"fail_on_unhealthy"`
// Return 503 if degraded
FailOnDegraded bool `yaml:"fail_on_degraded" json:"fail_on_degraded"`
// Custom response for unhealthy status
UnhealthyResponse string `yaml:"unhealthy_response" json:"unhealthy_response"`
// Custom response for degraded status
DegradedResponse string `yaml:"degraded_response" json:"degraded_response"`
// Include health status in response headers
IncludeHealthHeaders bool `yaml:"include_health_headers" json:"include_health_headers"`
// Health header name
HealthHeaderName string `yaml:"health_header_name" json:"health_header_name"`
// Include detailed health information
IncludeDetailedHealth bool `yaml:"include_detailed_health" json:"include_detailed_health"`
// Timeout for health checks
HealthCheckTimeout time.Duration `yaml:"health_check_timeout" json:"health_check_timeout"`
// Enable request tracking
TrackRequests bool `yaml:"track_requests" json:"track_requests"`
// Enable performance monitoring
MonitorPerformance bool `yaml:"monitor_performance" json:"monitor_performance"`
}
HealthMiddlewareConfig contains configuration for health middleware
func DefaultHealthMiddlewareConfig ¶
func DefaultHealthMiddlewareConfig() *HealthMiddlewareConfig
DefaultHealthMiddlewareConfig returns default configuration
type LivenessMiddleware ¶
type LivenessMiddleware struct {
// contains filtered or unexported fields
}
LivenessMiddleware provides liveness check middleware
func CreateLivenessMiddleware ¶
func CreateLivenessMiddleware(logger logger.Logger, metrics shared.Metrics) *LivenessMiddleware
CreateLivenessMiddleware creates a liveness middleware with default configuration
func NewLivenessMiddleware ¶
func NewLivenessMiddleware(config *LivenessMiddlewareConfig, logger logger.Logger, metrics shared.Metrics) *LivenessMiddleware
NewLivenessMiddleware creates a new liveness middleware
type LivenessMiddlewareConfig ¶
type LivenessMiddlewareConfig struct {
// Add liveness headers to responses
AddLivenessHeaders bool `yaml:"add_liveness_headers" json:"add_liveness_headers"`
// Liveness header name
LivenessHeaderName string `yaml:"liveness_header_name" json:"liveness_header_name"`
// Include uptime in headers
IncludeUptime bool `yaml:"include_uptime" json:"include_uptime"`
// Uptime header name
UptimeHeaderName string `yaml:"uptime_header_name" json:"uptime_header_name"`
}
LivenessMiddlewareConfig contains configuration for liveness middleware
func DefaultLivenessMiddlewareConfig ¶
func DefaultLivenessMiddlewareConfig() *LivenessMiddlewareConfig
DefaultLivenessMiddlewareConfig returns default configuration
type ReadinessMiddleware ¶
type ReadinessMiddleware struct {
// contains filtered or unexported fields
}
ReadinessMiddleware provides readiness check middleware
func CreateReadinessMiddleware ¶
func CreateReadinessMiddleware(healthService health.HealthService, logger logger.Logger, metrics shared.Metrics) *ReadinessMiddleware
CreateReadinessMiddleware creates a readiness middleware with default configuration
func NewReadinessMiddleware ¶
func NewReadinessMiddleware(healthService health.HealthService, config *ReadinessMiddlewareConfig, logger logger.Logger, metrics shared.Metrics) *ReadinessMiddleware
NewReadinessMiddleware creates a new readiness middleware
type ReadinessMiddlewareConfig ¶
type ReadinessMiddlewareConfig struct {
// Only allow requests when service is ready
StrictReadiness bool `yaml:"strict_readiness" json:"strict_readiness"`
// Grace period after startup before enforcing readiness
GracePeriod time.Duration `yaml:"grace_period" json:"grace_period"`
// Custom response for not ready status
NotReadyResponse string `yaml:"not_ready_response" json:"not_ready_response"`
// Paths to check readiness for
CheckPaths []string `yaml:"check_paths" json:"check_paths"`
// Skip readiness check for specific paths
SkipPaths []string `yaml:"skip_paths" json:"skip_paths"`
}
ReadinessMiddlewareConfig contains configuration for readiness middleware
func DefaultReadinessMiddlewareConfig ¶
func DefaultReadinessMiddlewareConfig() *ReadinessMiddlewareConfig
DefaultReadinessMiddlewareConfig returns default configuration