Skip to content

Commit

Permalink
API: Support Circuit Breakers in BackendTrafficPolicy (#2284)
Browse files Browse the repository at this point in the history
* API: Support Circuit Breakers in BackendTrafficPolicy

Signed-off-by: Guy Daich <guy.daich@sap.com>

* reivew fixes

Signed-off-by: Guy Daich <guy.daich@sap.com>

* Implement API changes

Signed-off-by: Guy Daich <guy.daich@sap.com>

---------

Signed-off-by: Guy Daich <guy.daich@sap.com>
Co-authored-by: zirain <zirain2009@gmail.com>
  • Loading branch information
guydc and zirain authored Dec 19, 2023
1 parent 769849e commit 64d7152
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ type BackendTrafficPolicySpec struct {
//
// +optional
TCPKeepalive *TCPKeepalive `json:"tcpKeepalive,omitempty"`

// Circuit Breaker settings for the upstream connections and requests.
// If not set, circuit breakers will be enabled with the default thresholds
//
// +optional
CircuitBreaker *CircuitBreaker `json:"circuitBreaker,omitempty"`
}

// BackendTrafficPolicyStatus defines the state of BackendTrafficPolicy
Expand Down
33 changes: 33 additions & 0 deletions api/v1alpha1/circuitbreaker_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package v1alpha1

// CircuitBreaker defines the Circuit Breaker configuration.
type CircuitBreaker struct {
// The maximum number of connections that Envoy will establish to the referenced backend defined within a xRoute rule.
//
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=4294967295
// +kubebuilder:default=1024
// +optional
MaxConnections *int64 `json:"maxConnections,omitempty"`

// The maximum number of pending requests that Envoy will queue to the referenced backend defined within a xRoute rule.
//
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=4294967295
// +kubebuilder:default=1024
// +optional
MaxPendingRequests *int64 `json:"maxPendingRequests,omitempty"`

// The maximum number of parallel requests that Envoy will make to the referenced backend defined within a xRoute rule.
//
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=4294967295
// +kubebuilder:default=1024
// +optional
MaxParallelRequests *int64 `json:"maxParallelRequests,omitempty"`
}
35 changes: 35 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,39 @@ spec:
spec:
description: spec defines the desired state of BackendTrafficPolicy.
properties:
circuitBreaker:
description: Circuit Breaker settings for the upstream connections
and requests. If not set, circuit breakers will be enabled with
the default thresholds
properties:
maxConnections:
default: 1024
description: The maximum number of connections that Envoy will
establish to the referenced backend defined within a xRoute
rule.
format: int64
maximum: 4294967295
minimum: 0
type: integer
maxParallelRequests:
default: 1024
description: The maximum number of parallel requests that Envoy
will make to the referenced backend defined within a xRoute
rule.
format: int64
maximum: 4294967295
minimum: 0
type: integer
maxPendingRequests:
default: 1024
description: The maximum number of pending requests that Envoy
will queue to the referenced backend defined within a xRoute
rule.
format: int64
maximum: 4294967295
minimum: 0
type: integer
type: object
loadBalancer:
description: LoadBalancer policy to apply when routing traffic from
the gateway to the backend endpoints
Expand Down
17 changes: 17 additions & 0 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ _Appears in:_
| `loadBalancer` _[LoadBalancer](#loadbalancer)_ | LoadBalancer policy to apply when routing traffic from the gateway to the backend endpoints |
| `proxyProtocol` _[ProxyProtocol](#proxyprotocol)_ | ProxyProtocol enables the Proxy Protocol when communicating with the backend. |
| `tcpKeepalive` _[TCPKeepalive](#tcpkeepalive)_ | TcpKeepalive settings associated with the upstream client connection. Disabled by default. |
| `circuitBreaker` _[CircuitBreaker](#circuitbreaker)_ | Circuit Breaker settings for the upstream connections and requests. If not set, circuit breakers will be enabled with the default thresholds |



Expand Down Expand Up @@ -126,6 +127,22 @@ _Appears in:_
| `allowCredentials` _boolean_ | AllowCredentials indicates whether a request can include user credentials like cookies, authentication headers, or TLS client certificates. |


#### CircuitBreaker



CircuitBreaker defines the Circuit Breaker configuration.

_Appears in:_
- [BackendTrafficPolicySpec](#backendtrafficpolicyspec)

| Field | Description |
| --- | --- |
| `maxConnections` _integer_ | The maximum number of connections that Envoy will establish to the referenced backend defined within a xRoute rule. |
| `maxPendingRequests` _integer_ | The maximum number of pending requests that Envoy will queue to the referenced backend defined within a xRoute rule. |
| `maxParallelRequests` _integer_ | The maximum number of parallel requests that Envoy will make to the referenced backend defined within a xRoute rule. |


#### ClaimToHeader


Expand Down
52 changes: 50 additions & 2 deletions test/cel-validation/backendtrafficpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ package celvalidation
import (
"context"
"fmt"
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"k8s.io/utils/pointer"
"strings"
"testing"
"time"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
)
Expand Down Expand Up @@ -306,6 +306,54 @@ func TestBackendTrafficPolicyTarget(t *testing.T) {
"spec.loadBalancer: Invalid value: \"object\": Currently SlowStart is only supported for RoundRobin and LeastRequest load balancers.",
},
},
{
desc: " valid config: min, max, nil",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
valMax := pointer.Int64(4294967295)
valMin := pointer.Int64(0)
btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
CircuitBreaker: &egv1a1.CircuitBreaker{
MaxConnections: valMax,
MaxPendingRequests: valMin,
MaxParallelRequests: nil,
},
}
},
wantErrors: []string{},
},
{
desc: " invalid config: min and max valyues",
mutate: func(btp *egv1a1.BackendTrafficPolicy) {
valOverMax := pointer.Int64(4294967296)
valUnderMin := pointer.Int64(-1)
btp.Spec = egv1a1.BackendTrafficPolicySpec{
TargetRef: gwapiv1a2.PolicyTargetReferenceWithSectionName{
PolicyTargetReference: gwapiv1a2.PolicyTargetReference{
Group: gwapiv1a2.Group("gateway.networking.k8s.io"),
Kind: gwapiv1a2.Kind("Gateway"),
Name: gwapiv1a2.ObjectName("eg"),
},
},
CircuitBreaker: &egv1a1.CircuitBreaker{
MaxConnections: valOverMax,
MaxPendingRequests: valUnderMin,
MaxParallelRequests: valOverMax,
},
}
},
wantErrors: []string{
"spec.circuitBreaker.maxParallelRequests: Invalid value: 4294967296: spec.circuitBreaker.maxParallelRequests in body should be less than or equal to 4294967295",
"spec.circuitBreaker.maxPendingRequests: Invalid value: -1: spec.circuitBreaker.maxPendingRequests in body should be greater than or equal to 0",
"spec.circuitBreaker.maxConnections: Invalid value: 4294967296: spec.circuitBreaker.maxConnections in body should be less than or equal to 4294967295",
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 64d7152

Please sign in to comment.