Skip to content

Commit 8030415

Browse files
committed
Finishing touches
1 parent 8efd962 commit 8030415

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

cmd/glbc/app/clients.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func NewGCEClient() *gce.GCECloud {
9999
// Configure GCE rate limiting
100100
rl, err := ratelimit.NewGCERateLimiter(flags.F.GCERateLimit.Values())
101101
if err != nil {
102-
glog.Errorf("Error in configuring rate limiting: %v", err)
102+
glog.Fatalf("Error configuring rate limiting: %v", err)
103103
}
104104
cloud.SetRateLimiter(rl)
105105
// If this controller is scheduled on a node without compute/rw

pkg/flags/flags.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var (
5959

6060
func init() {
6161
F.NodePortRanges.ports = []string{DefaultNodePortRange}
62-
F.GCERateLimit.specs = []string{}
62+
F.GCERateLimit.specs = []string{"alpha.Operations.Get,qps,10,100", "beta.Operations.Get,qps,10,100", "ga.Operations.Get,qps,10,100"}
6363
}
6464

6565
// Register flags with the command line parser.
@@ -91,7 +91,11 @@ associated Ingress is deleted.`)
9191
`Optional, can be used to rate limit certain GCE API calls. Example usage:
9292
--gce-ratelimit=ga.Addresses.Get,qps,1.5,5
9393
(limit ga.Addresses.Get to maximum of 1.5 qps with a burst of 5).
94-
Use the flag more than once to rate limit more than one call.`)
94+
Use the flag more than once to rate limit more than one call. If you do not
95+
specify this flag, the default is to rate limit Operations.Get for all versions.
96+
If you do specify this flag one or more times, this default will be overwritten.
97+
If you want to still use the default, simply specify it along with your other
98+
values.`)
9599
flag.StringVar(&F.HealthCheckPath, "health-check-path", "/",
96100
`Path used to health-check a backend service. All Services must serve a
97101
200 page on this path. Currently this is only configurable globally.`)
@@ -122,6 +126,7 @@ L7 load balancing. CSV values accepted. Example: -node-port-ranges=80,8080,400-5
122126

123127
type RateLimitSpecs struct {
124128
specs []string
129+
isSet bool
125130
}
126131

127132
// Part of the flag.Value interface.
@@ -131,6 +136,12 @@ func (r *RateLimitSpecs) String() string {
131136

132137
// Set supports the flag being repeated multiple times. Part of the flag.Value interface.
133138
func (r *RateLimitSpecs) Set(value string) error {
139+
// On first Set(), clear the original defaults
140+
// On subsequent Set()'s, append.
141+
if !r.isSet {
142+
r.specs = []string{}
143+
r.isSet = true
144+
}
134145
r.specs = append(r.specs, value)
135146
return nil
136147
}

pkg/ratelimit/ratelimit.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ import (
3131
// GCERateLimiter implements cloud.RateLimiter
3232
type GCERateLimiter struct {
3333
// Map a RateLimitKey to its rate limiter implementation.
34-
rateLimitImpls map[*cloud.RateLimitKey]flowcontrol.RateLimiter
34+
rateLimitImpls map[cloud.RateLimitKey]flowcontrol.RateLimiter
3535
}
3636

3737
// NewGCERateLimiter parses the list of rate limiting specs passed in and
3838
// returns a properly configured cloud.RateLimiter implementation.
3939
// Expected format of specs: {"[version].[service].[operation],[type],[param1],[param2],..", "..."}
4040
func NewGCERateLimiter(specs []string) (*GCERateLimiter, error) {
41-
rateLimitImpls := make(map[*cloud.RateLimitKey]flowcontrol.RateLimiter)
41+
rateLimitImpls := make(map[cloud.RateLimitKey]flowcontrol.RateLimiter)
4242
// Within each specification, split on comma to get the operation,
4343
// rate limiter type, and extra parameters.
4444
for _, spec := range specs {
@@ -91,7 +91,7 @@ func (l *GCERateLimiter) rateLimitImpl(key *cloud.RateLimitKey) flowcontrol.Rate
9191
// Since the passed in key will have the ProjectID field filled in, we need to
9292
// create a copy which does not, so that retreiving the rate limiter implementation
9393
// through the map works as expected.
94-
keyCopy := &cloud.RateLimitKey{
94+
keyCopy := cloud.RateLimitKey{
9595
ProjectID: "",
9696
Operation: key.Operation,
9797
Version: key.Version,
@@ -101,21 +101,23 @@ func (l *GCERateLimiter) rateLimitImpl(key *cloud.RateLimitKey) flowcontrol.Rate
101101
}
102102

103103
// Expected format of param is [version].[service].[operation]
104-
func constructRateLimitKey(param string) (*cloud.RateLimitKey, error) {
104+
func constructRateLimitKey(param string) (cloud.RateLimitKey, error) {
105+
var retVal cloud.RateLimitKey
105106
params := strings.Split(param, ".")
106107
if len(params) != 3 {
107-
return nil, fmt.Errorf("Must specify operation in [version].[service].[operation] format.")
108+
return retVal, fmt.Errorf("Must specify rate limit in [version].[service].[operation] format: %v", param)
108109
}
109110
// TODO(rramkumar): Add another layer of validation here?
110111
version := meta.Version(params[0])
111112
service := params[1]
112113
operation := params[2]
113-
return &cloud.RateLimitKey{
114+
retVal = cloud.RateLimitKey{
114115
ProjectID: "",
115116
Operation: operation,
116117
Version: version,
117118
Service: service,
118-
}, nil
119+
}
120+
return retVal, nil
119121
}
120122

121123
// constructRateLimitImpl parses the slice and returns a flowcontrol.RateLimiter

pkg/ratelimit/ratelimit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestConfigureGCERateLimiting(t *testing.T) {
2525
[]string{"ga.Addresses.Get,qps,1.5,5"},
2626
[]string{"ga.Addresses.List,qps,2,10"},
2727
[]string{"ga.Addresses.Get,qps,1.5,5", "ga.Firewalls.Get,qps,1.5,5"},
28+
[]string{"ga.Operations.Get,qps,10,100"},
2829
}
2930
invalidTestCases := [][]string{
3031
[]string{"gaAddresses.Get,qps,1.5,5"},

0 commit comments

Comments
 (0)