Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autoradio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
autoradio
Commits
ee4847fd
Commit
ee4847fd
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
minor cleanups to lb spec syntax
parent
7e02e304
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/redirectord/redirectord.go
+1
-1
1 addition, 1 deletion
cmd/redirectord/redirectord.go
fe/loadbalancing.go
+21
-7
21 additions, 7 deletions
fe/loadbalancing.go
fe/loadbalancing_test.go
+4
-4
4 additions, 4 deletions
fe/loadbalancing_test.go
with
26 additions
and
12 deletions
cmd/redirectord/redirectord.go
+
1
−
1
View file @
ee4847fd
...
...
@@ -18,7 +18,7 @@ var (
httpPort
=
flag
.
Int
(
"http-port"
,
80
,
"HTTP port"
)
staticDir
=
flag
.
String
(
"static-dir"
,
"/usr/share/autoradio/htdocs/static"
,
"Static content directory"
)
templateDir
=
flag
.
String
(
"template-dir"
,
"/usr/share/autoradio/htdocs/templates"
,
"HTML templates directory"
)
lbPolicy
=
flag
.
String
(
"lb-policy"
,
"
weighted"
,
"Load balancing policy (weighted, leastloaded
)"
)
lbPolicy
=
flag
.
String
(
"lb-policy"
,
"
listeners_available,listeners_score,weighted"
,
"Load balancing rules specification (see godoc documentation for details
)"
)
// Default DNS TTL (seconds).
dnsTtl
=
5
...
...
This diff is collapsed.
Click to expand it.
fe/loadbalancing.go
+
21
−
7
View file @
ee4847fd
package
fe
import
(
"errors"
"fmt"
"net"
"strings"
...
...
@@ -108,32 +109,45 @@ func (l *autoradioLoadBalancer) Choose(ctx lbv2.RequestContext) *autoradio.NodeS
return
result
.
(
*
lbNode
)
.
NodeStatus
}
// Parse a string that specifies how to build a LoadBalancer. The
// string should consist of a list of comma-separated tokens, each
// identifying a specific filter or policy.
//
// Some filters will always be included in the resulting LoadBalancer
// and do not need to be specified explicitly (icecastActiveFilter and
// ipProtocolFilter, plus an activeNodesFilter at the end).
func
parseLoadBalancerSpec
(
specstr
string
)
(
*
autoradioLoadBalancer
,
error
)
{
lb
:=
lbv2
.
New
()
lb
.
AddFilter
(
newIcecastActiveFilter
())
lb
.
AddFilter
(
newIpProtocolFilter
())
var
policy
lbv2
.
Policy
for
_
,
spec
:=
range
strings
.
Split
(
specstr
,
","
)
{
switch
spec
{
case
"ba"
,
"bw_avail"
,
"bandwidth_available"
:
case
"bandwidth_available"
:
lb
.
AddFilter
(
lbv2
.
NewCapacityAvailableFilter
(
lb
.
GetPredictor
(
UTIL_BANDWIDTH
)))
case
"la"
,
"listeners_available"
:
case
"listeners_available"
:
lb
.
AddFilter
(
lbv2
.
NewCapacityAvailableFilter
(
lb
.
GetPredictor
(
UTIL_LISTENERS
)))
case
"bw"
,
"bandwidth_
weight
"
:
case
"bandwidth_
score
"
:
lb
.
AddFilter
(
lbv2
.
NewCapacityAvailableScorer
(
lb
.
GetPredictor
(
UTIL_BANDWIDTH
)))
case
"lw"
,
"listeners_
weight
"
:
case
"listeners_
score
"
:
lb
.
AddFilter
(
lbv2
.
NewCapacityAvailableScorer
(
lb
.
GetPredictor
(
UTIL_LISTENERS
)))
case
"random"
:
lb
.
SetP
olicy
(
lbv2
.
RandomPolicy
)
p
olicy
=
lbv2
.
RandomPolicy
case
"weighted"
:
lb
.
SetP
olicy
(
lbv2
.
WeightedPolicy
)
p
olicy
=
lbv2
.
WeightedPolicy
case
"best"
:
lb
.
SetP
olicy
(
lbv2
.
HighestScorePolicy
)
p
olicy
=
lbv2
.
HighestScorePolicy
default
:
return
nil
,
fmt
.
Errorf
(
"unknown lb filter spec
\"
%s
\"
"
,
spec
)
}
}
if
policy
==
nil
{
return
nil
,
errors
.
New
(
"no lb policy specified"
)
}
lb
.
SetPolicy
(
policy
)
lb
.
AddFilter
(
lbv2
.
NewActiveNodesFilter
())
return
&
autoradioLoadBalancer
{
lb
},
nil
...
...
This diff is collapsed.
Click to expand it.
fe/loadbalancing_test.go
+
4
−
4
View file @
ee4847fd
...
...
@@ -104,13 +104,13 @@ func TestLoadBalancer_Policies(t *testing.T) {
}
// Weighted should return node1 4 times as often as node2.
runLBTest
(
t
,
nodes
,
nil
,
"b
w
,weighted"
,
1000
,
map
[
string
]
int
{
"node1"
:
200
,
"node2"
:
800
})
runLBTest
(
t
,
nodes
,
nil
,
"b
andwidth_score
,weighted"
,
1000
,
map
[
string
]
int
{
"node1"
:
200
,
"node2"
:
800
})
// The 'random' policy will ignore the weights.
runLBTest
(
t
,
nodes
,
nil
,
"b
w
,random"
,
1000
,
map
[
string
]
int
{
"node1"
:
500
,
"node2"
:
500
})
runLBTest
(
t
,
nodes
,
nil
,
"b
andwidth_score
,random"
,
1000
,
map
[
string
]
int
{
"node1"
:
500
,
"node2"
:
500
})
// The 'best' policy will always return node2.
runLBTest
(
t
,
nodes
,
nil
,
"b
w
,best"
,
1000
,
map
[
string
]
int
{
"node2"
:
1000
})
runLBTest
(
t
,
nodes
,
nil
,
"b
andwidth_score
,best"
,
1000
,
map
[
string
]
int
{
"node2"
:
1000
})
}
func
TestLoadBalancer_PoliciesIgnoreDisabledNodes
(
t
*
testing
.
T
)
{
...
...
@@ -127,7 +127,7 @@ func TestLoadBalancer_PoliciesIgnoreDisabledNodes(t *testing.T) {
},
}
for
_
,
spec
:=
range
[]
string
{
"b
w
_avail,weighted"
,
"b
w
_avail,random"
,
"b
w
_avail,best"
}
{
for
_
,
spec
:=
range
[]
string
{
"b
andwidth
_avail
able
,weighted"
,
"b
andwidth
_avail
able
,random"
,
"b
andwidth
_avail
able
,best"
}
{
runLBTest
(
t
,
nodes
,
nil
,
spec
,
1000
,
map
[
string
]
int
{
"node1"
:
1000
})
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment