Documentation
¶
Index ¶
- Variables
- func DefaultIsFailure(statusCode int) bool
- func StateToGaugeValue(s gobreaker.State) float64
- type ProviderCircuitBreakers
- func (p *ProviderCircuitBreakers) Execute(endpoint, model string, w http.ResponseWriter, ...) error
- func (p *ProviderCircuitBreakers) Get(endpoint, model string) *gobreaker.CircuitBreaker[struct{}]
- func (p *ProviderCircuitBreakers) OpenErrorResponse() []byte
- func (p *ProviderCircuitBreakers) Provider() string
- func (p *ProviderCircuitBreakers) Timeout() time.Duration
Constants ¶
This section is empty.
Variables ¶
var ErrCircuitOpen = errors.New("circuit breaker is open")
ErrCircuitOpen is returned by Execute when the circuit breaker is open and the request was rejected without calling the handler.
Functions ¶
func DefaultIsFailure ¶
DefaultIsFailure returns true for standard HTTP status codes that typically indicate upstream overload.
func StateToGaugeValue ¶
StateToGaugeValue converts gobreaker.State to a gauge value. closed=0, half-open=0.5, open=1
Types ¶
type ProviderCircuitBreakers ¶
type ProviderCircuitBreakers struct {
// contains filtered or unexported fields
}
ProviderCircuitBreakers manages per-endpoint/model circuit breakers for a single provider.
func NewProviderCircuitBreakers ¶
func NewProviderCircuitBreakers(provider string, cfg *config.CircuitBreaker, onChange func(endpoint, model string, from, to gobreaker.State), m *metrics.Metrics) *ProviderCircuitBreakers
NewProviderCircuitBreakers creates circuit breakers for a single provider. Returns nil if cfg is nil (no circuit breaker protection). onChange is called when circuit state changes. metrics is used to record circuit breaker reject counts (can be nil).
func (*ProviderCircuitBreakers) Execute ¶
func (p *ProviderCircuitBreakers) Execute(endpoint, model string, w http.ResponseWriter, handler func(http.ResponseWriter) error) error
Execute runs the given handler function within circuit breaker protection. If the circuit is open, the request is rejected with a 503 response, metrics are recorded, and ErrCircuitOpen is returned. Otherwise, it returns the handler's error (or nil on success). The handler receives a wrapped ResponseWriter that captures the status code. If the receiver is nil (no circuit breaker configured), the handler is called directly.
func (*ProviderCircuitBreakers) Get ¶
func (p *ProviderCircuitBreakers) Get(endpoint, model string) *gobreaker.CircuitBreaker[struct{}]
Get returns the circuit breaker for an endpoint/model tuple, creating it if needed.
func (*ProviderCircuitBreakers) OpenErrorResponse ¶
func (p *ProviderCircuitBreakers) OpenErrorResponse() []byte
OpenErrorResponse returns the error response body when the circuit is open. This is exposed for handlers to use when responding to rejected requests.
func (*ProviderCircuitBreakers) Provider ¶
func (p *ProviderCircuitBreakers) Provider() string
Provider returns the provider name for this circuit breaker.
func (*ProviderCircuitBreakers) Timeout ¶
func (p *ProviderCircuitBreakers) Timeout() time.Duration
Timeout returns the configured timeout duration for this circuit breaker.