Skip to content

Commit

Permalink
fix: adjust MeshCircuitBreaker with memo (#5651)
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com>
  • Loading branch information
lobkovilya authored Jan 12, 2023
1 parent ff27788 commit 9ef5f9e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type ConnectionLimits struct {

type OutlierDetection struct {
// When set to true, outlierDetection configuration won't take any effect
Disabled bool `json:"disabled,omitempty"`
Disabled *bool `json:"disabled,omitempty"`
// The time interval between ejection analysis sweeps. This can result in
// both new ejections and hosts being returned to service.
Interval *k8s.Duration `json:"interval,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,14 @@ func validateOutlierDetection(path validators.PathBuilder, outlierDetection *Out
func validateDetectors(path validators.PathBuilder, detectors *Detectors) validators.ValidationError {
var verr validators.ValidationError
if detectors == nil {
verr.AddViolationAt(path, "'detectors' should be configured")
verr.AddViolationAt(path, validators.MustBeDefined)
return verr
}

if detectors.FailurePercentage == nil && detectors.GatewayFailures == nil &&
detectors.LocalOriginFailures == nil && detectors.TotalFailures == nil &&
detectors.SuccessRate == nil {
verr.AddViolationAt(path, "at least one of the detectors ('totalFailures', 'gatewayFailures',"+
" 'localOriginFailures', 'successRate' or 'failurePercentage') should be configured")
verr.AddViolationAt(path, validators.MustHaveAtLeastOne("totalFailures", "gatewayFailures", "localOriginFailures", "successRate", "failurePercentage"))
return verr
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,39 @@ violations:
message: has to be in [0 - 100] range
- field: spec.to[0].default.outlierDetection.detectors.failurePercentage.threshold
message: has to be in [0 - 100] range`}),
Entry("detectors are not defined", testCase{
inputYaml: `
targetRef:
kind: MeshService
name: web-frontend
to:
- targetRef:
kind: MeshService
name: web-backend
default:
outlierDetection:
maxEjectionPercent: 100`,
expected: `
violations:
- field: spec.to[0].default.outlierDetection.detectors
message: must be defined`}),
Entry("detector is empty", testCase{
inputYaml: `
targetRef:
kind: MeshService
name: web-frontend
to:
- targetRef:
kind: MeshService
name: web-backend
default:
outlierDetection:
maxEjectionPercent: 100
detectors: {}`,
expected: `
violations:
- field: spec.to[0].default.outlierDetection.detectors
message: 'must have at least one defined: totalFailures, gatewayFailures, localOriginFailures, successRate, failurePercentage'`}),
)
})
})

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 @@ -46,7 +46,7 @@ var _ = Describe("MeshCircuitBreaker", func() {

genOutlierDetection := func(disabled bool) *api.OutlierDetection {
return &api.OutlierDetection{
Disabled: disabled,
Disabled: &disabled,
Interval: test.ParseDuration("10s"),
BaseEjectionTime: test.ParseDuration("8s"),
MaxEjectionPercent: test.PointerOf(uint32(88)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"

api "github.com/kumahq/kuma/pkg/plugins/policies/meshcircuitbreaker/api/v1alpha1"
"github.com/kumahq/kuma/pkg/util/pointer"
util_proto "github.com/kumahq/kuma/pkg/util/proto"
)

Expand Down Expand Up @@ -58,7 +59,7 @@ func configureCircuitBreakers(cluster *envoy_cluster.Cluster, conf *api.Connecti
}

func configureOutlierDetection(cluster *envoy_cluster.Cluster, conf *api.OutlierDetection) {
if conf == nil || conf.Disabled {
if conf == nil || pointer.Deref(conf.Disabled) {
return
}

Expand Down

0 comments on commit 9ef5f9e

Please sign in to comment.