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

Commit

Permalink
Circuit breaking thresholds are set to default value when not provide…
Browse files Browse the repository at this point in the history
…d in CRD
  • Loading branch information
Jont828 committed Jul 30, 2020
1 parent 0c1a096 commit 3d213fb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
12 changes: 6 additions & 6 deletions demo/deploy-backpressure-spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 20 additions & 5 deletions experimental/pkg/apis/policy/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1alpha1

import (
"encoding/json"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -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 ...
Expand Down
32 changes: 22 additions & 10 deletions pkg/envoy/cds/thresholds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 3d213fb

Please sign in to comment.