Skip to content

Commit cbeef17

Browse files
authored
feat(lb): add support for configuring fast health check (#2034)
* feat(lb): add support for configuring fast health check * update cassettes
1 parent 9bed856 commit cbeef17

20 files changed

+5166
-5142
lines changed

docs/resources/lb_backend.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,24 @@ e.g. 'failover-website.s3-website.fr-par.scw.cloud' if your bucket website URL i
7272
Backends use Health Check to test if a backend server is ready to receive requests.
7373
You may use one of the following health check types: `TCP`, `HTTP` or `HTTPS`. (Default: `TCP`)
7474

75-
- `health_check_timeout` - (Default: `30s`) Timeout before we consider a HC request failed.
76-
- `health_check_delay` - (Default: `60s`) Interval between two HC requests.
77-
- `health_check_port` - (Default: `forward_port`) Port the HC requests will be send to.
78-
- `health_check_max_retries` - (Default: `2`) Number of allowed failed HC requests before the backend server is marked down.
79-
- `health_check_tcp` - (Optional) This block enable TCP health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
80-
- `health_check_http` - (Optional) This block enable HTTP health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
81-
- `uri` - (Required) The HTTP endpoint URL to call for HC requests.
82-
- `method` - (Default: `GET`) The HTTP method to use for HC requests.
83-
- `code` - (Default: `200`) The expected HTTP status code.
84-
- `host_header` - (Optional) The HTTP host header to use for HC requests.
85-
- `health_check_https` - (Optional) This block enable HTTPS health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
86-
- `uri` - (Required) The HTTPS endpoint URL to call for HC requests.
87-
- `method` - (Default: `GET`) The HTTP method to use for HC requests.
88-
- `code` - (Default: `200`) The expected HTTP status code.
89-
- `host_header` - (Optional) The HTTP host header to use for HC requests.
90-
- `sni` - (Optional) The SNI to use for HC requests over SSL.
91-
- `on_marked_down_action` - (Default: `none`) Modify what occurs when a backend server is marked down. Possible values are: `none` and `shutdown_sessions`.
92-
75+
- `health_check_timeout` - (Default: `30s`) Timeout before we consider a HC request failed.
76+
- `health_check_delay` - (Default: `60s`) Interval between two HC requests.
77+
- `health_check_port` - (Default: `forward_port`) Port the HC requests will be send to.
78+
- `health_check_max_retries` - (Default: `2`) Number of allowed failed HC requests before the backend server is marked down.
79+
- `health_check_tcp` - (Optional) This block enable TCP health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
80+
- `health_check_http` - (Optional) This block enable HTTP health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
81+
- `uri` - (Required) The HTTP endpoint URL to call for HC requests.
82+
- `method` - (Default: `GET`) The HTTP method to use for HC requests.
83+
- `code` - (Default: `200`) The expected HTTP status code.
84+
- `host_header` - (Optional) The HTTP host header to use for HC requests.
85+
- `health_check_https` - (Optional) This block enable HTTPS health check. Only one of `health_check_tcp`, `health_check_http` and `health_check_https` should be specified.
86+
- `uri` - (Required) The HTTPS endpoint URL to call for HC requests.
87+
- `method` - (Default: `GET`) The HTTP method to use for HC requests.
88+
- `code` - (Default: `200`) The expected HTTP status code.
89+
- `host_header` - (Optional) The HTTP host header to use for HC requests.
90+
- `sni` - (Optional) The SNI to use for HC requests over SSL.
91+
- `on_marked_down_action` - (Default: `none`) Modify what occurs when a backend server is marked down. Possible values are: `none` and `shutdown_sessions`.
92+
- `health_check_transient_delay` - (Default: `0.5s`) The time to wait between two consecutive health checks when a backend server is in a transient state (going UP or DOWN).
9393

9494
## Attributes Reference
9595

scaleway/resource_lb_backend.go

+30-9
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ func resourceScalewayLbBackend() *schema.Resource {
249249
},
250250
},
251251
},
252+
"health_check_transient_delay": {
253+
Type: schema.TypeString,
254+
Optional: true,
255+
Default: "0.5s",
256+
ValidateFunc: validateDuration(),
257+
DiffSuppressFunc: diffSuppressFuncDuration,
258+
Description: "Time to wait between two consecutive health checks when a backend server is in a transient state (going UP or DOWN)",
259+
},
252260
"on_marked_down_action": {
253261
Type: schema.TypeString,
254262
ValidateFunc: validation.StringInSlice([]string{
@@ -286,11 +294,12 @@ E.g. 'failover-website.s3-website.fr-par.scw.cloud' if your bucket website URL i
286294
Description: "Maximum number of connections allowed per backend server",
287295
},
288296
"timeout_queue": {
289-
Type: schema.TypeString,
290-
Optional: true,
291-
Default: "0s",
292-
ValidateFunc: validateDuration(),
293-
Description: "Maximum time (in seconds) for a request to be left pending in queue when `max_connections` is reached",
297+
Type: schema.TypeString,
298+
Optional: true,
299+
Default: "0s",
300+
ValidateFunc: validateDuration(),
301+
DiffSuppressFunc: diffSuppressFuncDuration,
302+
Description: "Maximum time (in seconds) for a request to be left pending in queue when `max_connections` is reached",
294303
},
295304
"redispatch_attempt_count": {
296305
Type: schema.TypeInt,
@@ -399,6 +408,13 @@ func resourceScalewayLbBackendCreate(ctx context.Context, d *schema.ResourceData
399408
if maxRetries, ok := d.GetOk("max_retries"); ok {
400409
createReq.MaxRetries = expandInt32Ptr(maxRetries)
401410
}
411+
if healthCheckTransientDelay, ok := d.GetOk("health_check_transient_delay"); ok {
412+
timeout, err := time.ParseDuration(healthCheckTransientDelay.(string))
413+
if err != nil {
414+
return diag.FromErr(err)
415+
}
416+
createReq.HealthCheck.TransientCheckDelay = &scw.Duration{Seconds: int64(timeout.Seconds()), Nanos: int32(timeout.Nanoseconds())}
417+
}
402418

403419
// deprecated attribute
404420
createReq.SendProxyV2 = expandBoolPtr(getBool(d, "send_proxy_v2"))
@@ -467,10 +483,8 @@ func resourceScalewayLbBackendRead(ctx context.Context, d *schema.ResourceData,
467483
_ = d.Set("max_connections", flattenInt32Ptr(backend.MaxConnections))
468484
_ = d.Set("redispatch_attempt_count", flattenInt32Ptr(backend.RedispatchAttemptCount))
469485
_ = d.Set("max_retries", flattenInt32Ptr(backend.MaxRetries))
470-
471-
if backend.TimeoutQueue != nil {
472-
_ = d.Set("timeout_queue", flattenDuration(backend.TimeoutQueue.ToTimeDuration()))
473-
}
486+
_ = d.Set("timeout_queue", flattenDuration(backend.TimeoutQueue.ToTimeDuration()))
487+
_ = d.Set("health_check_transient_delay", flattenDuration(backend.HealthCheck.TransientCheckDelay.ToTimeDuration()))
474488

475489
_, err = waitForLB(ctx, lbAPI, zone, backend.LB.ID, d.Timeout(schema.TimeoutRead))
476490
if err != nil {
@@ -575,6 +589,13 @@ func resourceScalewayLbBackendUpdate(ctx context.Context, d *schema.ResourceData
575589
HTTPConfig: expandLbHCHTTP(d.Get("health_check_http")),
576590
HTTPSConfig: expandLbHCHTTPS(d.Get("health_check_https")),
577591
}
592+
if healthCheckTransientDelay, ok := d.GetOk("health_check_transient_delay"); ok {
593+
timeout, err := time.ParseDuration(healthCheckTransientDelay.(string))
594+
if err != nil {
595+
return diag.FromErr(err)
596+
}
597+
updateHCRequest.TransientCheckDelay = &scw.Duration{Seconds: int64(timeout.Seconds()), Nanos: int32(timeout.Nanoseconds())}
598+
}
578599

579600
// As this is the default behaviour if no other HC type are present we enable TCP
580601
if updateHCRequest.HTTPConfig == nil && updateHCRequest.HTTPSConfig == nil {

scaleway/resource_lb_backend_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestAccScalewayLbBackend_Basic(t *testing.T) {
5656
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "ignore_ssl_server_verify", "false"),
5757
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "redispatch_attempt_count", "0"),
5858
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "max_retries", "3"),
59+
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "health_check_transient_delay", "500ms"),
5960
),
6061
},
6162
{
@@ -94,6 +95,7 @@ func TestAccScalewayLbBackend_Basic(t *testing.T) {
9495
timeout_queue = "4s"
9596
redispatch_attempt_count = 1
9697
max_retries = 6
98+
health_check_transient_delay = "0.2s"
9799
}
98100
`,
99101
Check: resource.ComposeTestCheckFunc(
@@ -114,6 +116,7 @@ func TestAccScalewayLbBackend_Basic(t *testing.T) {
114116
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "timeout_queue", "4s"),
115117
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "redispatch_attempt_count", "1"),
116118
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "max_retries", "6"),
119+
resource.TestCheckResourceAttr("scaleway_lb_backend.bkd01", "health_check_transient_delay", "200ms"),
117120
),
118121
},
119122
},

0 commit comments

Comments
 (0)