Skip to content

Commit 87448b8

Browse files
Backport of add gateway failures into release/2.0.x (#23569)
backport of commit 8af3ade Co-authored-by: Sanika Chavan <sanika.vikaschavan@hashicorp.com>
1 parent d6f2894 commit 87448b8

10 files changed

Lines changed: 179 additions & 26 deletions

File tree

.changelog/23563.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
xds: add `Consecutive5xx`, `ConsecutiveGatewayFailure`, and `EnforcingConsecutiveGatewayFailure` fields to `PassiveHealthCheck`, allowing operators to configure Envoy outlier detection thresholds for 5xx responses and gateway failures (502/503/504) on upstreams defaults.

agent/consul/config_endpoint_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,11 +1684,14 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) {
16841684
Upstream: wildcard,
16851685
Config: map[string]interface{}{
16861686
"passive_health_check": map[string]interface{}{
1687-
"Interval": int64(10),
1688-
"MaxFailures": int64(2),
1689-
"EnforcingConsecutive5xx": int64(60),
1690-
"MaxEjectionPercent": int64(61),
1691-
"BaseEjectionTime": uint64(62 * time.Second),
1687+
"Interval": int64(10),
1688+
"MaxFailures": int64(2),
1689+
"EnforcingConsecutive5xx": int64(60),
1690+
"EnforcingConsecutiveGatewayFailure": interface{}(nil),
1691+
"Consecutive5xx": interface{}(nil),
1692+
"ConsecutiveGatewayFailure": interface{}(nil),
1693+
"MaxEjectionPercent": int64(61),
1694+
"BaseEjectionTime": uint64(62 * time.Second),
16921695
},
16931696
"mesh_gateway": map[string]interface{}{
16941697
"Mode": "none",
@@ -1700,11 +1703,14 @@ func TestConfigEntry_ResolveServiceConfig_Upstreams(t *testing.T) {
17001703
Upstream: mysql,
17011704
Config: map[string]interface{}{
17021705
"passive_health_check": map[string]interface{}{
1703-
"Interval": int64(10),
1704-
"MaxFailures": int64(2),
1705-
"EnforcingConsecutive5xx": int64(60),
1706-
"MaxEjectionPercent": int64(61),
1707-
"BaseEjectionTime": uint64(62 * time.Second),
1706+
"Interval": int64(10),
1707+
"MaxFailures": int64(2),
1708+
"EnforcingConsecutive5xx": int64(60),
1709+
"EnforcingConsecutiveGatewayFailure": interface{}(nil),
1710+
"Consecutive5xx": interface{}(nil),
1711+
"ConsecutiveGatewayFailure": interface{}(nil),
1712+
"MaxEjectionPercent": int64(61),
1713+
"BaseEjectionTime": uint64(62 * time.Second),
17081714
},
17091715
"mesh_gateway": map[string]interface{}{
17101716
"Mode": "local",

agent/proxycfg/proxycfg.deepcopy.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/structs/config_entry.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,19 @@ type PassiveHealthCheck struct {
12091209
// This setting can be used to disable ejection or to ramp it up slowly. Defaults to 100.
12101210
EnforcingConsecutive5xx *uint32 `json:",omitempty" alias:"enforcing_consecutive_5xx"`
12111211

1212+
// EnforcingConsecutiveGatewayFailure is the % chance that a host will be actually ejected
1213+
// when an outlier status is detected through consecutive gateway failures.
1214+
// This setting can be used to disable ejection or to ramp it up slowly. Defaults to 0.
1215+
EnforcingConsecutiveGatewayFailure *uint32 `json:",omitempty" alias:"enforcing_consecutive_gateway_failure"`
1216+
1217+
// Consecutive5xx is the number of consecutive 5xx responses that trigger outlier detection.
1218+
// If not set, defaults to 5. Setting this overrides MaxFailures for 5xx detection.
1219+
Consecutive5xx *uint32 `json:",omitempty" alias:"consecutive_5xx"`
1220+
1221+
// ConsecutiveGatewayFailure is the number of consecutive gateway failures (502, 503, 504)
1222+
// that trigger outlier detection. If not set, defaults to 0 (disabled).
1223+
ConsecutiveGatewayFailure *uint32 `json:",omitempty" alias:"consecutive_gateway_failure"`
1224+
12121225
// The maximum % of an upstream cluster that can be ejected due to outlier detection.
12131226
// Defaults to 10% but will eject at least one host regardless of the value.
12141227
// TODO: remove me
@@ -1240,6 +1253,15 @@ func (chk PassiveHealthCheck) Validate() error {
12401253
if chk.EnforcingConsecutive5xx != nil && *chk.EnforcingConsecutive5xx > 100 {
12411254
return fmt.Errorf("passive health check enforcing_consecutive_5xx must be a percentage between 0 and 100")
12421255
}
1256+
if chk.EnforcingConsecutiveGatewayFailure != nil && *chk.EnforcingConsecutiveGatewayFailure > 100 {
1257+
return fmt.Errorf("passive health check enforcing_consecutive_gateway_failure must be a percentage between 0 and 100")
1258+
}
1259+
if chk.Consecutive5xx != nil && *chk.Consecutive5xx < 1 {
1260+
return fmt.Errorf("passive health check consecutive_5xx must be greater than 0")
1261+
}
1262+
if chk.ConsecutiveGatewayFailure != nil && *chk.ConsecutiveGatewayFailure < 1 {
1263+
return fmt.Errorf("passive health check consecutive_gateway_failure must be greater than 0")
1264+
}
12431265
if chk.MaxEjectionPercent != nil && *chk.MaxEjectionPercent > 100 {
12441266
return fmt.Errorf("passive health check max_ejection_percent must be a percentage between 0 and 100")
12451267
}

agent/structs/structs.deepcopy.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/xds/config/config.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import (
88
"time"
99

1010
envoy_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
11-
"google.golang.org/protobuf/types/known/durationpb"
12-
1311
"github.com/go-viper/mapstructure/v2"
12+
"google.golang.org/protobuf/types/known/durationpb"
1413
"google.golang.org/protobuf/types/known/wrapperspb"
1514

1615
"github.com/hashicorp/consul/agent/structs"
@@ -215,13 +214,22 @@ func ToOutlierDetection(p *structs.PassiveHealthCheck, override *structs.Passive
215214
od.Consecutive_5Xx = &wrapperspb.UInt32Value{Value: p.MaxFailures}
216215
}
217216

218-
if p.EnforcingConsecutive5xx != nil {
217+
if p.Consecutive5xx != nil && *p.Consecutive5xx != 0 {
218+
od.Consecutive_5Xx = &wrapperspb.UInt32Value{Value: *p.Consecutive5xx}
219+
}
220+
221+
if p.ConsecutiveGatewayFailure != nil && *p.ConsecutiveGatewayFailure != 0 {
222+
od.ConsecutiveGatewayFailure = &wrapperspb.UInt32Value{Value: *p.ConsecutiveGatewayFailure}
223+
}
224+
225+
if p.EnforcingConsecutive5xx != nil && (*p.EnforcingConsecutive5xx != 0 || allowZero) {
219226
// NOTE: EnforcingConsecutive5xx must be greater than 0 for ingress-gateway
220-
if *p.EnforcingConsecutive5xx != 0 {
221-
od.EnforcingConsecutive_5Xx = &wrapperspb.UInt32Value{Value: *p.EnforcingConsecutive5xx}
222-
} else if allowZero {
223-
od.EnforcingConsecutive_5Xx = &wrapperspb.UInt32Value{Value: *p.EnforcingConsecutive5xx}
224-
}
227+
od.EnforcingConsecutive_5Xx = &wrapperspb.UInt32Value{Value: *p.EnforcingConsecutive5xx}
228+
}
229+
230+
if p.EnforcingConsecutiveGatewayFailure != nil && (*p.EnforcingConsecutiveGatewayFailure != 0 || allowZero) {
231+
// NOTE: EnforcingConsecutiveGatewayFailure must be greater than 0 for ingress-gateway
232+
od.EnforcingConsecutiveGatewayFailure = &wrapperspb.UInt32Value{Value: *p.EnforcingConsecutiveGatewayFailure}
225233
}
226234

227235
if p.MaxEjectionPercent != nil {
@@ -244,11 +252,24 @@ func ToOutlierDetection(p *structs.PassiveHealthCheck, override *structs.Passive
244252
od.Consecutive_5Xx = &wrapperspb.UInt32Value{Value: override.MaxFailures}
245253
}
246254

247-
if override.EnforcingConsecutive5xx != nil {
255+
if override.Consecutive5xx != nil && *override.Consecutive5xx != 0 {
256+
od.Consecutive_5Xx = &wrapperspb.UInt32Value{Value: *override.Consecutive5xx}
257+
}
258+
259+
if override.ConsecutiveGatewayFailure != nil && *override.ConsecutiveGatewayFailure != 0 {
260+
od.ConsecutiveGatewayFailure = &wrapperspb.UInt32Value{Value: *override.ConsecutiveGatewayFailure}
261+
}
262+
263+
if override.EnforcingConsecutive5xx != nil && *override.EnforcingConsecutive5xx != 0 {
248264
// NOTE: EnforcingConsecutive5xx must be great than 0 for ingress-gateway
249-
if *override.EnforcingConsecutive5xx != 0 {
250-
od.EnforcingConsecutive_5Xx = &wrapperspb.UInt32Value{Value: *override.EnforcingConsecutive5xx}
251-
}
265+
od.EnforcingConsecutive_5Xx = &wrapperspb.UInt32Value{Value: *override.EnforcingConsecutive5xx}
266+
// Because only ingress gateways have overrides and they cannot have a value of 0, there is no allowZero
267+
// override case to handle
268+
}
269+
270+
if override.EnforcingConsecutiveGatewayFailure != nil && *override.EnforcingConsecutiveGatewayFailure != 0 {
271+
// NOTE: EnforcingConsecutiveGatewayFailure must be greater than 0 for ingress-gateway
272+
od.EnforcingConsecutiveGatewayFailure = &wrapperspb.UInt32Value{Value: *override.EnforcingConsecutiveGatewayFailure}
252273
// Because only ingress gateways have overrides and they cannot have a value of 0, there is no allowZero
253274
// override case to handle
254275
}

api/config_entry.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,19 @@ type PassiveHealthCheck struct {
288288
// This setting can be used to disable ejection or to ramp it up slowly.
289289
EnforcingConsecutive5xx *uint32 `json:",omitempty" alias:"enforcing_consecutive_5xx"`
290290

291+
// EnforcingConsecutiveGatewayFailure is the % chance that a host will be actually ejected
292+
// when an outlier status is detected through consecutive gateway failures(codes-502, 503, 504).
293+
// This setting can be used to disable ejection or to ramp it up slowly. Defaults to 0.
294+
EnforcingConsecutiveGatewayFailure *uint32 `json:",omitempty" alias:"enforcing_consecutive_gateway_failure"`
295+
296+
// Consecutive5xx is the number of consecutive 5xx responses that trigger outlier detection.
297+
// If not set, defaults to 5. Setting this overrides MaxFailures for 5xx detection.
298+
Consecutive5xx *uint32 `json:",omitempty" alias:"consecutive_5xx"`
299+
300+
// ConsecutiveGatewayFailure is the number of consecutive gateway failures (502, 503, 504)
301+
// that trigger outlier detection. If not set, defaults to 0 (disabled).
302+
ConsecutiveGatewayFailure *uint32 `json:",omitempty" alias:"consecutive_gateway_failure"`
303+
291304
// The maximum % of an upstream cluster that can be ejected due to outlier detection.
292305
// Defaults to 10% but will eject at least one host regardless of the value.
293306
MaxEjectionPercent *uint32 `json:",omitempty" alias:"max_ejection_percent"`

proto/private/pbconfigentry/config_entry.gen.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/private/pbconfigentry/config_entry.pb.go

Lines changed: 34 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)