diff --git a/charts/osm/crds/experimental/backpressure.yaml b/charts/osm/crds/experimental/backpressure.yaml index 3239a44f07..ffbfccae0f 100644 --- a/charts/osm/crds/experimental/backpressure.yaml +++ b/charts/osm/crds/experimental/backpressure.yaml @@ -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]*' diff --git a/demo/deploy-backpressure-spec.sh b/demo/deploy-backpressure-spec.sh index 9b67d7152a..d2dae28d75 100755 --- a/demo/deploy-backpressure-spec.sh +++ b/demo/deploy-backpressure-spec.sh @@ -18,6 +18,10 @@ metadata: app: bookstore spec: - maxConnections: 10 + maxConnections: 5 + maxRequests: 6 + maxPendingRequests: 7 + maxRetries: 8 + maxConnectionPools: 9 EOF diff --git a/experimental/pkg/apis/policy/v1alpha1/types.go b/experimental/pkg/apis/policy/v1alpha1/types.go index 778a23a8f5..15a1ec3219 100644 --- a/experimental/pkg/apis/policy/v1alpha1/types.go +++ b/experimental/pkg/apis/policy/v1alpha1/types.go @@ -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 ... diff --git a/pkg/envoy/cds/backpressure.go b/pkg/envoy/cds/backpressure.go index 5b830404f8..c3995931cc 100644 --- a/pkg/envoy/cds/backpressure.go +++ b/pkg/envoy/cds/backpressure.go @@ -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), } } diff --git a/pkg/envoy/cds/thresholds.go b/pkg/envoy/cds/thresholds.go index 007d6c194b..2090efcb0a 100644 --- a/pkg/envoy/cds/thresholds.go +++ b/pkg/envoy/cds/thresholds.go @@ -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{