pomerium/config/circuit_breaker_thresholds.go
Caleb Doxsey 5ac7ae9c26
config: add circuit breaker thresholds (#5650)
## Summary
Add a new `circuit_breaker_thresholds` option:

```yaml
circuit_breaker_thresholds:
  max_connections: 1
  max_pending_requests: 2
  max_requests: 3
  max_retries: 4
  max_connection_pools: 5
```

This option can be set at the global level or at the route level. Each
threshold is optional and when not set a default will be used. For
internal clusters we will disable the circuit breaker. For normal routes
we will use the envoy defaults.

## Related issues
-
[ENG-2310](https://linear.app/pomerium/issue/ENG-2310/add-circuit-breaker-settings-per-route)

## Checklist
- [x] reference any related issues
- [x] updated unit tests
- [x] add appropriate label (`enhancement`, `bug`, `breaking`,
`dependencies`, `ci`)
- [x] ready for review
2025-06-16 09:38:39 -06:00

56 lines
2.1 KiB
Go

package config
import (
"github.com/volatiletech/null/v9"
configpb "github.com/pomerium/pomerium/pkg/grpc/config"
)
// CircuitBreakerThresholds define thresholds for circuit breaking.
type CircuitBreakerThresholds struct {
MaxConnections null.Uint32 `mapstructure:"max_connections" yaml:"max_connections,omitempty" json:"max_connections,omitempty"`
MaxPendingRequests null.Uint32 `mapstructure:"max_pending_requests" yaml:"max_pending_requests,omitempty" json:"max_pending_requests,omitempty"`
MaxRequests null.Uint32 `mapstructure:"max_requests" yaml:"max_requests,omitempty" json:"max_requests,omitempty"`
MaxRetries null.Uint32 `mapstructure:"max_retries" yaml:"max_retries,omitempty" json:"max_retries,omitempty"`
MaxConnectionPools null.Uint32 `mapstructure:"max_connection_pools" yaml:"max_connection_pools,omitempty" json:"max_connection_pools,omitempty"`
}
// CircuitBreakerThresholdsFromPB converts the CircuitBreakerThresholds from a protobuf type.
func CircuitBreakerThresholdsFromPB(src *configpb.CircuitBreakerThresholds) *CircuitBreakerThresholds {
if src == nil {
return nil
}
dst := &CircuitBreakerThresholds{}
if src.MaxConnections != nil {
dst.MaxConnections = null.Uint32From(*src.MaxConnections)
}
if src.MaxPendingRequests != nil {
dst.MaxPendingRequests = null.Uint32From(*src.MaxPendingRequests)
}
if src.MaxRequests != nil {
dst.MaxRequests = null.Uint32From(*src.MaxRequests)
}
if src.MaxRetries != nil {
dst.MaxRetries = null.Uint32From(*src.MaxRetries)
}
if src.MaxConnectionPools != nil {
dst.MaxConnectionPools = null.Uint32From(*src.MaxConnectionPools)
}
return dst
}
// CircuitBreakerThresholdsToPB converts the CircuitBreakerThresholds into a protobuf type.
func CircuitBreakerThresholdsToPB(src *CircuitBreakerThresholds) *configpb.CircuitBreakerThresholds {
if src == nil {
return nil
}
return &configpb.CircuitBreakerThresholds{
MaxConnections: src.MaxConnections.Ptr(),
MaxPendingRequests: src.MaxPendingRequests.Ptr(),
MaxRequests: src.MaxRequests.Ptr(),
MaxRetries: src.MaxRetries.Ptr(),
MaxConnectionPools: src.MaxConnectionPools.Ptr(),
}
}