Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust MeshCircuitBreaker with memo #5651

Merged
merged 4 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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