Skip to content

Commit

Permalink
Merge pull request cloudflare#658 from tpolich/load_balancer_load_she…
Browse files Browse the repository at this point in the history
…dding

Support for LoadBalancer load shedding
  • Loading branch information
jacobbednarz authored Jun 23, 2021
2 parents dfa227c + 5872391 commit 590aa29
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 12 deletions.
33 changes: 21 additions & 12 deletions load_balancing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import (

// LoadBalancerPool represents a load balancer pool's properties.
type LoadBalancerPool struct {
ID string `json:"id,omitempty"`
CreatedOn *time.Time `json:"created_on,omitempty"`
ModifiedOn *time.Time `json:"modified_on,omitempty"`
Description string `json:"description"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
MinimumOrigins int `json:"minimum_origins,omitempty"`
Monitor string `json:"monitor,omitempty"`
Origins []LoadBalancerOrigin `json:"origins"`
NotificationEmail string `json:"notification_email,omitempty"`
Latitude *float32 `json:"latitude,omitempty"`
Longitude *float32 `json:"longitude,omitempty"`
ID string `json:"id,omitempty"`
CreatedOn *time.Time `json:"created_on,omitempty"`
ModifiedOn *time.Time `json:"modified_on,omitempty"`
Description string `json:"description"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
MinimumOrigins int `json:"minimum_origins,omitempty"`
Monitor string `json:"monitor,omitempty"`
Origins []LoadBalancerOrigin `json:"origins"`
NotificationEmail string `json:"notification_email,omitempty"`
Latitude *float32 `json:"latitude,omitempty"`
Longitude *float32 `json:"longitude,omitempty"`
LoadShedding *LoadBalancerLoadShedding `json:"load_shedding,omitempty"`

// CheckRegions defines the geographic region(s) from where to run health-checks from - e.g. "WNAM", "WEU", "SAF", "SAM".
// Providing a null/empty value means "all regions", which may not be available to all plan types.
Expand Down Expand Up @@ -89,6 +90,14 @@ type LoadBalancer struct {
SteeringPolicy string `json:"steering_policy,omitempty"`
}

// LoadBalancerLoadShedding contains the settings for controlling load shedding
type LoadBalancerLoadShedding struct {
DefaultPercent float32 `json:"default_percent,omitempty"`
DefaultPolicy string `json:"default_policy,omitempty"`
SessionPercent float32 `json:"session_percent,omitempty"`
SessionPolicy string `json:"session_policy,omitempty"`
}

// LoadBalancerRule represents a single rule entry for a Load Balancer. Each rules
// is run one after the other in priority order. Disabled rules are skipped.
type LoadBalancerRule struct {
Expand Down
24 changes: 24 additions & 0 deletions load_balancing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func TestCreateLoadBalancerPool(t *testing.T) {
"monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc",
"latitude": 55,
"longitude": -12.5,
"load_shedding": {
"default_percent": 50,
"default_policy": "random",
"session_percent": 10,
"session_policy": "hash"
},
"origins": [
{
"name": "app-server-1",
Expand Down Expand Up @@ -62,6 +68,12 @@ func TestCreateLoadBalancerPool(t *testing.T) {
"monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc",
"latitude": 55,
"longitude": -12.5,
"load_shedding": {
"default_percent": 50,
"default_policy": "random",
"session_percent": 10,
"session_policy": "hash"
},
"origins": [
{
"name": "app-server-1",
Expand Down Expand Up @@ -101,6 +113,12 @@ func TestCreateLoadBalancerPool(t *testing.T) {
Monitor: "f1aba936b94213e5b8dca0c0dbf1f9cc",
Latitude: fptr(55),
Longitude: fptr(-12.5),
LoadShedding: &LoadBalancerLoadShedding{
DefaultPercent: 50,
DefaultPolicy: "random",
SessionPercent: 10,
SessionPolicy: "hash",
},
Origins: []LoadBalancerOrigin{
{
Name: "app-server-1",
Expand All @@ -124,6 +142,12 @@ func TestCreateLoadBalancerPool(t *testing.T) {
Monitor: "f1aba936b94213e5b8dca0c0dbf1f9cc",
Latitude: fptr(55),
Longitude: fptr(-12.5),
LoadShedding: &LoadBalancerLoadShedding{
DefaultPercent: 50,
DefaultPolicy: "random",
SessionPercent: 10,
SessionPolicy: "hash",
},
Origins: []LoadBalancerOrigin{
{
Name: "app-server-1",
Expand Down

0 comments on commit 590aa29

Please sign in to comment.