Skip to content

Commit

Permalink
Adds support for global circuit budget
Browse files Browse the repository at this point in the history
Solves #6001

Signed-off-by: Sotiris Nanopoulos <sotiris.nanopoulos@reddit.com>
  • Loading branch information
davinci26 committed Dec 12, 2023
1 parent 4d48db7 commit 46629af
Show file tree
Hide file tree
Showing 18 changed files with 652 additions and 10 deletions.
16 changes: 16 additions & 0 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ type ContourConfigurationSpec struct {
// +optional
Policy *PolicyConfig `json:"policy,omitempty"`

// GlobalCircuitBreakerDefaults specifies default circuit breaker budget across all services.
// If defined, this will be used as the default for all services.
// +optional
GlobalCircuitBreakerDefaults *GlobalCircuitBreakerDefaults `json:"circuitBreaker,omitempty"`

// Metrics defines the endpoint Contour uses to serve metrics.
//
// Contour's default is { address: "0.0.0.0", port: 8000 }.
Expand Down Expand Up @@ -107,6 +112,17 @@ const (
EnvoyServerType XDSServerType = "envoy"
)

type GlobalCircuitBreakerDefaults struct {
// +optional
MaxConnections uint32 `json:"maxConnections,omitempty" yaml:"maxConnections,omitempty"`
// +optional
MaxPendingRequests uint32 `json:"maxPendingRequests,omitempty" yaml:"maxPendingRequests,omitempty"`
// +optional
MaxRequests uint32 `json:"maxRequests,omitempty" yaml:"maxRequests,omitempty"`
// +optional
MaxRetries uint32 `json:"maxRetries,omitempty" yaml:"maxRetries,omitempty"`
}

// XDSServerConfig holds the config for the Contour xDS server.
type XDSServerConfig struct {
// Defines the XDSServer to use for `contour serve`.
Expand Down
20 changes: 20 additions & 0 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 cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ func (s *Server) doServe() error {
globalRateLimitService: contourConfiguration.RateLimitService,
maxRequestsPerConnection: contourConfiguration.Envoy.Cluster.MaxRequestsPerConnection,
perConnectionBufferLimitBytes: contourConfiguration.Envoy.Cluster.PerConnectionBufferLimitBytes,
globalCircuitBreakerDefaults: contourConfiguration.GlobalCircuitBreakerDefaults,

Check warning on line 563 in cmd/contour/serve.go

View check run for this annotation

Codecov / codecov/patch

cmd/contour/serve.go#L563

Added line #L563 was not covered by tests
})

// Build the core Kubernetes event handler.
Expand Down Expand Up @@ -1117,6 +1118,7 @@ type dagBuilderConfig struct {
maxRequestsPerConnection *uint32
perConnectionBufferLimitBytes *uint32
globalRateLimitService *contour_api_v1alpha1.RateLimitServiceConfig
globalCircuitBreakerDefaults *contour_api_v1alpha1.GlobalCircuitBreakerDefaults
}

func (s *Server) getDAGBuilder(dbc dagBuilderConfig) *dag.Builder {
Expand Down Expand Up @@ -1209,6 +1211,7 @@ func (s *Server) getDAGBuilder(dbc dagBuilderConfig) *dag.Builder {
GlobalRateLimitService: dbc.globalRateLimitService,
PerConnectionBufferLimitBytes: dbc.perConnectionBufferLimitBytes,
SetSourceMetadataOnRoutes: true,
GlobalCircuitBreakerDefaults: dbc.globalCircuitBreakerDefaults,
},
}

Expand Down
15 changes: 8 additions & 7 deletions cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,13 +584,14 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_api_v1alpha
RootNamespaces: ctx.proxyRootNamespaces(),
FallbackCertificate: fallbackCertificate,
},
EnableExternalNameService: &ctx.Config.EnableExternalNameService,
GlobalExternalAuthorization: globalExtAuth,
RateLimitService: rateLimitService,
Policy: policy,
Metrics: &contourMetrics,
Tracing: tracingConfig,
FeatureFlags: ctx.Config.FeatureFlags,
EnableExternalNameService: &ctx.Config.EnableExternalNameService,
GlobalExternalAuthorization: globalExtAuth,
RateLimitService: rateLimitService,
Policy: policy,
GlobalCircuitBreakerDefaults: ctx.Config.GlobalCircuitBreakerDefaults,
Metrics: &contourMetrics,
Tracing: tracingConfig,
FeatureFlags: ctx.Config.FeatureFlags,
}

xdsServerType := contour_api_v1alpha1.ContourServerType
Expand Down
36 changes: 36 additions & 0 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ spec:
Contour controller. It contains most of all the options that can be
customized, the other remaining options being command line flags.
properties:
circuitBreaker:
description: GlobalCircuitBreakerDefaults specifies default circuit
breaker budget across all services. If defined, this will be used
as the default for all services.
properties:
maxConnections:
format: int32
type: integer
maxPendingRequests:
format: int32
type: integer
maxRequests:
format: int32
type: integer
maxRetries:
format: int32
type: integer
type: object
debug:
description: Debug contains parameters to enable debug logging and
debug interfaces inside Contour.
Expand Down Expand Up @@ -3505,6 +3523,24 @@ spec:
used when provisioning a Contour instance that will influence aspects
of the Contour instance's runtime behavior.
properties:
circuitBreaker:
description: GlobalCircuitBreakerDefaults specifies default circuit
breaker budget across all services. If defined, this will be
used as the default for all services.
properties:
maxConnections:
format: int32
type: integer
maxPendingRequests:
format: int32
type: integer
maxRequests:
format: int32
type: integer
maxRetries:
format: int32
type: integer
type: object
debug:
description: Debug contains parameters to enable debug logging
and debug interfaces inside Contour.
Expand Down
36 changes: 36 additions & 0 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ spec:
Contour controller. It contains most of all the options that can be
customized, the other remaining options being command line flags.
properties:
circuitBreaker:
description: GlobalCircuitBreakerDefaults specifies default circuit
breaker budget across all services. If defined, this will be used
as the default for all services.
properties:
maxConnections:
format: int32
type: integer
maxPendingRequests:
format: int32
type: integer
maxRequests:
format: int32
type: integer
maxRetries:
format: int32
type: integer
type: object
debug:
description: Debug contains parameters to enable debug logging and
debug interfaces inside Contour.
Expand Down Expand Up @@ -3724,6 +3742,24 @@ spec:
used when provisioning a Contour instance that will influence aspects
of the Contour instance's runtime behavior.
properties:
circuitBreaker:
description: GlobalCircuitBreakerDefaults specifies default circuit
breaker budget across all services. If defined, this will be
used as the default for all services.
properties:
maxConnections:
format: int32
type: integer
maxPendingRequests:
format: int32
type: integer
maxRequests:
format: int32
type: integer
maxRetries:
format: int32
type: integer
type: object
debug:
description: Debug contains parameters to enable debug logging
and debug interfaces inside Contour.
Expand Down
36 changes: 36 additions & 0 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ spec:
Contour controller. It contains most of all the options that can be
customized, the other remaining options being command line flags.
properties:
circuitBreaker:
description: GlobalCircuitBreakerDefaults specifies default circuit
breaker budget across all services. If defined, this will be used
as the default for all services.
properties:
maxConnections:
format: int32
type: integer
maxPendingRequests:
format: int32
type: integer
maxRequests:
format: int32
type: integer
maxRetries:
format: int32
type: integer
type: object
debug:
description: Debug contains parameters to enable debug logging and
debug interfaces inside Contour.
Expand Down Expand Up @@ -3516,6 +3534,24 @@ spec:
used when provisioning a Contour instance that will influence aspects
of the Contour instance's runtime behavior.
properties:
circuitBreaker:
description: GlobalCircuitBreakerDefaults specifies default circuit
breaker budget across all services. If defined, this will be
used as the default for all services.
properties:
maxConnections:
format: int32
type: integer
maxPendingRequests:
format: int32
type: integer
maxRequests:
format: int32
type: integer
maxRetries:
format: int32
type: integer
type: object
debug:
description: Debug contains parameters to enable debug logging
and debug interfaces inside Contour.
Expand Down
36 changes: 36 additions & 0 deletions examples/render/contour-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,24 @@ spec:
Contour controller. It contains most of all the options that can be
customized, the other remaining options being command line flags.
properties:
circuitBreaker:
description: GlobalCircuitBreakerDefaults specifies default circuit
breaker budget across all services. If defined, this will be used
as the default for all services.
properties:
maxConnections:
format: int32
type: integer
maxPendingRequests:
format: int32
type: integer
maxRequests:
format: int32
type: integer
maxRetries:
format: int32
type: integer
type: object
debug:
description: Debug contains parameters to enable debug logging and
debug interfaces inside Contour.
Expand Down Expand Up @@ -3727,6 +3745,24 @@ spec:
used when provisioning a Contour instance that will influence aspects
of the Contour instance's runtime behavior.
properties:
circuitBreaker:
description: GlobalCircuitBreakerDefaults specifies default circuit
breaker budget across all services. If defined, this will be
used as the default for all services.
properties:
maxConnections:
format: int32
type: integer
maxPendingRequests:
format: int32
type: integer
maxRequests:
format: int32
type: integer
maxRetries:
format: int32
type: integer
type: object
debug:
description: Debug contains parameters to enable debug logging
and debug interfaces inside Contour.
Expand Down
36 changes: 36 additions & 0 deletions examples/render/contour.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,24 @@ spec:
Contour controller. It contains most of all the options that can be
customized, the other remaining options being command line flags.
properties:
circuitBreaker:
description: GlobalCircuitBreakerDefaults specifies default circuit
breaker budget across all services. If defined, this will be used
as the default for all services.
properties:
maxConnections:
format: int32
type: integer
maxPendingRequests:
format: int32
type: integer
maxRequests:
format: int32
type: integer
maxRetries:
format: int32
type: integer
type: object
debug:
description: Debug contains parameters to enable debug logging and
debug interfaces inside Contour.
Expand Down Expand Up @@ -3724,6 +3742,24 @@ spec:
used when provisioning a Contour instance that will influence aspects
of the Contour instance's runtime behavior.
properties:
circuitBreaker:
description: GlobalCircuitBreakerDefaults specifies default circuit
breaker budget across all services. If defined, this will be
used as the default for all services.
properties:
maxConnections:
format: int32
type: integer
maxPendingRequests:
format: int32
type: integer
maxRequests:
format: int32
type: integer
maxRetries:
format: int32
type: integer
type: object
debug:
description: Debug contains parameters to enable debug logging
and debug interfaces inside Contour.
Expand Down
9 changes: 9 additions & 0 deletions internal/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,15 @@ type Cluster struct {
PerConnectionBufferLimitBytes *uint32
}

// CircuitBreakerPolicy defines the circuit breaker policy for a cluster.
type CircuitBreakerPolicy struct {
// IdleConnectionTimeout is the timeout applied to idle connection.
IdleConnectionTimeout timeout.Setting

// ConnectTimeout defines how long the proxy should wait when establishing connection to upstream service.
ConnectTimeout time.Duration
}

// WeightedService represents the load balancing weight of a
// particular v1.Weighted port.
type WeightedService struct {
Expand Down
4 changes: 4 additions & 0 deletions internal/dag/httpproxy_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ type HTTPProxyProcessor struct {
// configurable and off by default in order to support the feature
// without requiring all existing test cases to change.
SetSourceMetadataOnRoutes bool

// GlobalCircuitBreakerDefaults defines global circuit breaker defaults.
GlobalCircuitBreakerDefaults *contour_api_v1alpha1.GlobalCircuitBreakerDefaults
}

// Run translates HTTPProxies into DAG objects and
Expand Down Expand Up @@ -933,6 +936,7 @@ func (p *HTTPProxyProcessor) computeRoutes(
"Spec.Routes unresolved service reference: %s", err)
continue
}
s = serviceCircuitBreakerPolicy(s, p.GlobalCircuitBreakerDefaults, p.source.Metrics)

// Determine the protocol to use to speak to this Cluster.
protocol, err := getProtocol(service, s)
Expand Down
Loading

0 comments on commit 46629af

Please sign in to comment.