Skip to content

Commit

Permalink
load_balancing: support least_connections steering policy and origin …
Browse files Browse the repository at this point in the history
…steering policy

- load_balancer: update description for steering_policy and steering_policy override
and extend the enum for least_connections

- load_balancer: update description for random_steering and random_steering override

- pool: update description for origin_steering.policy and extend the enum
for least_connections

- pool: update description for origin weight
  • Loading branch information
tc80 committed Oct 6, 2023
1 parent 0361820 commit 8729458
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .changelog/2818.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/cloudflare_load_balancer: Add support for least_connections steering
```

```release-note:enhancement
resource/cloudflare_load_balancer_pool: Add support for least_connections origin steering
```
8 changes: 4 additions & 4 deletions docs/resources/load_balancer.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ resource "cloudflare_load_balancer_pool" "example" {
- `location_strategy` (Block Set) Controls location-based steering for non-proxied requests. (see [below for nested schema](#nestedblock--location_strategy))
- `pop_pools` (Block Set) A set containing mappings of Cloudflare Point-of-Presence (PoP) identifiers to a list of pool IDs (ordered by their failover priority) for the PoP (datacenter). This feature is only available to enterprise customers. (see [below for nested schema](#nestedblock--pop_pools))
- `proxied` (Boolean) Whether the hostname gets Cloudflare's origin protection. Defaults to `false`. Conflicts with `ttl`.
- `random_steering` (Block Set) Configures pool weights. When [`steering_policy="random"`](#steering_policy), a random pool is selected with probability proportional to pool weights. When [`steering_policy="least_outstanding_requests"`](#steering_policy), pool weights are used to scale each pool's outstanding requests. (see [below for nested schema](#nestedblock--random_steering))
- `random_steering` (Block Set) Configures pool weights. When [`steering_policy="random"`](#steering_policy), a random pool is selected with probability proportional to pool weights. When [`steering_policy="least_outstanding_requests"`](#steering_policy), pool weights are used to scale each pool's outstanding requests. When [`steering_policy="least_connections"`](#steering_policy), pool weights are used to scale each pool's open connections. (see [below for nested schema](#nestedblock--random_steering))
- `region_pools` (Block Set) A set containing mappings of region codes to a list of pool IDs (ordered by their failover priority) for the given region. (see [below for nested schema](#nestedblock--region_pools))
- `rules` (Block List) A list of rules for this load balancer to execute. (see [below for nested schema](#nestedblock--rules))
- `session_affinity` (String) Specifies the type of session affinity the load balancer should use unless specified as `none` or `""` (default). With value `cookie`, on the first request to a proxied load balancer, a cookie is generated, encoding information of which origin the request will be forwarded to. Subsequent requests, by the same client to the same load balancer, will be sent to the origin server the cookie encodes, for the duration of the cookie and as long as the origin server remains healthy. If the cookie has expired or the origin server is unhealthy then a new origin server is calculated and used. Value `ip_cookie` behaves the same as `cookie` except the initial origin selection is stable and based on the client's IP address. Available values: `""`, `none`, `cookie`, `ip_cookie`, `header`. Defaults to `none`.
- `session_affinity_attributes` (Block Set) Configure attributes for session affinity. (see [below for nested schema](#nestedblock--session_affinity_attributes))
- `session_affinity_ttl` (Number) Time, in seconds, until this load balancer's session affinity cookie expires after being created. This parameter is ignored unless a supported session affinity policy is set. The current default of `82800` (23 hours) will be used unless [`session_affinity_ttl`](#session_affinity_ttl) is explicitly set. Once the expiry time has been reached, subsequent requests may get sent to a different origin server. Valid values are between `1800` and `604800`.
- `steering_policy` (String) The method the load balancer uses to determine the route to your origin. Value `off` uses [`default_pool_ids`](#default_pool_ids). Value `geo` uses [`pop_pools`](#pop_pools)/[`country_pools`](#country_pools)/[`region_pools`](#region_pools). For non-proxied requests, the [`country`](#country) for [`country_pools`](#country_pools) is determined by [`location_strategy`](#location_strategy). Value `random` selects a pool randomly. Value `dynamic_latency` uses round trip time to select the closest pool in [`default_pool_ids`](#default_pool_ids) (requires pool health checks). Value `proximity` uses the pools' latitude and longitude to select the closest pool using the Cloudflare PoP location for proxied requests or the location determined by [`location_strategy`](#location_strategy) for non-proxied requests. Value `least_outstanding_requests` selects a pool by taking into consideration [`random_steering`](#random_steering) weights, as well as each pool's number of outstanding requests. Pools with more pending requests are weighted proportionately less relative to others. Value `""` maps to `geo` if you use [`pop_pools`](#pop_pools)/[`country_pools`](#country_pools)/[`region_pools`](#region_pools) otherwise `off`. Available values: `off`, `geo`, `dynamic_latency`, `random`, `proximity`, `least_outstanding_requests`, `""` Defaults to `""`.
- `steering_policy` (String) The method the load balancer uses to determine the route to your origin. Value `off` uses [`default_pool_ids`](#default_pool_ids). Value `geo` uses [`pop_pools`](#pop_pools)/[`country_pools`](#country_pools)/[`region_pools`](#region_pools). For non-proxied requests, the [`country`](#country) for [`country_pools`](#country_pools) is determined by [`location_strategy`](#location_strategy). Value `random` selects a pool randomly. Value `dynamic_latency` uses round trip time to select the closest pool in [`default_pool_ids`](#default_pool_ids) (requires pool health checks). Value `proximity` uses the pools' latitude and longitude to select the closest pool using the Cloudflare PoP location for proxied requests or the location determined by [`location_strategy`](#location_strategy) for non-proxied requests. Value `least_outstanding_requests` selects a pool by taking into consideration [`random_steering`](#random_steering) weights, as well as each pool's number of outstanding requests. Pools with more pending requests are weighted proportionately less relative to others. Value `least_connections` selects a pool by taking into consideration [`random_steering`](#random_steering) weights, as well as each pool's number of open connections. Pools with more open connections are weighted proportionately less relative to others. Supported for HTTP/1 and HTTP/2 connections. Value `""` maps to `geo` if you use [`pop_pools`](#pop_pools)/[`country_pools`](#country_pools)/[`region_pools`](#region_pools) otherwise `off`. Available values: `off`, `geo`, `dynamic_latency`, `random`, `proximity`, `least_outstanding_requests`, `least_connections`, `""` Defaults to `""`.
- `ttl` (Number) Time to live (TTL) of the DNS entry for the IP address returned by this load balancer. This cannot be set for proxied load balancers. Defaults to `30`. Conflicts with `proxied`.

### Read-Only
Expand Down Expand Up @@ -194,12 +194,12 @@ Optional:
- `fallback_pool` (String) The pool ID to use when all other pools are detected as unhealthy.
- `location_strategy` (Block Set) Controls location-based steering for non-proxied requests. (see [below for nested schema](#nestedblock--rules--overrides--location_strategy))
- `pop_pools` (Block Set) A set containing mappings of Cloudflare Point-of-Presence (PoP) identifiers to a list of pool IDs (ordered by their failover priority) for the PoP (datacenter). This feature is only available to enterprise customers. (see [below for nested schema](#nestedblock--rules--overrides--pop_pools))
- `random_steering` (Block Set) Configures pool weights. When [`steering_policy="random"`](#steering_policy), a random pool is selected with probability proportional to pool weights. When [`steering_policy="least_outstanding_requests"`](#steering_policy), pool weights are used to scale each pool's outstanding requests. (see [below for nested schema](#nestedblock--rules--overrides--random_steering))
- `random_steering` (Block Set) Configures pool weights. When [`steering_policy="random"`](#steering_policy), a random pool is selected with probability proportional to pool weights. When [`steering_policy="least_outstanding_requests"`](#steering_policy), pool weights are used to scale each pool's outstanding requests. When [`steering_policy="least_connections"`](#steering_policy), pool weights are used to scale each pool's open connections. (see [below for nested schema](#nestedblock--rules--overrides--random_steering))
- `region_pools` (Block Set) A set containing mappings of region codes to a list of pool IDs (ordered by their failover priority) for the given region. (see [below for nested schema](#nestedblock--rules--overrides--region_pools))
- `session_affinity` (String) Configure attributes for session affinity.
- `session_affinity_attributes` (Block Set) Configure attributes for session affinity. Note that the property [`drain_duration`](#drain_duration) is not currently supported as a rule override. (see [below for nested schema](#nestedblock--rules--overrides--session_affinity_attributes))
- `session_affinity_ttl` (Number) Time, in seconds, until this load balancer's session affinity cookie expires after being created. This parameter is ignored unless a supported session affinity policy is set. The current default of `82800` (23 hours) will be used unless [`session_affinity_ttl`](#session_affinity_ttl) is explicitly set. Once the expiry time has been reached, subsequent requests may get sent to a different origin server. Valid values are between `1800` and `604800`.
- `steering_policy` (String) The method the load balancer uses to determine the route to your origin. Value `off` uses [`default_pool_ids`](#default_pool_ids). Value `geo` uses [`pop_pools`](#pop_pools)/[`country_pools`](#country_pools)/[`region_pools`](#region_pools). For non-proxied requests, the [`country`](#country) for [`country_pools`](#country_pools) is determined by [`location_strategy`](#location_strategy). Value `random` selects a pool randomly. Value `dynamic_latency` uses round trip time to select the closest pool in [`default_pool_ids`](#default_pool_ids) (requires pool health checks). Value `proximity` uses the pools' latitude and longitude to select the closest pool using the Cloudflare PoP location for proxied requests or the location determined by [`location_strategy`](#location_strategy) for non-proxied requests. Value `least_outstanding_requests` selects a pool by taking into consideration [`random_steering`](#random_steering) weights, as well as each pool's number of outstanding requests. Pools with more pending requests are weighted proportionately less relative to others. Value `""` maps to `geo` if you use [`pop_pools`](#pop_pools)/[`country_pools`](#country_pools)/[`region_pools`](#region_pools) otherwise `off`. Available values: `off`, `geo`, `dynamic_latency`, `random`, `proximity`, `least_outstanding_requests`, `""` Defaults to `""`.
- `steering_policy` (String) The method the load balancer uses to determine the route to your origin. Value `off` uses [`default_pool_ids`](#default_pool_ids). Value `geo` uses [`pop_pools`](#pop_pools)/[`country_pools`](#country_pools)/[`region_pools`](#region_pools). For non-proxied requests, the [`country`](#country) for [`country_pools`](#country_pools) is determined by [`location_strategy`](#location_strategy). Value `random` selects a pool randomly. Value `dynamic_latency` uses round trip time to select the closest pool in [`default_pool_ids`](#default_pool_ids) (requires pool health checks). Value `proximity` uses the pools' latitude and longitude to select the closest pool using the Cloudflare PoP location for proxied requests or the location determined by [`location_strategy`](#location_strategy) for non-proxied requests. Value `least_outstanding_requests` selects a pool by taking into consideration [`random_steering`](#random_steering) weights, as well as each pool's number of outstanding requests. Pools with more pending requests are weighted proportionately less relative to others. Value `least_connections` selects a pool by taking into consideration [`random_steering`](#random_steering) weights, as well as each pool's number of open connections. Pools with more open connections are weighted proportionately less relative to others. Supported for HTTP/1 and HTTP/2 connections. Value `""` maps to `geo` if you use [`pop_pools`](#pop_pools)/[`country_pools`](#country_pools)/[`region_pools`](#region_pools) otherwise `off`. Available values: `off`, `geo`, `dynamic_latency`, `random`, `proximity`, `least_outstanding_requests`, `least_connections`, `""` Defaults to `""`.
- `ttl` (Number) Time to live (TTL) of the DNS entry for the IP address returned by this load balancer. This cannot be set for proxied load balancers. Defaults to `30`.

<a id="nestedblock--rules--overrides--adaptive_routing"></a>
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/load_balancer_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Optional:

- `enabled` (Boolean) Whether this origin is enabled. Disabled origins will not receive traffic and are excluded from health checks. Defaults to `true`.
- `header` (Block Set) HTTP request headers. (see [below for nested schema](#nestedblock--origins--header))
- `weight` (Number) The weight (0.01 - 1.00) of this origin, relative to other origins in the pool. Equal values mean equal weighting. A weight of 0 means traffic will not be sent to this origin, but health is still checked. When [`origin_steering.policy="least_outstanding_requests"`](#policy), weight is used to scale the origin's outstanding requests. Defaults to `1`.
- `weight` (Number) The weight (0.01 - 1.00) of this origin, relative to other origins in the pool. Equal values mean equal weighting. A weight of 0 means traffic will not be sent to this origin, but health is still checked. When [`origin_steering.policy="least_outstanding_requests"`](#policy), weight is used to scale the origin's outstanding requests. When [`origin_steering.policy="least_connections"`](#policy), weight is used to scale the origin's open connections. Defaults to `1`.

<a id="nestedblock--origins--header"></a>
### Nested Schema for `origins.header`
Expand Down Expand Up @@ -119,7 +119,7 @@ Optional:

Optional:

- `policy` (String) Origin steering policy to be used. Value `random` selects an origin randomly. Value `hash` selects an origin by computing a hash over the CF-Connecting-IP address. Value `least_outstanding_requests` selects an origin by taking into consideration origin weights, as well as each origin's number of outstanding requests. Origins with more pending requests are weighted proportionately less relative to others. Available values: `""`, `hash`, `random`, `least_outstanding_requests`. Defaults to `random`.
- `policy` (String) Origin steering policy to be used. Value `random` selects an origin randomly. Value `hash` selects an origin by computing a hash over the CF-Connecting-IP address. Value `least_outstanding_requests` selects an origin by taking into consideration origin weights, as well as each origin's number of outstanding requests. Origins with more pending requests are weighted proportionately less relative to others. Value `least_connections` selects an origin by taking into consideration origin weights, as well as each origin's number of open connections. Origins with more open connections are weighted proportionately less relative to others. Supported for HTTP/1 and HTTP/2 connections. Available values: `""`, `hash`, `random`, `least_outstanding_requests`, `least_connections`. Defaults to `random`.

## Import

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,40 @@ func TestAccCloudflareLoadBalancerPool_OriginSteeringLeastOutstandingRequests(t
})
}

func TestAccCloudflareLoadBalancerPool_OriginSteeringLeastConnections(t *testing.T) {
// multiple instances of this config would conflict but we only use it once
t.Parallel()
testStartTime := time.Now().UTC()
var loadBalancerPool cloudflare.LoadBalancerPool
rnd := generateRandomResourceName()
name := "cloudflare_load_balancer_pool." + rnd
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckCloudflareLoadBalancerPoolDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckCloudflareLoadBalancerPoolConfigOriginSteeringLeastConnections(rnd, accountID),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareLoadBalancerPoolExists(name, &loadBalancerPool),
// dont check that specified values are set, this will be evident by lack of plan diff
// some values will get empty values
resource.TestCheckResourceAttr(name, "check_regions.#", "0"),
resource.TestCheckResourceAttr(name, "header.#", "0"),
resource.TestCheckResourceAttr(name, "origin_steering.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(name, "origin_steering.*", map[string]string{
"policy": "least_connections",
}),
// also expect api to generate some values
testAccCheckCloudflareLoadBalancerPoolDates(name, &loadBalancerPool, testStartTime),
),
},
},
})
}

func TestAccCloudflareLoadBalancerPool_FullySpecified(t *testing.T) {
t.Parallel()
var loadBalancerPool cloudflare.LoadBalancerPool
Expand Down Expand Up @@ -321,6 +355,24 @@ resource "cloudflare_load_balancer_pool" "%[1]s" {
}`, id, accountID)
}

func testAccCheckCloudflareLoadBalancerPoolConfigOriginSteeringLeastConnections(id, accountID string) string {
return fmt.Sprintf(`
resource "cloudflare_load_balancer_pool" "%[1]s" {
account_id = "%[2]s"
name = "my-tf-pool-basic-%[1]s"
latitude = 12.3
longitude = 55
origins {
name = "example-1"
address = "192.0.2.1"
enabled = true
}
origin_steering {
policy = "least_connections"
}
}`, id, accountID)
}

func testAccCheckCloudflareLoadBalancerPoolConfigFullySpecified(id, headerValue, accountID string) string {
return fmt.Sprintf(`
resource "cloudflare_load_balancer_pool" "%[1]s" {
Expand Down
Loading

0 comments on commit 8729458

Please sign in to comment.