Skip to content

Commit

Permalink
add circuit breaker support for extension services.
Browse files Browse the repository at this point in the history
Signed-off-by: Clayton Gonsalves <clayton.gonsalves@reddit.com>
  • Loading branch information
clayton-gonsalves committed Jul 3, 2024
1 parent 20d2ed9 commit 9e946e2
Show file tree
Hide file tree
Showing 27 changed files with 759 additions and 179 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 CircuitBreaker 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 @@ -704,7 +708,7 @@ type ClusterParameters struct {
// If defined, this will be used as the default for all services.
//
// +optional
GlobalCircuitBreakerDefaults *GlobalCircuitBreakerDefaults `json:"circuitBreakers,omitempty"`
GlobalCircuitBreakerDefaults *CircuitBreaker `json:"circuitBreakers,omitempty"`

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

// CircuitBreaker specifies the circuit breaker budget across the extension service.
// This overrides the global circuite breaker budget if defined.
// If defined this overrides the global circuit breaker budget.
// +optional
CircuitBreakerPolicy *CircuitBreaker `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.

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

This change enabled the user to configure the Circuit breakers for extension services either via the global Contour config or on the Extension Service CRD itself on a per Extension Service itself.
10 changes: 5 additions & 5 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ type dagBuilderConfig struct {
maxRequestsPerConnection *uint32
perConnectionBufferLimitBytes *uint32
globalRateLimitService *contour_v1alpha1.RateLimitServiceConfig
globalCircuitBreakerDefaults *contour_v1alpha1.GlobalCircuitBreakerDefaults
globalCircuitBreakerDefaults *contour_v1alpha1.CircuitBreaker
upstreamTLS *dag.UpstreamTLS
}

Expand Down Expand Up @@ -1141,10 +1141,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.CircuitBreaker{
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.CircuitBreaker{
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.CircuitBreaker{
MaxConnections: 4,
MaxPendingRequests: 5,
MaxRequests: 6,
Expand Down
46 changes: 46 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 @@ -3894,6 +3900,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 @@ -5057,6 +5069,40 @@ spec:
description: ExtensionServiceSpec defines the desired state of an ExtensionService
resource.
properties:
circuitBreakerPolicy:
description: |-
CircuitBreaker specifies the circuit breaker budget across the extension service.
This overrides the global circuite breaker budget if defined.
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
46 changes: 46 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 @@ -4114,6 +4120,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 @@ -5277,6 +5289,40 @@ spec:
description: ExtensionServiceSpec defines the desired state of an ExtensionService
resource.
properties:
circuitBreakerPolicy:
description: |-
CircuitBreaker specifies the circuit breaker budget across the extension service.
This overrides the global circuite breaker budget if defined.
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
46 changes: 46 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 @@ -3905,6 +3911,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 @@ -5068,6 +5080,40 @@ spec:
description: ExtensionServiceSpec defines the desired state of an ExtensionService
resource.
properties:
circuitBreakerPolicy:
description: |-
CircuitBreaker specifies the circuit breaker budget across the extension service.
This overrides the global circuite breaker budget if defined.
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 9e946e2

Please sign in to comment.