Skip to content

Commit

Permalink
Add circuit breaker support for extension services (#6539)
Browse files Browse the repository at this point in the history
Closes #6537.

Signed-off-by: Clayton Gonsalves <clayton.gonsalves@reddit.com>
  • Loading branch information
clayton-gonsalves authored Jul 25, 2024
1 parent cd05c4f commit 601218d
Show file tree
Hide file tree
Showing 28 changed files with 884 additions and 205 deletions.
8 changes: 6 additions & 2 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const (
EnvoyServerType XDSServerType = "envoy"
)

type GlobalCircuitBreakerDefaults struct {
type CircuitBreakers struct {
// The maximum number of connections that a single Envoy instance allows to the Kubernetes Service; defaults to 1024.
// +optional
MaxConnections uint32 `json:"maxConnections,omitempty" yaml:"max-connections,omitempty"`
Expand All @@ -120,6 +120,10 @@ type GlobalCircuitBreakerDefaults struct {
// The maximum number of parallel retries a single Envoy instance allows to the Kubernetes Service; defaults to 3.
// +optional
MaxRetries uint32 `json:"maxRetries,omitempty" yaml:"max-retries,omitempty"`

// PerHostMaxConnections is the maximum number of connections
// that Envoy will allow to each individual host in a cluster.
PerHostMaxConnections uint32 `json:"perHostMaxConnections,omitempty" yaml:"per-host-max-connections,omitempty"`
}

// XDSServerConfig holds the config for the Contour xDS server.
Expand Down Expand Up @@ -707,7 +711,7 @@ type ClusterParameters struct {
// If defined, this will be used as the default for all services.
//
// +optional
GlobalCircuitBreakerDefaults *GlobalCircuitBreakerDefaults `json:"circuitBreakers,omitempty"`
GlobalCircuitBreakerDefaults *CircuitBreakers `json:"circuitBreakers,omitempty"`

// UpstreamTLS contains the TLS policy parameters for upstream connections
//
Expand Down
5 changes: 5 additions & 0 deletions apis/projectcontour/v1alpha1/extensionservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ type ExtensionServiceSpec struct {
// +optional
// +kubebuilder:validation:Enum=v3
ProtocolVersion ExtensionProtocolVersion `json:"protocolVersion,omitempty"`

// CircuitBreakerPolicy specifies the circuit breaker budget across the extension service.
// If defined this overrides the global circuit breaker budget.
// +optional
CircuitBreakerPolicy *CircuitBreakers `json:"circuitBreakerPolicy,omitempty"`
}

// ExtensionServiceStatus defines the observed state of an
Expand Down
37 changes: 21 additions & 16 deletions apis/projectcontour/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions changelogs/unreleased/6539-clayton-gonsalves-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Add Circuit Breaker support for Extension Services

This change enables the user to configure the Circuit breakers for extension services either via the global Contour config or on an individual Extension Service.

**NOTE**: The `PerHostMaxConnections` is now also configurable via the global settings.

10 changes: 5 additions & 5 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ type dagBuilderConfig struct {
maxRequestsPerConnection *uint32
perConnectionBufferLimitBytes *uint32
globalRateLimitService *contour_v1alpha1.RateLimitServiceConfig
globalCircuitBreakerDefaults *contour_v1alpha1.GlobalCircuitBreakerDefaults
globalCircuitBreakerDefaults *contour_v1alpha1.CircuitBreakers
upstreamTLS *dag.UpstreamTLS
}

Expand Down Expand Up @@ -1145,10 +1145,10 @@ func (s *Server) getDAGBuilder(dbc dagBuilderConfig) *dag.Builder {
&dag.ExtensionServiceProcessor{
// Note that ExtensionService does not support ExternalName, if it does get added,
// need to bring EnableExternalNameService in here too.
FieldLogger: s.log.WithField("context", "ExtensionServiceProcessor"),
ClientCertificate: dbc.clientCert,
ConnectTimeout: dbc.connectTimeout,
UpstreamTLS: dbc.upstreamTLS,
FieldLogger: s.log.WithField("context", "ExtensionServiceProcessor"),
ClientCertificate: dbc.clientCert,
ConnectTimeout: dbc.connectTimeout,
GlobalCircuitBreakerDefaults: dbc.globalCircuitBreakerDefaults,
},
&dag.HTTPProxyProcessor{
EnableExternalNameService: dbc.enableExternalNameService,
Expand Down
2 changes: 1 addition & 1 deletion cmd/contour/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestGetDAGBuilder(t *testing.T) {
})

t.Run("GlobalCircuitBreakerDefaults specified for all processors", func(t *testing.T) {
g := contour_v1alpha1.GlobalCircuitBreakerDefaults{
g := contour_v1alpha1.CircuitBreakers{
MaxConnections: 100,
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/contour/servecontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ func TestConvertServeContext(t *testing.T) {
},
"global circuit breaker defaults": {
getServeContext: func(ctx *serveContext) *serveContext {
ctx.Config.Cluster.GlobalCircuitBreakerDefaults = &contour_v1alpha1.GlobalCircuitBreakerDefaults{
ctx.Config.Cluster.GlobalCircuitBreakerDefaults = &contour_v1alpha1.CircuitBreakers{
MaxConnections: 4,
MaxPendingRequests: 5,
MaxRequests: 6,
Expand All @@ -776,7 +776,7 @@ func TestConvertServeContext(t *testing.T) {
return ctx
},
getContourConfiguration: func(cfg contour_v1alpha1.ContourConfigurationSpec) contour_v1alpha1.ContourConfigurationSpec {
cfg.Envoy.Cluster.GlobalCircuitBreakerDefaults = &contour_v1alpha1.GlobalCircuitBreakerDefaults{
cfg.Envoy.Cluster.GlobalCircuitBreakerDefaults = &contour_v1alpha1.CircuitBreakers{
MaxConnections: 4,
MaxPendingRequests: 5,
MaxRequests: 6,
Expand Down
45 changes: 45 additions & 0 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ spec:
defaults to 3.
format: int32
type: integer
perHostMaxConnections:
description: |-
PerHostMaxConnections is the maximum number of connections
that Envoy will allow to each individual host in a cluster.
format: int32
type: integer
type: object
dnsLookupFamily:
description: |-
Expand Down Expand Up @@ -3896,6 +3902,12 @@ spec:
Service; defaults to 3.
format: int32
type: integer
perHostMaxConnections:
description: |-
PerHostMaxConnections is the maximum number of connections
that Envoy will allow to each individual host in a cluster.
format: int32
type: integer
type: object
dnsLookupFamily:
description: |-
Expand Down Expand Up @@ -5061,6 +5073,39 @@ spec:
description: ExtensionServiceSpec defines the desired state of an ExtensionService
resource.
properties:
circuitBreakerPolicy:
description: |-
CircuitBreakerPolicy specifies the circuit breaker budget across the extension service.
If defined this overrides the global circuit breaker budget.
properties:
maxConnections:
description: The maximum number of connections that a single Envoy
instance allows to the Kubernetes Service; defaults to 1024.
format: int32
type: integer
maxPendingRequests:
description: The maximum number of pending requests that a single
Envoy instance allows to the Kubernetes Service; defaults to
1024.
format: int32
type: integer
maxRequests:
description: The maximum parallel requests a single Envoy instance
allows to the Kubernetes Service; defaults to 1024
format: int32
type: integer
maxRetries:
description: The maximum number of parallel retries a single Envoy
instance allows to the Kubernetes Service; defaults to 3.
format: int32
type: integer
perHostMaxConnections:
description: |-
PerHostMaxConnections is the maximum number of connections
that Envoy will allow to each individual host in a cluster.
format: int32
type: integer
type: object
loadBalancerPolicy:
description: |-
The policy for load balancing GRPC service requests. Note that the
Expand Down
45 changes: 45 additions & 0 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ spec:
defaults to 3.
format: int32
type: integer
perHostMaxConnections:
description: |-
PerHostMaxConnections is the maximum number of connections
that Envoy will allow to each individual host in a cluster.
format: int32
type: integer
type: object
dnsLookupFamily:
description: |-
Expand Down Expand Up @@ -4116,6 +4122,12 @@ spec:
Service; defaults to 3.
format: int32
type: integer
perHostMaxConnections:
description: |-
PerHostMaxConnections is the maximum number of connections
that Envoy will allow to each individual host in a cluster.
format: int32
type: integer
type: object
dnsLookupFamily:
description: |-
Expand Down Expand Up @@ -5281,6 +5293,39 @@ spec:
description: ExtensionServiceSpec defines the desired state of an ExtensionService
resource.
properties:
circuitBreakerPolicy:
description: |-
CircuitBreakerPolicy specifies the circuit breaker budget across the extension service.
If defined this overrides the global circuit breaker budget.
properties:
maxConnections:
description: The maximum number of connections that a single Envoy
instance allows to the Kubernetes Service; defaults to 1024.
format: int32
type: integer
maxPendingRequests:
description: The maximum number of pending requests that a single
Envoy instance allows to the Kubernetes Service; defaults to
1024.
format: int32
type: integer
maxRequests:
description: The maximum parallel requests a single Envoy instance
allows to the Kubernetes Service; defaults to 1024
format: int32
type: integer
maxRetries:
description: The maximum number of parallel retries a single Envoy
instance allows to the Kubernetes Service; defaults to 3.
format: int32
type: integer
perHostMaxConnections:
description: |-
PerHostMaxConnections is the maximum number of connections
that Envoy will allow to each individual host in a cluster.
format: int32
type: integer
type: object
loadBalancerPolicy:
description: |-
The policy for load balancing GRPC service requests. Note that the
Expand Down
45 changes: 45 additions & 0 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ spec:
defaults to 3.
format: int32
type: integer
perHostMaxConnections:
description: |-
PerHostMaxConnections is the maximum number of connections
that Envoy will allow to each individual host in a cluster.
format: int32
type: integer
type: object
dnsLookupFamily:
description: |-
Expand Down Expand Up @@ -3907,6 +3913,12 @@ spec:
Service; defaults to 3.
format: int32
type: integer
perHostMaxConnections:
description: |-
PerHostMaxConnections is the maximum number of connections
that Envoy will allow to each individual host in a cluster.
format: int32
type: integer
type: object
dnsLookupFamily:
description: |-
Expand Down Expand Up @@ -5072,6 +5084,39 @@ spec:
description: ExtensionServiceSpec defines the desired state of an ExtensionService
resource.
properties:
circuitBreakerPolicy:
description: |-
CircuitBreakerPolicy specifies the circuit breaker budget across the extension service.
If defined this overrides the global circuit breaker budget.
properties:
maxConnections:
description: The maximum number of connections that a single Envoy
instance allows to the Kubernetes Service; defaults to 1024.
format: int32
type: integer
maxPendingRequests:
description: The maximum number of pending requests that a single
Envoy instance allows to the Kubernetes Service; defaults to
1024.
format: int32
type: integer
maxRequests:
description: The maximum parallel requests a single Envoy instance
allows to the Kubernetes Service; defaults to 1024
format: int32
type: integer
maxRetries:
description: The maximum number of parallel retries a single Envoy
instance allows to the Kubernetes Service; defaults to 3.
format: int32
type: integer
perHostMaxConnections:
description: |-
PerHostMaxConnections is the maximum number of connections
that Envoy will allow to each individual host in a cluster.
format: int32
type: integer
type: object
loadBalancerPolicy:
description: |-
The policy for load balancing GRPC service requests. Note that the
Expand Down
Loading

0 comments on commit 601218d

Please sign in to comment.