Skip to content

Commit

Permalink
Support for LoadBalancerOriginSteering
Browse files Browse the repository at this point in the history
  • Loading branch information
gofish committed Oct 6, 2021
1 parent 7d00b60 commit abe1783
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 52 deletions.
33 changes: 20 additions & 13 deletions load_balancing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ 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"`
LoadShedding *LoadBalancerLoadShedding `json:"load_shedding,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"`
OriginSteering *LoadBalancerOriginSteering `json:"origin_steering,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 All @@ -40,6 +41,12 @@ type LoadBalancerOrigin struct {
Header map[string][]string `json:"header"`
}

// LoadBalancerOriginSteering controls origin selection for new sessions and traffic without session affinity.
type LoadBalancerOriginSteering struct {
// Policy defaults to "random" (weighted) when empty or unspecified.
Policy string `json:"policy,omitempty"`
}

// LoadBalancerMonitor represents a load balancer monitor's properties.
type LoadBalancerMonitor struct {
ID string `json:"id,omitempty"`
Expand Down
114 changes: 75 additions & 39 deletions load_balancing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,35 @@ func TestCreateLoadBalancerPool(t *testing.T) {
"name": "primary-dc-1",
"enabled": true,
"monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc",
"latitude": 55,
"longitude": -12.5,
"load_shedding": {
"default_percent": 50,
"default_policy": "random",
"session_percent": 10,
"session_policy": "hash"
},
"latitude": 55,
"longitude": -12.5,
"load_shedding": {
"default_percent": 50,
"default_policy": "random",
"session_percent": 10,
"session_policy": "hash"
},
"origin_steering": {
"policy": "random"
},
"origins": [
{
"name": "app-server-1",
"address": "0.0.0.0",
"enabled": true,
"weight": 1,
"header": {
"Host": [
"example.com"
]
}
}
"header": {
"Host": [
"example.com"
]
}
}
],
"notification_email": "someone@example.com",
"check_regions": [
"WEU"
]
}`, string(b))
}`, string(b))
}
fmt.Fprint(w, `{
"success": true,
Expand All @@ -66,26 +69,29 @@ func TestCreateLoadBalancerPool(t *testing.T) {
"enabled": true,
"minimum_origins": 1,
"monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc",
"latitude": 55,
"longitude": -12.5,
"load_shedding": {
"default_percent": 50,
"default_policy": "random",
"session_percent": 10,
"session_policy": "hash"
},
"latitude": 55,
"longitude": -12.5,
"load_shedding": {
"default_percent": 50,
"default_policy": "random",
"session_percent": 10,
"session_policy": "hash"
},
"origin_steering": {
"policy": "random"
},
"origins": [
{
"name": "app-server-1",
"address": "0.0.0.0",
"enabled": true,
"weight": 1,
"header": {
"Host": [
"example.com"
]
}
}
"header": {
"Host": [
"example.com"
]
}
}
],
"notification_email": "someone@example.com",
"check_regions": [
Expand Down Expand Up @@ -119,6 +125,9 @@ func TestCreateLoadBalancerPool(t *testing.T) {
SessionPercent: 10,
SessionPolicy: "hash",
},
OriginSteering: &LoadBalancerOriginSteering{
Policy: "random",
},
Origins: []LoadBalancerOrigin{
{
Name: "app-server-1",
Expand Down Expand Up @@ -148,6 +157,9 @@ func TestCreateLoadBalancerPool(t *testing.T) {
SessionPercent: 10,
SessionPolicy: "hash",
},
OriginSteering: &LoadBalancerOriginSteering{
Policy: "random",
},
Origins: []LoadBalancerOrigin{
{
Name: "app-server-1",
Expand Down Expand Up @@ -191,6 +203,9 @@ func TestListLoadBalancerPools(t *testing.T) {
"name": "primary-dc-1",
"enabled": true,
"monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc",
"origin_steering": {
"policy": "random"
},
"origins": [
{
"name": "app-server-1",
Expand Down Expand Up @@ -223,6 +238,9 @@ func TestListLoadBalancerPools(t *testing.T) {
Name: "primary-dc-1",
Enabled: true,
Monitor: "f1aba936b94213e5b8dca0c0dbf1f9cc",
OriginSteering: &LoadBalancerOriginSteering{
Policy: "random",
},
Origins: []LoadBalancerOrigin{
{
Name: "app-server-1",
Expand Down Expand Up @@ -260,6 +278,9 @@ func TestLoadBalancerPoolDetails(t *testing.T) {
"name": "primary-dc-1",
"enabled": true,
"monitor": "f1aba936b94213e5b8dca0c0dbf1f9cc",
"origin_steering": {
"policy": "random"
},
"origins": [
{
"name": "app-server-1",
Expand All @@ -284,6 +305,9 @@ func TestLoadBalancerPoolDetails(t *testing.T) {
Name: "primary-dc-1",
Enabled: true,
Monitor: "f1aba936b94213e5b8dca0c0dbf1f9cc",
OriginSteering: &LoadBalancerOriginSteering{
Policy: "random",
},
Origins: []LoadBalancerOrigin{
{
Name: "app-server-1",
Expand Down Expand Up @@ -341,17 +365,20 @@ func TestModifyLoadBalancerPool(t *testing.T) {
"description": "Primary data center - Provider XYZZY",
"name": "primary-dc-2",
"enabled": false,
"origin_steering": {
"policy": "random"
},
"origins": [
{
"name": "app-server-2",
"address": "0.0.0.1",
"enabled": false,
"weight": 1,
"header": {
"Host": [
"example.com"
]
}
"header": {
"Host": [
"example.com"
]
}
}
],
"notification_email": "nobody@example.com",
Expand All @@ -371,17 +398,20 @@ func TestModifyLoadBalancerPool(t *testing.T) {
"description": "Primary data center - Provider XYZZY",
"name": "primary-dc-2",
"enabled": false,
"origin_steering": {
"policy": "random"
},
"origins": [
{
"name": "app-server-2",
"address": "0.0.0.1",
"enabled": false,
"weight": 1,
"header": {
"Host": [
"example.com"
]
}
"header": {
"Host": [
"example.com"
]
}
}
],
"notification_email": "nobody@example.com",
Expand All @@ -402,6 +432,9 @@ func TestModifyLoadBalancerPool(t *testing.T) {
Description: "Primary data center - Provider XYZZY",
Name: "primary-dc-2",
Enabled: false,
OriginSteering: &LoadBalancerOriginSteering{
Policy: "random",
},
Origins: []LoadBalancerOrigin{
{
Name: "app-server-2",
Expand All @@ -423,6 +456,9 @@ func TestModifyLoadBalancerPool(t *testing.T) {
Description: "Primary data center - Provider XYZZY",
Name: "primary-dc-2",
Enabled: false,
OriginSteering: &LoadBalancerOriginSteering{
Policy: "random",
},
Origins: []LoadBalancerOrigin{
{
Name: "app-server-2",
Expand Down

0 comments on commit abe1783

Please sign in to comment.