Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Added additional circuit breaking config options to the CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Jul 30, 2020
1 parent e53657d commit 7912a7c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
18 changes: 17 additions & 1 deletion charts/osm/crds/experimental/backpressure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ spec:
spec:
properties:
maxConnections:
description: "Max number of connections"
description: "Maximum number of connections"
type: integer
pattern: '^[1-9]{1}[0-9]*'
maxRequests:
description: "Maximum number of parallel requests"
type: integer
pattern: '^[1-9]{1}[0-9]*'
maxPendingRequests:
description: "Max number of pending requests"
type: integer
pattern: '^[1-9]{1}[0-9]*'
maxRetries:
description: "Max number of parallel retries"
type: integer
pattern: '^[1-9]{1}[0-9]*'
maxConnectionPools:
description: "Maximum number of connection pools per cluster"
type: integer
pattern: '^[1-9]{1}[0-9]*'
6 changes: 5 additions & 1 deletion demo/deploy-backpressure-spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ metadata:
app: bookstore
spec:
maxConnections: 10
maxConnections: 5
maxRequests: 6
maxPendingRequests: 7
maxRetries: 8
maxConnectionPools: 9
EOF
6 changes: 5 additions & 1 deletion experimental/pkg/apis/policy/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ type BackpressureSpec struct {
metav1.ObjectMeta `json:"metadata,omitempty"`

// MaxConnections is the max number of connections a proxy will make to the remote service.
MaxConnections uint32 `json:"maxConnections,omitempty"`
MaxConnections uint32 `json:"maxConnections,omitempty"`
MaxRequests uint32 `json:"maxRequests,omitempty"`
MaxPendingRequests uint32 `json:"maxPendingRequests,omitempty"`
MaxRetries uint32 `json:"maxRetries,omitempty"`
MaxConnectionPools uint32 `json:"maxConnectionPools,omitempty"`
}

// BackpressureList is ...
Expand Down
4 changes: 2 additions & 2 deletions pkg/envoy/cds/backpressure.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func enableBackpressure(meshSpec smi.MeshSpec, remoteCluster *xds_cluster.Cluste
if len(backpressures) > 0 {
log.Trace().Msgf("Backpressure Spec: %+v", backpressures[0].Spec)

remoteCluster.CircuitBreakers = &xds_cluster.CircuitBreakers{
Thresholds: makeThresholds(&backpressures[0].Spec.MaxConnections),
remoteCluster.CircuitBreakers = &envoy_api_v2_cluster.CircuitBreakers{
Thresholds: makeThresholds(backpressures[0].Spec),
}

}
Expand Down
33 changes: 16 additions & 17 deletions pkg/envoy/cds/thresholds.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,37 @@ package cds
import (
xds_cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
"github.com/golang/protobuf/ptypes/wrappers"
backpressure "github.com/openservicemesh/osm/experimental/pkg/apis/policy/v1alpha1"
)

func makeThresholds(maxConnections *uint32) []*xds_cluster.CircuitBreakers_Thresholds {
// Use Envoy defaults if no limits have been defined
if maxConnections == nil {
return nil
}
func makeThresholds(spec backpressure.BackpressureSpec) []*envoy_api_v2_cluster.CircuitBreakers_Thresholds {

threshold := &xds_cluster.CircuitBreakers_Thresholds{}

if maxConnections != nil {
if spec.MaxConnections != 0 {
threshold.MaxConnections = &wrappers.UInt32Value{
Value: *maxConnections,
Value: spec.MaxConnections,
}

// The maximum number of parallel requests that Envoy will make to the upstream cluster. If not specified, the default is 1024.
}
if spec.MaxRequests != 0 {
threshold.MaxRequests = &wrappers.UInt32Value{
Value: *maxConnections,
Value: spec.MaxRequests,
}

}
if spec.MaxPendingRequests != 0 {
threshold.MaxPendingRequests = &wrappers.UInt32Value{
Value: *maxConnections,
Value: spec.MaxPendingRequests,
}

}
if spec.MaxRetries != 0 {
threshold.MaxRetries = &wrappers.UInt32Value{
Value: *maxConnections,
Value: spec.MaxRetries,
}

}
if spec.MaxConnectionPools != 0 {
threshold.MaxConnectionPools = &wrappers.UInt32Value{
Value: *maxConnections,
Value: spec.MaxConnectionPools,
}

}

return []*xds_cluster.CircuitBreakers_Thresholds{
Expand Down

0 comments on commit 7912a7c

Please sign in to comment.