Skip to content

Commit

Permalink
Spatel/net 1646 add max ejection percent and base ejection time (#2064)
Browse files Browse the repository at this point in the history
* Add MaxEjectionPercent and BaseEjectionTime to servicedefaults

* test with sister branch in consul repo

* missed one

* fix tag names

* fix json tags and duration type

* update test

* generate yaml files and fix imports

---------

Co-authored-by: Semir Patel <semir.patel@hashicorp.com>
  • Loading branch information
malizz and analogue authored May 4, 2023
1 parent bc693e6 commit c86f3d5
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 1 deletion.
2 changes: 2 additions & 0 deletions acceptance/tests/fixtures/bases/crds-oss/servicedefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ spec:
interval: 1s
maxFailures: 10
enforcing_consecutive_5xx: 60
maxEjectionPercent: 100
baseEjectionTime: 20s
- name: "bar"
limits:
maxConnections: 5
Expand Down
28 changes: 28 additions & 0 deletions charts/consul/templates/crd-servicedefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ spec:
upstream proxy instances will be monitored for removal from
the load balancing pool.
properties:
baseEjectionTime:
description: The base time that a host is ejected for.
The real time is equal to the base time multiplied by
the number of times the host has been ejected and is
capped by max_ejection_time (Default 300s). Defaults
to 30000ms or 30s.
type: string
enforcing_consecutive_5xx:
description: EnforcingConsecutive5xx is the % chance that
a host will be actually ejected when an outlier status
Expand All @@ -285,6 +292,13 @@ spec:
description: Interval between health check analysis sweeps.
Each sweep may remove hosts or return hosts to the pool.
type: string
maxEjectionPercent:
description: The maximum % of an upstream cluster that
can be ejected due to outlier detection. Defaults to
10% but will eject at least one host regardless of the
value.
format: int32
type: integer
maxFailures:
description: MaxFailures is the count of consecutive failures
that results in a host being removed from the pool.
Expand Down Expand Up @@ -377,6 +391,13 @@ spec:
how upstream proxy instances will be monitored for removal
from the load balancing pool.
properties:
baseEjectionTime:
description: The base time that a host is ejected for.
The real time is equal to the base time multiplied
by the number of times the host has been ejected and
is capped by max_ejection_time (Default 300s). Defaults
to 30000ms or 30s.
type: string
enforcing_consecutive_5xx:
description: EnforcingConsecutive5xx is the % chance
that a host will be actually ejected when an outlier
Expand All @@ -389,6 +410,13 @@ spec:
sweeps. Each sweep may remove hosts or return hosts
to the pool.
type: string
maxEjectionPercent:
description: The maximum % of an upstream cluster that
can be ejected due to outlier detection. Defaults
to 10% but will eject at least one host regardless
of the value.
format: int32
type: integer
maxFailures:
description: MaxFailures is the count of consecutive
failures that results in a host being removed from
Expand Down
11 changes: 10 additions & 1 deletion control-plane/api/v1alpha1/servicedefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
capi "github.com/hashicorp/consul/api"
"github.com/miekg/dns"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -19,6 +18,7 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"

"github.com/hashicorp/consul-k8s/control-plane/api/common"
capi "github.com/hashicorp/consul/api"
)

const (
Expand Down Expand Up @@ -184,6 +184,13 @@ type PassiveHealthCheck struct {
// when an outlier status is detected through consecutive 5xx.
// This setting can be used to disable ejection or to ramp it up slowly.
EnforcingConsecutive5xx *uint32 `json:"enforcing_consecutive_5xx,omitempty"`
// The maximum % of an upstream cluster that can be ejected due to outlier detection.
// Defaults to 10% but will eject at least one host regardless of the value.
MaxEjectionPercent *uint32 `json:"maxEjectionPercent,omitempty"`
// The base time that a host is ejected for. The real time is equal to the base time
// multiplied by the number of times the host has been ejected and is capped by
// max_ejection_time (Default 300s). Defaults to 30000ms or 30s.
BaseEjectionTime *metav1.Duration `json:"baseEjectionTime,omitempty"`
}

type ServiceDefaultsDestination struct {
Expand Down Expand Up @@ -448,6 +455,8 @@ func (in *PassiveHealthCheck) toConsul() *capi.PassiveHealthCheck {
Interval: in.Interval.Duration,
MaxFailures: in.MaxFailures,
EnforcingConsecutive5xx: in.EnforcingConsecutive5xx,
MaxEjectionPercent: in.MaxEjectionPercent,
BaseEjectionTime: &in.BaseEjectionTime.Duration,
}
}

Expand Down
36 changes: 36 additions & 0 deletions control-plane/api/v1alpha1/servicedefaults_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func TestServiceDefaults_ToConsul(t *testing.T) {
},
MaxFailures: uint32(20),
EnforcingConsecutive5xx: pointer.Uint32(100),
MaxEjectionPercent: pointer.Uint32(10),
BaseEjectionTime: &metav1.Duration{
Duration: 10 * time.Second,
},
},
MeshGateway: MeshGateway{
Mode: "local",
Expand All @@ -115,6 +119,10 @@ func TestServiceDefaults_ToConsul(t *testing.T) {
},
MaxFailures: uint32(10),
EnforcingConsecutive5xx: pointer.Uint32(60),
MaxEjectionPercent: pointer.Uint32(20),
BaseEjectionTime: &metav1.Duration{
Duration: 20 * time.Second,
},
},
MeshGateway: MeshGateway{
Mode: "remote",
Expand All @@ -139,6 +147,10 @@ func TestServiceDefaults_ToConsul(t *testing.T) {
},
MaxFailures: uint32(10),
EnforcingConsecutive5xx: pointer.Uint32(60),
MaxEjectionPercent: pointer.Uint32(30),
BaseEjectionTime: &metav1.Duration{
Duration: 30 * time.Second,
},
},
MeshGateway: MeshGateway{
Mode: "remote",
Expand Down Expand Up @@ -215,6 +227,8 @@ func TestServiceDefaults_ToConsul(t *testing.T) {
Interval: 2 * time.Second,
MaxFailures: uint32(20),
EnforcingConsecutive5xx: pointer.Uint32(100),
MaxEjectionPercent: pointer.Uint32(10),
BaseEjectionTime: pointer.Duration(10 * time.Second),
},
MeshGateway: capi.MeshGatewayConfig{
Mode: "local",
Expand All @@ -238,6 +252,8 @@ func TestServiceDefaults_ToConsul(t *testing.T) {
Interval: 2 * time.Second,
MaxFailures: uint32(10),
EnforcingConsecutive5xx: pointer.Uint32(60),
MaxEjectionPercent: pointer.Uint32(20),
BaseEjectionTime: pointer.Duration(20 * time.Second),
},
MeshGateway: capi.MeshGatewayConfig{
Mode: "remote",
Expand All @@ -260,6 +276,8 @@ func TestServiceDefaults_ToConsul(t *testing.T) {
Interval: 2 * time.Second,
MaxFailures: uint32(10),
EnforcingConsecutive5xx: pointer.Uint32(60),
MaxEjectionPercent: pointer.Uint32(30),
BaseEjectionTime: pointer.Duration(30 * time.Second),
},
MeshGateway: capi.MeshGatewayConfig{
Mode: "remote",
Expand Down Expand Up @@ -386,6 +404,10 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) {
},
MaxFailures: uint32(20),
EnforcingConsecutive5xx: pointer.Uint32(100),
MaxEjectionPercent: pointer.Uint32(10),
BaseEjectionTime: &metav1.Duration{
Duration: 10 * time.Second,
},
},
MeshGateway: MeshGateway{
Mode: "local",
Expand All @@ -410,6 +432,10 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) {
},
MaxFailures: uint32(10),
EnforcingConsecutive5xx: pointer.Uint32(60),
MaxEjectionPercent: pointer.Uint32(20),
BaseEjectionTime: &metav1.Duration{
Duration: 20 * time.Second,
},
},
MeshGateway: MeshGateway{
Mode: "remote",
Expand All @@ -433,6 +459,10 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) {
},
MaxFailures: uint32(10),
EnforcingConsecutive5xx: pointer.Uint32(60),
MaxEjectionPercent: pointer.Uint32(30),
BaseEjectionTime: &metav1.Duration{
Duration: 30 * time.Second,
},
},
MeshGateway: MeshGateway{
Mode: "remote",
Expand Down Expand Up @@ -504,6 +534,8 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) {
Interval: 2 * time.Second,
MaxFailures: uint32(20),
EnforcingConsecutive5xx: pointer.Uint32(100),
MaxEjectionPercent: pointer.Uint32(10),
BaseEjectionTime: pointer.Duration(10 * time.Second),
},
MeshGateway: capi.MeshGatewayConfig{
Mode: "local",
Expand All @@ -526,6 +558,8 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) {
Interval: 2 * time.Second,
MaxFailures: uint32(10),
EnforcingConsecutive5xx: pointer.Uint32(60),
MaxEjectionPercent: pointer.Uint32(20),
BaseEjectionTime: pointer.Duration(20 * time.Second),
},
MeshGateway: capi.MeshGatewayConfig{
Mode: "remote",
Expand All @@ -547,6 +581,8 @@ func TestServiceDefaults_MatchesConsul(t *testing.T) {
Interval: 2 * time.Second,
MaxFailures: uint32(10),
EnforcingConsecutive5xx: pointer.Uint32(60),
MaxEjectionPercent: pointer.Uint32(30),
BaseEjectionTime: pointer.Duration(30 * time.Second),
},
MeshGateway: capi.MeshGatewayConfig{
Mode: "remote",
Expand Down
11 changes: 11 additions & 0 deletions control-plane/api/v1alpha1/zz_generated.deepcopy.go

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 @@ -270,6 +270,13 @@ spec:
upstream proxy instances will be monitored for removal from
the load balancing pool.
properties:
baseEjectionTime:
description: The base time that a host is ejected for.
The real time is equal to the base time multiplied by
the number of times the host has been ejected and is
capped by max_ejection_time (Default 300s). Defaults
to 30000ms or 30s.
type: string
enforcing_consecutive_5xx:
description: EnforcingConsecutive5xx is the % chance that
a host will be actually ejected when an outlier status
Expand All @@ -281,6 +288,13 @@ spec:
description: Interval between health check analysis sweeps.
Each sweep may remove hosts or return hosts to the pool.
type: string
maxEjectionPercent:
description: The maximum % of an upstream cluster that
can be ejected due to outlier detection. Defaults to
10% but will eject at least one host regardless of the
value.
format: int32
type: integer
maxFailures:
description: MaxFailures is the count of consecutive failures
that results in a host being removed from the pool.
Expand Down Expand Up @@ -373,6 +387,13 @@ spec:
how upstream proxy instances will be monitored for removal
from the load balancing pool.
properties:
baseEjectionTime:
description: The base time that a host is ejected for.
The real time is equal to the base time multiplied
by the number of times the host has been ejected and
is capped by max_ejection_time (Default 300s). Defaults
to 30000ms or 30s.
type: string
enforcing_consecutive_5xx:
description: EnforcingConsecutive5xx is the % chance
that a host will be actually ejected when an outlier
Expand All @@ -385,6 +406,13 @@ spec:
sweeps. Each sweep may remove hosts or return hosts
to the pool.
type: string
maxEjectionPercent:
description: The maximum % of an upstream cluster that
can be ejected due to outlier detection. Defaults
to 10% but will eject at least one host regardless
of the value.
format: int32
type: integer
maxFailures:
description: MaxFailures is the count of consecutive
failures that results in a host being removed from
Expand Down

0 comments on commit c86f3d5

Please sign in to comment.