diff --git a/demo/deploy-backpressure-spec.sh b/demo/deploy-backpressure-spec.sh index d2dae28d75..5c265cc3d4 100755 --- a/demo/deploy-backpressure-spec.sh +++ b/demo/deploy-backpressure-spec.sh @@ -18,10 +18,10 @@ metadata: app: bookstore spec: - maxConnections: 5 - maxRequests: 6 - maxPendingRequests: 7 - maxRetries: 8 - maxConnectionPools: 9 - + maxConnections: 10 + maxRequests: 11 + maxPendingRequests: 12 + maxRetries: 13 + maxConnectionPools: 14 + EOF diff --git a/experimental/pkg/apis/policy/v1alpha1/types.go b/experimental/pkg/apis/policy/v1alpha1/types.go index 15a1ec3219..3bde5237ba 100644 --- a/experimental/pkg/apis/policy/v1alpha1/types.go +++ b/experimental/pkg/apis/policy/v1alpha1/types.go @@ -1,6 +1,8 @@ package v1alpha1 import ( + "encoding/json" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -20,11 +22,24 @@ 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"` - MaxRequests uint32 `json:"maxRequests,omitempty"` - MaxPendingRequests uint32 `json:"maxPendingRequests,omitempty"` - MaxRetries uint32 `json:"maxRetries,omitempty"` - MaxConnectionPools uint32 `json:"maxConnectionPools,omitempty"` + MaxConnections int `json:"maxConnections,omitempty"` + MaxRequests int `json:"maxRequests,omitempty"` + MaxPendingRequests int `json:"maxPendingRequests,omitempty"` + MaxRetries int `json:"maxRetries,omitempty"` + MaxConnectionPools int `json:"maxConnectionPools,omitempty"` +} + +// UnmarshalJSON is ... +func (spec *BackpressureSpec) UnmarshalJSON(data []byte) error { + spec.MaxConnections = -1 // set default value before unmarshaling + spec.MaxRequests = -1 // set default value before unmarshaling + spec.MaxPendingRequests = -1 // set default value before unmarshaling + spec.MaxRetries = -1 // set default value before unmarshaling + spec.MaxConnectionPools = -1 // set default value before unmarshaling + type Alias BackpressureSpec // create alias to prevent endless loop + tmp := (*Alias)(spec) + + return json.Unmarshal(data, tmp) } // BackpressureList is ... diff --git a/pkg/envoy/cds/thresholds.go b/pkg/envoy/cds/thresholds.go index cfd6cb56e9..d9655d78e6 100644 --- a/pkg/envoy/cds/thresholds.go +++ b/pkg/envoy/cds/thresholds.go @@ -10,32 +10,44 @@ func makeThresholds(spec backpressure.BackpressureSpec) []*xds_cluster.CircuitBr threshold := &xds_cluster.CircuitBreakers_Thresholds{} - if spec.MaxConnections != 0 { + if spec.MaxConnections != -1 { threshold.MaxConnections = &wrappers.UInt32Value{ - Value: spec.MaxConnections, + Value: uint32(spec.MaxConnections), } + } else { + log.Trace().Msgf("Backpressure: got default value for maxcon") } - if spec.MaxRequests != 0 { + if spec.MaxRequests != -1 { threshold.MaxRequests = &wrappers.UInt32Value{ - Value: spec.MaxRequests, + Value: uint32(spec.MaxRequests), } + } else { + log.Trace().Msgf("Backpressure: got default value for maxreq") } - if spec.MaxPendingRequests != 0 { + if spec.MaxPendingRequests != -1 { threshold.MaxPendingRequests = &wrappers.UInt32Value{ - Value: spec.MaxPendingRequests, + Value: uint32(spec.MaxPendingRequests), } + } else { + log.Trace().Msgf("Backpressure: got default value for maxpending") } - if spec.MaxRetries != 0 { + if spec.MaxRetries != -1 { threshold.MaxRetries = &wrappers.UInt32Value{ - Value: spec.MaxRetries, + Value: uint32(spec.MaxRetries), } + } else { + log.Trace().Msgf("Backpressure: got default value for maxretries") } - if spec.MaxConnectionPools != 0 { + if spec.MaxConnectionPools != -1 { threshold.MaxConnectionPools = &wrappers.UInt32Value{ - Value: spec.MaxConnectionPools, + Value: uint32(spec.MaxConnectionPools), } + } else { + log.Trace().Msgf("Backpressure: got default value for maxconpools") } + log.Trace().Msgf("Backpressure: CircuitBreaker threshold contains %+v", threshold) + return []*xds_cluster.CircuitBreakers_Thresholds{ threshold, }