From 8050cf5cce3c4c7e626c5feab3686a56d34446a7 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 21 Mar 2023 10:21:45 -0700 Subject: [PATCH] Add WEIGHTED_MAGLEV to localityLbPolicy enum, and update associated docstrings. (#7444) (#5353) * Add WEIGHTED_MAGLEV to localityLbPolicy enum, and update associated docstrings. * Example for WEIGHTED_MAGLEV uses HTTP health check. Signed-off-by: Modular Magician --- .changelog/7444.txt | 3 ++ .../resource_compute_backend_service.go | 24 ++++++++-- ...resource_compute_region_backend_service.go | 24 ++++++++-- ...e_region_backend_service_generated_test.go | 47 ++++++++++++++++++ .../r/compute_backend_service.html.markdown | 21 ++++++-- ...mpute_region_backend_service.html.markdown | 48 +++++++++++++++++-- 6 files changed, 153 insertions(+), 14 deletions(-) create mode 100644 .changelog/7444.txt diff --git a/.changelog/7444.txt b/.changelog/7444.txt new file mode 100644 index 0000000000..de77cda019 --- /dev/null +++ b/.changelog/7444.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: added `WEIGHED_MAGLEV` to `locality_lb_policy` enum for backend service resources. +``` diff --git a/google-beta/resource_compute_backend_service.go b/google-beta/resource_compute_backend_service.go index 588138e762..2f8571302f 100644 --- a/google-beta/resource_compute_backend_service.go +++ b/google-beta/resource_compute_backend_service.go @@ -765,7 +765,7 @@ The possible values are: "locality_lb_policy": { Type: schema.TypeString, Optional: true, - ValidateFunc: validateEnum([]string{"ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", ""}), + ValidateFunc: validateEnum([]string{"ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", "WEIGHTED_MAGLEV", ""}), Description: `The load balancing algorithm used within the scope of the locality. The possible values are: @@ -793,20 +793,36 @@ The possible values are: build times and host selection times. For more information about Maglev, refer to https://ai.google/research/pubs/pub44824 +* 'WEIGHTED_MAGLEV': Per-instance weighted Load Balancing via health check + reported weights. If set, the Backend Service must + configure a non legacy HTTP-based Health Check, and + health check replies are expected to contain + non-standard HTTP response header field + X-Load-Balancing-Endpoint-Weight to specify the + per-instance weights. If set, Load Balancing is weight + based on the per-instance weights reported in the last + processed health check replies, as long as every + instance either reported a valid weight or had + UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains + equal-weight. + This field is applicable to either: * A regional backend service with the service_protocol set to HTTP, HTTPS, or HTTP2, and loadBalancingScheme set to INTERNAL_MANAGED. * A global backend service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED. +* A regional backend service with loadBalancingScheme set to EXTERNAL (External Network + Load Balancing). Only MAGLEV and WEIGHTED_MAGLEV values are possible for External + Network Load Balancing. The default is MAGLEV. -If session_affinity is not NONE, and this field is not set to MAGLEV or RING_HASH, -session affinity settings will not take effect. +If session_affinity is not NONE, and this field is not set to MAGLEV, WEIGHTED_MAGLEV, +or RING_HASH, session affinity settings will not take effect. Only ROUND_ROBIN and RING_HASH are supported when the backend service is referenced by a URL map that is bound to target gRPC proxy that has validate_for_proxyless -field set to true. Possible values: ["ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV"]`, +field set to true. Possible values: ["ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", "WEIGHTED_MAGLEV"]`, }, "log_config": { Type: schema.TypeList, diff --git a/google-beta/resource_compute_region_backend_service.go b/google-beta/resource_compute_region_backend_service.go index e4c264831f..d954d091d1 100644 --- a/google-beta/resource_compute_region_backend_service.go +++ b/google-beta/resource_compute_region_backend_service.go @@ -673,7 +673,7 @@ balancing cannot be used with the other(s). For more information, refer to "locality_lb_policy": { Type: schema.TypeString, Optional: true, - ValidateFunc: validateEnum([]string{"ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", ""}), + ValidateFunc: validateEnum([]string{"ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", "WEIGHTED_MAGLEV", ""}), Description: `The load balancing algorithm used within the scope of the locality. The possible values are: @@ -701,20 +701,36 @@ The possible values are: build times and host selection times. For more information about Maglev, refer to https://ai.google/research/pubs/pub44824 +* 'WEIGHTED_MAGLEV': Per-instance weighted Load Balancing via health check + reported weights. If set, the Backend Service must + configure a non legacy HTTP-based Health Check, and + health check replies are expected to contain + non-standard HTTP response header field + X-Load-Balancing-Endpoint-Weight to specify the + per-instance weights. If set, Load Balancing is weight + based on the per-instance weights reported in the last + processed health check replies, as long as every + instance either reported a valid weight or had + UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains + equal-weight. + This field is applicable to either: * A regional backend service with the service_protocol set to HTTP, HTTPS, or HTTP2, and loadBalancingScheme set to INTERNAL_MANAGED. * A global backend service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED. +* A regional backend service with loadBalancingScheme set to EXTERNAL (External Network + Load Balancing). Only MAGLEV and WEIGHTED_MAGLEV values are possible for External + Network Load Balancing. The default is MAGLEV. -If session_affinity is not NONE, and this field is not set to MAGLEV or RING_HASH, -session affinity settings will not take effect. +If session_affinity is not NONE, and this field is not set to MAGLEV, WEIGHTED_MAGLEV, +or RING_HASH, session affinity settings will not take effect. Only ROUND_ROBIN and RING_HASH are supported when the backend service is referenced by a URL map that is bound to target gRPC proxy that has validate_for_proxyless -field set to true. Possible values: ["ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV"]`, +field set to true. Possible values: ["ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH", "RANDOM", "ORIGINAL_DESTINATION", "MAGLEV", "WEIGHTED_MAGLEV"]`, }, "log_config": { Type: schema.TypeList, diff --git a/google-beta/resource_compute_region_backend_service_generated_test.go b/google-beta/resource_compute_region_backend_service_generated_test.go index d7790d6796..b2bab09ca0 100644 --- a/google-beta/resource_compute_region_backend_service_generated_test.go +++ b/google-beta/resource_compute_region_backend_service_generated_test.go @@ -224,6 +224,53 @@ resource "google_compute_region_health_check" "health_check" { `, context) } +func TestAccComputeRegionBackendService_regionBackendServiceExternalWeightedExample(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": RandString(t, 10), + } + + VcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV5ProviderFactories: ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckComputeRegionBackendServiceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionBackendService_regionBackendServiceExternalWeightedExample(context), + }, + { + ResourceName: "google_compute_region_backend_service.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"network", "region"}, + }, + }, + }) +} + +func testAccComputeRegionBackendService_regionBackendServiceExternalWeightedExample(context map[string]interface{}) string { + return Nprintf(` +resource "google_compute_region_backend_service" "default" { + region = "us-central1" + name = "tf-test-region-service%{random_suffix}" + health_checks = [google_compute_region_health_check.health_check.id] + protocol = "TCP" + load_balancing_scheme = "EXTERNAL" + locality_lb_policy = "WEIGHTED_MAGLEV" +} + +resource "google_compute_region_health_check" "health_check" { + name = "tf-test-rbs-health-check%{random_suffix}" + region = "us-central1" + + http_health_check { + port = 80 + } +} +`, context) +} + func TestAccComputeRegionBackendService_regionBackendServiceIlbRingHashExample(t *testing.T) { t.Parallel() diff --git a/website/docs/r/compute_backend_service.html.markdown b/website/docs/r/compute_backend_service.html.markdown index 5c2c08346c..4f2863da53 100644 --- a/website/docs/r/compute_backend_service.html.markdown +++ b/website/docs/r/compute_backend_service.html.markdown @@ -421,18 +421,33 @@ The following arguments are supported: Maglev is not as stable as ring hash but has faster table lookup build times and host selection times. For more information about Maglev, refer to https://ai.google/research/pubs/pub44824 + * `WEIGHTED_MAGLEV`: Per-instance weighted Load Balancing via health check + reported weights. If set, the Backend Service must + configure a non legacy HTTP-based Health Check, and + health check replies are expected to contain + non-standard HTTP response header field + X-Load-Balancing-Endpoint-Weight to specify the + per-instance weights. If set, Load Balancing is weight + based on the per-instance weights reported in the last + processed health check replies, as long as every + instance either reported a valid weight or had + UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains + equal-weight. This field is applicable to either: * A regional backend service with the service_protocol set to HTTP, HTTPS, or HTTP2, and loadBalancingScheme set to INTERNAL_MANAGED. * A global backend service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED. + * A regional backend service with loadBalancingScheme set to EXTERNAL (External Network + Load Balancing). Only MAGLEV and WEIGHTED_MAGLEV values are possible for External + Network Load Balancing. The default is MAGLEV. - If session_affinity is not NONE, and this field is not set to MAGLEV or RING_HASH, - session affinity settings will not take effect. + If session_affinity is not NONE, and this field is not set to MAGLEV, WEIGHTED_MAGLEV, + or RING_HASH, session affinity settings will not take effect. Only ROUND_ROBIN and RING_HASH are supported when the backend service is referenced by a URL map that is bound to target gRPC proxy that has validate_for_proxyless field set to true. - Possible values are `ROUND_ROBIN`, `LEAST_REQUEST`, `RING_HASH`, `RANDOM`, `ORIGINAL_DESTINATION`, and `MAGLEV`. + Possible values are `ROUND_ROBIN`, `LEAST_REQUEST`, `RING_HASH`, `RANDOM`, `ORIGINAL_DESTINATION`, `MAGLEV`, and `WEIGHTED_MAGLEV`. * `locality_lb_policies` - (Optional) diff --git a/website/docs/r/compute_region_backend_service.html.markdown b/website/docs/r/compute_region_backend_service.html.markdown index c98489a436..18b8717357 100644 --- a/website/docs/r/compute_region_backend_service.html.markdown +++ b/website/docs/r/compute_region_backend_service.html.markdown @@ -154,6 +154,33 @@ resource "google_compute_region_health_check" "health_check" { } } ``` + +## Example Usage - Region Backend Service External Weighted + + +```hcl +resource "google_compute_region_backend_service" "default" { + region = "us-central1" + name = "region-service" + health_checks = [google_compute_region_health_check.health_check.id] + protocol = "TCP" + load_balancing_scheme = "EXTERNAL" + locality_lb_policy = "WEIGHTED_MAGLEV" +} + +resource "google_compute_region_health_check" "health_check" { + name = "rbs-health-check" + region = "us-central1" + + http_health_check { + port = 80 + } +} +```
Open in Cloud Shell @@ -432,18 +459,33 @@ The following arguments are supported: Maglev is not as stable as ring hash but has faster table lookup build times and host selection times. For more information about Maglev, refer to https://ai.google/research/pubs/pub44824 + * `WEIGHTED_MAGLEV`: Per-instance weighted Load Balancing via health check + reported weights. If set, the Backend Service must + configure a non legacy HTTP-based Health Check, and + health check replies are expected to contain + non-standard HTTP response header field + X-Load-Balancing-Endpoint-Weight to specify the + per-instance weights. If set, Load Balancing is weight + based on the per-instance weights reported in the last + processed health check replies, as long as every + instance either reported a valid weight or had + UNAVAILABLE_WEIGHT. Otherwise, Load Balancing remains + equal-weight. This field is applicable to either: * A regional backend service with the service_protocol set to HTTP, HTTPS, or HTTP2, and loadBalancingScheme set to INTERNAL_MANAGED. * A global backend service with the load_balancing_scheme set to INTERNAL_SELF_MANAGED. + * A regional backend service with loadBalancingScheme set to EXTERNAL (External Network + Load Balancing). Only MAGLEV and WEIGHTED_MAGLEV values are possible for External + Network Load Balancing. The default is MAGLEV. - If session_affinity is not NONE, and this field is not set to MAGLEV or RING_HASH, - session affinity settings will not take effect. + If session_affinity is not NONE, and this field is not set to MAGLEV, WEIGHTED_MAGLEV, + or RING_HASH, session affinity settings will not take effect. Only ROUND_ROBIN and RING_HASH are supported when the backend service is referenced by a URL map that is bound to target gRPC proxy that has validate_for_proxyless field set to true. - Possible values are `ROUND_ROBIN`, `LEAST_REQUEST`, `RING_HASH`, `RANDOM`, `ORIGINAL_DESTINATION`, and `MAGLEV`. + Possible values are `ROUND_ROBIN`, `LEAST_REQUEST`, `RING_HASH`, `RANDOM`, `ORIGINAL_DESTINATION`, `MAGLEV`, and `WEIGHTED_MAGLEV`. * `outlier_detection` - (Optional)