Skip to content

Commit

Permalink
Add support for load balancing weighted random pools
Browse files Browse the repository at this point in the history
  • Loading branch information
roopa-13 committed Jun 8, 2022
1 parent c49a828 commit bc1704c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
10 changes: 10 additions & 0 deletions load_balancing.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type LoadBalancer struct {
PersistenceTTL int `json:"session_affinity_ttl,omitempty"`
SessionAffinityAttributes *SessionAffinityAttributes `json:"session_affinity_attributes,omitempty"`
Rules []*LoadBalancerRule `json:"rules,omitempty"`
RandomSteering *RandomSteering `json:"random_steering,omitempty"`

// SteeringPolicy controls pool selection logic.
// "off" select pools in DefaultPools order
Expand Down Expand Up @@ -161,6 +162,15 @@ type LoadBalancerRuleOverrides struct {
PoPPools map[string][]string `json:"pop_pools,omitempty"`
RegionPools map[string][]string `json:"region_pools,omitempty"`
CountryPools map[string][]string `json:"country_pools,omitempty"`

RandomSteering *RandomSteering `json:"random_steering,omitempty"`
}

// RandomSteering represents fields used to set pool weights on a load balancer
// with "random" steering policy.
type RandomSteering struct {
DefaultWeight float64 `json:"default_weight,omitempty"`
PoolWeights map[string]float64 `json:"pool_weights,omitempty"`
}

// LoadBalancerRuleOverridesSessionAffinityAttrs mimics SessionAffinityAttributes without the
Expand Down
80 changes: 80 additions & 0 deletions load_balancing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,13 @@ func TestCreateLoadBalancer(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"random_steering": {
"default_weight": 0.2,
"pool_weights": {
"9290f38c5d07c2e2f4df57b1f61d4196": 0.6,
"de90f38ced07c2e2f4df50b1f61d4194": 0.4
}
},
"rules": [
{
"name": "example rule",
Expand Down Expand Up @@ -1002,6 +1009,13 @@ func TestCreateLoadBalancer(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"random_steering": {
"default_weight": 0.2,
"pool_weights": {
"9290f38c5d07c2e2f4df57b1f61d4196": 0.6,
"de90f38ced07c2e2f4df50b1f61d4194": 0.4
}
},
"rules": [
{
"name": "example rule",
Expand Down Expand Up @@ -1072,6 +1086,13 @@ func TestCreateLoadBalancer(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194",
},
},
RandomSteering: &RandomSteering{
DefaultWeight: 0.2,
PoolWeights: map[string]float64{
"9290f38c5d07c2e2f4df57b1f61d4196": 0.6,
"de90f38ced07c2e2f4df50b1f61d4194": 0.4,
},
},
Rules: []*LoadBalancerRule{
{
Name: "example rule",
Expand Down Expand Up @@ -1133,6 +1154,13 @@ func TestCreateLoadBalancer(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194",
},
},
RandomSteering: &RandomSteering{
DefaultWeight: 0.2,
PoolWeights: map[string]float64{
"9290f38c5d07c2e2f4df57b1f61d4196": 0.6,
"de90f38ced07c2e2f4df50b1f61d4194": 0.4,
},
},
Rules: []*LoadBalancerRule{
{
Name: "example rule",
Expand Down Expand Up @@ -1216,6 +1244,13 @@ func TestListLoadBalancers(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"random_steering": {
"default_weight": 0.2,
"pool_weights": {
"9290f38c5d07c2e2f4df57b1f61d4196": 0.6,
"de90f38ced07c2e2f4df50b1f61d4194": 0.4
}
},
"proxied": true
}
],
Expand Down Expand Up @@ -1275,6 +1310,13 @@ func TestListLoadBalancers(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194",
},
},
RandomSteering: &RandomSteering{
DefaultWeight: 0.2,
PoolWeights: map[string]float64{
"9290f38c5d07c2e2f4df57b1f61d4196": 0.6,
"de90f38ced07c2e2f4df50b1f61d4194": 0.4,
},
},
Proxied: true,
},
}
Expand Down Expand Up @@ -1339,6 +1381,13 @@ func TestLoadBalancerDetails(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"random_steering": {
"default_weight": 0.2,
"pool_weights": {
"9290f38c5d07c2e2f4df57b1f61d4196": 0.6,
"de90f38ced07c2e2f4df50b1f61d4194": 0.4
}
},
"proxied": true
}
}`)
Expand Down Expand Up @@ -1390,6 +1439,13 @@ func TestLoadBalancerDetails(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194",
},
},
RandomSteering: &RandomSteering{
DefaultWeight: 0.2,
PoolWeights: map[string]float64{
"9290f38c5d07c2e2f4df57b1f61d4196": 0.6,
"de90f38ced07c2e2f4df50b1f61d4194": 0.4,
},
},
Proxied: true,
}

Expand Down Expand Up @@ -1470,6 +1526,12 @@ func TestModifyLoadBalancer(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"random_steering": {
"default_weight": 0.5,
"pool_weights": {
"9290f38c5d07c2e2f4df57b1f61d4196": 0.2
}
},
"proxied": true,
"session_affinity": "none",
"session_affinity_attributes": {
Expand Down Expand Up @@ -1521,6 +1583,12 @@ func TestModifyLoadBalancer(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194"
]
},
"random_steering": {
"default_weight": 0.5,
"pool_weights": {
"9290f38c5d07c2e2f4df57b1f61d4196": 0.2
}
},
"proxied": true,
"session_affinity": "none",
"session_affinity_attributes": {
Expand Down Expand Up @@ -1573,6 +1641,12 @@ func TestModifyLoadBalancer(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194",
},
},
RandomSteering: &RandomSteering{
DefaultWeight: 0.5,
PoolWeights: map[string]float64{
"9290f38c5d07c2e2f4df57b1f61d4196": 0.2,
},
},
Proxied: true,
Persistence: "none",
SessionAffinityAttributes: &SessionAffinityAttributes{
Expand Down Expand Up @@ -1617,6 +1691,12 @@ func TestModifyLoadBalancer(t *testing.T) {
"00920f38ce07c2e2f4df50b1f61d4194",
},
},
RandomSteering: &RandomSteering{
DefaultWeight: 0.5,
PoolWeights: map[string]float64{
"9290f38c5d07c2e2f4df57b1f61d4196": 0.2,
},
},
Proxied: true,
Persistence: "none",
SessionAffinityAttributes: &SessionAffinityAttributes{
Expand Down

0 comments on commit bc1704c

Please sign in to comment.