Skip to content

Commit 8a51b89

Browse files
Add WEIGHTED_MAGLEV to localityLbPolicy enum, and update associated docstrings. (#7444) (#14055)
* Add WEIGHTED_MAGLEV to localityLbPolicy enum, and update associated docstrings. * Example for WEIGHTED_MAGLEV uses HTTP health check. Signed-off-by: Modular Magician <[email protected]>
1 parent 987ff6a commit 8a51b89

6 files changed

+153
-14
lines changed

.changelog/7444.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `WEIGHED_MAGLEV` to `locality_lb_policy` enum for backend service resources.
3+
```

google/resource_compute_backend_service.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ The possible values are:
740740
"locality_lb_policy": {
741741
Type: schema.TypeString,
742742
Optional: true,
743-
ValidateFunc: validateEnum([]string{"ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", ""}),
743+
ValidateFunc: validateEnum([]string{"ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", "WEIGHTED_MAGLEV", ""}),
744744
Description: `The load balancing algorithm used within the scope of the locality.
745745
The possible values are:
746746
@@ -768,20 +768,36 @@ The possible values are:
768768
build times and host selection times. For more information about
769769
Maglev, refer to https://ai.google/research/pubs/pub44824
770770
771+
* 'WEIGHTED_MAGLEV': Per-instance weighted Load Balancing via health check
772+
reported weights. If set, the Backend Service must
773+
configure a non legacy HTTP-based Health Check, and
774+
health check replies are expected to contain
775+
non-standard HTTP response header field
776+
X-Load-Balancing-Endpoint-Weight to specify the
777+
per-instance weights. If set, Load Balancing is weight
778+
based on the per-instance weights reported in the last
779+
processed health check replies, as long as every
780+
instance either reported a valid weight or had
781+
UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains
782+
equal-weight.
783+
771784
772785
This field is applicable to either:
773786
774787
* A regional backend service with the service_protocol set to HTTP, HTTPS, or HTTP2,
775788
and loadBalancingScheme set to INTERNAL_MANAGED.
776789
* A global backend service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED.
790+
* A regional backend service with loadBalancingScheme set to EXTERNAL (External Network
791+
Load Balancing). Only MAGLEV and WEIGHTED_MAGLEV values are possible for External
792+
Network Load Balancing. The default is MAGLEV.
777793
778794
779-
If session_affinity is not NONE, and this field is not set to MAGLEV or RING_HASH,
780-
session affinity settings will not take effect.
795+
If session_affinity is not NONE, and this field is not set to MAGLEV, WEIGHTED_MAGLEV,
796+
or RING_HASH, session affinity settings will not take effect.
781797
782798
Only ROUND_ROBIN and RING_HASH are supported when the backend service is referenced
783799
by a URL map that is bound to target gRPC proxy that has validate_for_proxyless
784-
field set to true. Possible values: ["ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV"]`,
800+
field set to true. Possible values: ["ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", "WEIGHTED_MAGLEV"]`,
785801
},
786802
"log_config": {
787803
Type: schema.TypeList,

google/resource_compute_region_backend_service.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ balancing cannot be used with the other(s). For more information, refer to
585585
"locality_lb_policy": {
586586
Type: schema.TypeString,
587587
Optional: true,
588-
ValidateFunc: validateEnum([]string{"ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", ""}),
588+
ValidateFunc: validateEnum([]string{"ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", "WEIGHTED_MAGLEV", ""}),
589589
Description: `The load balancing algorithm used within the scope of the locality.
590590
The possible values are:
591591
@@ -613,20 +613,36 @@ The possible values are:
613613
build times and host selection times. For more information about
614614
Maglev, refer to https://ai.google/research/pubs/pub44824
615615
616+
* 'WEIGHTED_MAGLEV': Per-instance weighted Load Balancing via health check
617+
reported weights. If set, the Backend Service must
618+
configure a non legacy HTTP-based Health Check, and
619+
health check replies are expected to contain
620+
non-standard HTTP response header field
621+
X-Load-Balancing-Endpoint-Weight to specify the
622+
per-instance weights. If set, Load Balancing is weight
623+
based on the per-instance weights reported in the last
624+
processed health check replies, as long as every
625+
instance either reported a valid weight or had
626+
UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains
627+
equal-weight.
628+
616629
617630
This field is applicable to either:
618631
619632
* A regional backend service with the service_protocol set to HTTP, HTTPS, or HTTP2,
620633
and loadBalancingScheme set to INTERNAL_MANAGED.
621634
* A global backend service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED.
635+
* A regional backend service with loadBalancingScheme set to EXTERNAL (External Network
636+
Load Balancing). Only MAGLEV and WEIGHTED_MAGLEV values are possible for External
637+
Network Load Balancing. The default is MAGLEV.
622638
623639
624-
If session_affinity is not NONE, and this field is not set to MAGLEV or RING_HASH,
625-
session affinity settings will not take effect.
640+
If session_affinity is not NONE, and this field is not set to MAGLEV, WEIGHTED_MAGLEV,
641+
or RING_HASH, session affinity settings will not take effect.
626642
627643
Only ROUND_ROBIN and RING_HASH are supported when the backend service is referenced
628644
by a URL map that is bound to target gRPC proxy that has validate_for_proxyless
629-
field set to true. Possible values: ["ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV"]`,
645+
field set to true. Possible values: ["ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", "WEIGHTED_MAGLEV"]`,
630646
},
631647
"log_config": {
632648
Type: schema.TypeList,

google/resource_compute_region_backend_service_generated_test.go

+47
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,53 @@ resource "google_compute_health_check" "health_check" {
115115
`, context)
116116
}
117117

118+
func TestAccComputeRegionBackendService_regionBackendServiceExternalWeightedExample(t *testing.T) {
119+
t.Parallel()
120+
121+
context := map[string]interface{}{
122+
"random_suffix": RandString(t, 10),
123+
}
124+
125+
VcrTest(t, resource.TestCase{
126+
PreCheck: func() { testAccPreCheck(t) },
127+
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
128+
CheckDestroy: testAccCheckComputeRegionBackendServiceDestroyProducer(t),
129+
Steps: []resource.TestStep{
130+
{
131+
Config: testAccComputeRegionBackendService_regionBackendServiceExternalWeightedExample(context),
132+
},
133+
{
134+
ResourceName: "google_compute_region_backend_service.default",
135+
ImportState: true,
136+
ImportStateVerify: true,
137+
ImportStateVerifyIgnore: []string{"network", "region"},
138+
},
139+
},
140+
})
141+
}
142+
143+
func testAccComputeRegionBackendService_regionBackendServiceExternalWeightedExample(context map[string]interface{}) string {
144+
return Nprintf(`
145+
resource "google_compute_region_backend_service" "default" {
146+
region = "us-central1"
147+
name = "tf-test-region-service%{random_suffix}"
148+
health_checks = [google_compute_region_health_check.health_check.id]
149+
protocol = "TCP"
150+
load_balancing_scheme = "EXTERNAL"
151+
locality_lb_policy = "WEIGHTED_MAGLEV"
152+
}
153+
154+
resource "google_compute_region_health_check" "health_check" {
155+
name = "tf-test-rbs-health-check%{random_suffix}"
156+
region = "us-central1"
157+
158+
http_health_check {
159+
port = 80
160+
}
161+
}
162+
`, context)
163+
}
164+
118165
func TestAccComputeRegionBackendService_regionBackendServiceIlbRingHashExample(t *testing.T) {
119166
t.Parallel()
120167

website/docs/r/compute_backend_service.html.markdown

+18-3
Original file line numberDiff line numberDiff line change
@@ -421,18 +421,33 @@ The following arguments are supported:
421421
Maglev is not as stable as ring hash but has faster table lookup
422422
build times and host selection times. For more information about
423423
Maglev, refer to https://ai.google/research/pubs/pub44824
424+
* `WEIGHTED_MAGLEV`: Per-instance weighted Load Balancing via health check
425+
reported weights. If set, the Backend Service must
426+
configure a non legacy HTTP-based Health Check, and
427+
health check replies are expected to contain
428+
non-standard HTTP response header field
429+
X-Load-Balancing-Endpoint-Weight to specify the
430+
per-instance weights. If set, Load Balancing is weight
431+
based on the per-instance weights reported in the last
432+
processed health check replies, as long as every
433+
instance either reported a valid weight or had
434+
UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains
435+
equal-weight.
424436

425437
This field is applicable to either:
426438
* A regional backend service with the service_protocol set to HTTP, HTTPS, or HTTP2,
427439
and loadBalancingScheme set to INTERNAL_MANAGED.
428440
* A global backend service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED.
441+
* A regional backend service with loadBalancingScheme set to EXTERNAL (External Network
442+
Load Balancing). Only MAGLEV and WEIGHTED_MAGLEV values are possible for External
443+
Network Load Balancing. The default is MAGLEV.
429444

430-
If session_affinity is not NONE, and this field is not set to MAGLEV or RING_HASH,
431-
session affinity settings will not take effect.
445+
If session_affinity is not NONE, and this field is not set to MAGLEV, WEIGHTED_MAGLEV,
446+
or RING_HASH, session affinity settings will not take effect.
432447
Only ROUND_ROBIN and RING_HASH are supported when the backend service is referenced
433448
by a URL map that is bound to target gRPC proxy that has validate_for_proxyless
434449
field set to true.
435-
Possible values are `ROUND_ROBIN`, `LEAST_REQUEST`, `RING_HASH`, `RANDOM`, `ORIGINAL_DESTINATION`, and `MAGLEV`.
450+
Possible values are `ROUND_ROBIN`, `LEAST_REQUEST`, `RING_HASH`, `RANDOM`, `ORIGINAL_DESTINATION`, `MAGLEV`, and `WEIGHTED_MAGLEV`.
436451

437452
* `locality_lb_policies` -
438453
(Optional)

website/docs/r/compute_region_backend_service.html.markdown

+45-3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,33 @@ resource "google_compute_region_health_check" "health_check" {
154154
}
155155
}
156156
```
157+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
158+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=region_backend_service_external_weighted&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
159+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
160+
</a>
161+
</div>
162+
## Example Usage - Region Backend Service External Weighted
163+
164+
165+
```hcl
166+
resource "google_compute_region_backend_service" "default" {
167+
region = "us-central1"
168+
name = "region-service"
169+
health_checks = [google_compute_region_health_check.health_check.id]
170+
protocol = "TCP"
171+
load_balancing_scheme = "EXTERNAL"
172+
locality_lb_policy = "WEIGHTED_MAGLEV"
173+
}
174+
175+
resource "google_compute_region_health_check" "health_check" {
176+
name = "rbs-health-check"
177+
region = "us-central1"
178+
179+
http_health_check {
180+
port = 80
181+
}
182+
}
183+
```
157184
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
158185
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=region_backend_service_ilb_ring_hash&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
159186
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
@@ -432,18 +459,33 @@ The following arguments are supported:
432459
Maglev is not as stable as ring hash but has faster table lookup
433460
build times and host selection times. For more information about
434461
Maglev, refer to https://ai.google/research/pubs/pub44824
462+
* `WEIGHTED_MAGLEV`: Per-instance weighted Load Balancing via health check
463+
reported weights. If set, the Backend Service must
464+
configure a non legacy HTTP-based Health Check, and
465+
health check replies are expected to contain
466+
non-standard HTTP response header field
467+
X-Load-Balancing-Endpoint-Weight to specify the
468+
per-instance weights. If set, Load Balancing is weight
469+
based on the per-instance weights reported in the last
470+
processed health check replies, as long as every
471+
instance either reported a valid weight or had
472+
UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains
473+
equal-weight.
435474

436475
This field is applicable to either:
437476
* A regional backend service with the service_protocol set to HTTP, HTTPS, or HTTP2,
438477
and loadBalancingScheme set to INTERNAL_MANAGED.
439478
* A global backend service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED.
479+
* A regional backend service with loadBalancingScheme set to EXTERNAL (External Network
480+
Load Balancing). Only MAGLEV and WEIGHTED_MAGLEV values are possible for External
481+
Network Load Balancing. The default is MAGLEV.
440482

441-
If session_affinity is not NONE, and this field is not set to MAGLEV or RING_HASH,
442-
session affinity settings will not take effect.
483+
If session_affinity is not NONE, and this field is not set to MAGLEV, WEIGHTED_MAGLEV,
484+
or RING_HASH, session affinity settings will not take effect.
443485
Only ROUND_ROBIN and RING_HASH are supported when the backend service is referenced
444486
by a URL map that is bound to target gRPC proxy that has validate_for_proxyless
445487
field set to true.
446-
Possible values are `ROUND_ROBIN`, `LEAST_REQUEST`, `RING_HASH`, `RANDOM`, `ORIGINAL_DESTINATION`, and `MAGLEV`.
488+
Possible values are `ROUND_ROBIN`, `LEAST_REQUEST`, `RING_HASH`, `RANDOM`, `ORIGINAL_DESTINATION`, `MAGLEV`, and `WEIGHTED_MAGLEV`.
447489

448490
* `outlier_detection` -
449491
(Optional)

0 commit comments

Comments
 (0)