Skip to content

Conversation

@yuval-k
Copy link
Contributor

@yuval-k yuval-k commented Nov 22, 2025

Description

Add circuit breakers to BackendConfigPolicy. claude did most of the work.

Change Type

/kind feature

Changelog

Add support for circuit breakers in BackendConfigPolicy.

Signed-off-by: Yuval Kohavi <[email protected]>
Copilot AI review requested due to automatic review settings November 22, 2025 13:26
@gateway-bot gateway-bot added kind/feature Categorizes issue or PR as related to a new feature. release-note labels Nov 22, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds circuit breaker support to the BackendConfigPolicy CRD, allowing users to configure Envoy circuit breaker thresholds (maxConnections, maxPendingRequests, maxRequests, maxRetries) for backend services. The implementation follows established patterns in the codebase for similar backend configuration options like outlier detection.

Key Changes:

  • Added CircuitBreakers type to the BackendConfigPolicy API with CEL validation requiring at least one threshold field
  • Implemented translation from API types to Envoy CircuitBreakers configuration
  • Added comprehensive unit tests and integration test cases for minimal and full configurations

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
api/v1alpha1/backend_config_policy_types.go Defines CircuitBreakers struct with four optional int32 fields and XValidation rule
api/v1alpha1/zz_generated.deepcopy.go Auto-generated DeepCopy methods for CircuitBreakers type
install/helm/kgateway-crds/templates/gateway.kgateway.dev_backendconfigpolicies.yaml CRD schema with circuit breaker field definitions and validation rules
internal/kgateway/extensions2/plugins/backendconfigpolicy/circuitbreakers.go Translation logic converting API types to Envoy protobuf messages
internal/kgateway/extensions2/plugins/backendconfigpolicy/plugin.go Integration of circuit breakers into the plugin lifecycle with validation
internal/kgateway/extensions2/plugins/backendconfigpolicy/plugin_test.go Unit tests for minimal and full circuit breaker configurations
internal/kgateway/translator/gateway/gateway_translator_test.go Integration test cases for circuit breaker scenarios
internal/kgateway/translator/gateway/testutils/inputs/backendconfigpolicy/circuitbreakers-*.yaml Test input manifests for minimal and full circuit breaker configurations
internal/kgateway/translator/gateway/testutils/outputs/backendconfigpolicy/circuitbreakers-*.yaml Expected Envoy configuration output for circuit breaker test cases
examples/example-backendconfigpolicy-circuit-breakers.yaml Example manifest demonstrating circuit breaker usage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 66 to 80
minimum: 0
type: integer
maxPendingRequests:
description: |-
MaxPendingRequests is the maximum number of pending requests that are
allowed to the upstream cluster. If not specified, defaults to 1024.
format: int32
minimum: 0
type: integer
maxRequests:
description: |-
MaxRequests is the maximum number of parallel requests that are allowed
to the upstream cluster. If not specified, defaults to 1024.
format: int32
minimum: 0
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation rules are inconsistent between the API types and the generated CRD. The API types specify Minimum=1 for MaxConnections, MaxPendingRequests, and MaxRequests (lines 114, 120, 126 in backend_config_policy_types.go), but the CRD has minimum: 0 for these same fields (lines 66, 73, 80 in the CRD file).

This inconsistency means the CRD will accept values of 0 for these fields, which would bypass the intended validation. The CRD should be regenerated to match the API types, or the API types should be updated to use Minimum=0 if that's the intended behavior. Based on Envoy's circuit breaker semantics, a minimum of 1 makes more sense for connections, pending requests, and parallel requests.

Suggested change
minimum: 0
type: integer
maxPendingRequests:
description: |-
MaxPendingRequests is the maximum number of pending requests that are
allowed to the upstream cluster. If not specified, defaults to 1024.
format: int32
minimum: 0
type: integer
maxRequests:
description: |-
MaxRequests is the maximum number of parallel requests that are allowed
to the upstream cluster. If not specified, defaults to 1024.
format: int32
minimum: 0
minimum: 1
type: integer
maxPendingRequests:
description: |-
MaxPendingRequests is the maximum number of pending requests that are
allowed to the upstream cluster. If not specified, defaults to 1024.
format: int32
minimum: 1
type: integer
maxRequests:
description: |-
MaxRequests is the maximum number of parallel requests that are allowed
to the upstream cluster. If not specified, defaults to 1024.
format: int32
minimum: 1

Copilot uses AI. Check for mistakes.

// CircuitBreakers contains the options to configure circuit breaker thresholds for the default priority.
// See [Envoy documentation](https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/circuit_breaker.proto) for more details.
// +kubebuilder:validation:XValidation:rule="has(self.maxConnections) || has(self.maxPendingRequests) || has(self.maxRequests) || has(self.maxRetries)",message="At least one circuit breaker threshold must be specified"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// +kubebuilder:validation:XValidation:rule="has(self.maxConnections) || has(self.maxPendingRequests) || has(self.maxRequests) || has(self.maxRetries)",message="At least one circuit breaker threshold must be specified"
// +kubebuilder:validation:AtLeastOneOf=maxConnections,maxPendingRequests,maxRequests,maxRetries

@puertomontt
Copy link
Contributor

mostly LGTM, once CI passing

Signed-off-by: Yuval Kohavi <[email protected]>
@yuval-k yuval-k added this pull request to the merge queue Nov 24, 2025
Merged via the queue into main with commit 08e80af Nov 24, 2025
30 checks passed
@yuval-k yuval-k deleted the yuval-k/circuit-breakers branch November 24, 2025 04:19
@howardjohn
Copy link
Contributor

IMO we should disable the default circuit breakers by default too

@puertomontt puertomontt linked an issue Dec 1, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to configure envoy circuit breakers

5 participants