pomerium/config/constants.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

48 lines
1.9 KiB
Go

package config
import (
"errors"
"github.com/mitchellh/mapstructure"
"github.com/spf13/viper"
"google.golang.org/protobuf/encoding/protojson"
"github.com/pomerium/pomerium/config/otelconfig"
)
const (
toKey = "to"
envoyOptsKey = "_envoy_opts"
)
var (
errKeysMustBeStrings = errors.New("cannot convert nested map: all keys must be strings")
errZeroWeight = errors.New("zero load balancing weight not permitted")
errEndpointWeightsSpec = errors.New("either no weights should be provided, or all endpoints must have non-zero weight specified")
errHostnameMustBeSpecified = errors.New("endpoint hostname must be specified")
errSchemeMustBeSpecified = errors.New("url scheme must be provided")
errEmptyUrls = errors.New("url list is empty")
errEitherToOrRedirectOrResponseRequired = errors.New("policy should have either `to` or `redirect` or `response` defined")
)
var protoPartial = protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
// ViperPolicyHooks are used to decode options and policy coming from YAML and env vars
var ViperPolicyHooks = viper.DecodeHook(mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToTimeDurationHookFunc(),
mapstructure.StringToSliceHookFunc(","),
// decode policy including all protobuf-native notations - i.e. duration as `1s`
// https://developers.google.com/protocol-buffers/docs/proto3#json
DecodePolicyHookFunc(),
// parse base-64 encoded POLICY that is bound to environment variable
DecodePolicyBase64Hook(),
decodeNullBoolHookFunc(),
decodeNullUint32HookFunc(),
decodeJWTClaimHeadersHookFunc(),
decodeBearerTokenFormatHookFunc(),
decodeCodecTypeHookFunc(),
decodePPLPolicyHookFunc(),
decodeSANMatcherHookFunc(),
decodeStringToMapHookFunc(),
otelconfig.OtelDurationFunc(),
))