Skip to content

Commit cedce8b

Browse files
committed
init rate limit
Signed-off-by: roc <[email protected]>
1 parent 0063223 commit cedce8b

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

charts/tke-extend-network-controller/templates/deployment.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ spec:
6262
value: "{{ .Values.concurrency.podController }}"
6363
- name: WORKER_NODE_CONTROLLER
6464
value: "{{ .Values.concurrency.nodeController }}"
65+
{{- with .Values.apiRateLimit.DescribeLoadBalancers }}
66+
- name: API_RATELIMIT_DESCRIBE_LOAD_BALANCERS
67+
value: "{{ . }}"
68+
{{- end }}
69+
{{- with .Values.apiRateLimit.CreateListener }}
70+
- name: API_RATELIMIT_CREATE_LISTENER
71+
value: "{{ . }}"
72+
{{- end }}
73+
{{- with .Values.apiRateLimit.DescribeListeners }}
74+
- name: API_RATELIMIT_DESCRIBE_LISTENERS
75+
value: "{{ . }}"
76+
{{- end }}
77+
{{- with .Values.apiRateLimit.DeleteLoadBalancerListeners }}
78+
- name: API_RATELIMIT_DELETE_LOAD_BALANCER_LISTENERS
79+
value: "{{ . }}"
80+
{{- end }}
81+
{{- with .Values.apiRateLimit.BatchRegisterTargets }}
82+
- name: API_RATELIMIT_BATCH_REGISTER_TARGETS
83+
value: "{{ . }}"
84+
{{- end }}
85+
{{- with .Values.apiRateLimit.DescribeTargets }}
86+
- name: API_RATELIMIT_DESCRIBE_TARGETS
87+
value: "{{ . }}"
88+
{{- end }}
89+
{{- with .Values.apiRateLimit.BatchDeregisterTargets }}
90+
- name: API_RATELIMIT_BATCH_DEREGISTER_TARGETS
91+
value: "{{ . }}"
92+
{{- end }}
6593
envFrom:
6694
- secretRef:
6795
name: {{ include "tke-extend-network-controller.fullname" . }}-env

charts/tke-extend-network-controller/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ concurrency:
2828
clbPortPoolController: 10
2929
dedicatedClbServiceController: 1
3030

31+
# -- Precisely control the frequency limit of cloud API calls to avoid frequent over-limits
32+
# in large-scale scenarios, resulting in excessive retries and reduced scaling speed.
33+
# apiRateLimit:
34+
# DescribeLoadBalancers: 20
35+
# CreateListener: 20
36+
# DescribeListeners: 20
37+
# DeleteLoadBalancerListeners: 20
38+
# BatchRegisterTargets: 20
39+
# DescribeTargets: 20
40+
# BatchDeregisterTargets: 20
41+
3142
# -- Logging otpions of the controller
3243
log:
3344
# -- Log level of the controller, be one of 'debug', 'info', 'error', or any integer value > 0 which corresponds to custom debug levels of increasing verbosity

pkg/clb/rate-limit.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
package clb
22

3-
import "golang.org/x/time/rate"
3+
import (
4+
"os"
5+
"strconv"
6+
7+
"golang.org/x/time/rate"
8+
)
49

510
var limiter map[string]*rate.Limiter = make(map[string]*rate.Limiter)
611

7-
func SetRateLimit(limits map[string]int) {
8-
for apiName, limit := range limits {
9-
limit := rate.NewLimiter(rate.Limit(limit), 1)
10-
limiter[apiName] = limit
12+
var envMap = map[string]string{
13+
"API_RATELIMIT_DESCRIBE_LOAD_BALANCERS": "DescribeLoadBalancers",
14+
"API_RATELIMIT_CREATE_LISTENER": "CreateListener",
15+
"API_RATELIMIT_DESCRIBE_LISTENERS": "DescribeListeners",
16+
"API_RATELIMIT_DELETE_LOAD_BALANCER_LISTENERS": "DeleteLoadBalancerListeners",
17+
"API_RATELIMIT_BATCH_REGISTER_TARGETS": "BatchRegisterTargets",
18+
"API_RATELIMIT_DESCRIBE_TARGETS": "DescribeTargets",
19+
"API_RATELIMIT_BATCH_DEREGISTER_TARGETS": "BatchDeregisterTargets",
20+
}
21+
22+
func init() {
23+
for envName, apiName := range envMap {
24+
v := os.Getenv(envName)
25+
if v != "" {
26+
if vv, err := strconv.Atoi(v); err == nil {
27+
limiter[apiName] = rate.NewLimiter(rate.Limit(vv), 1)
28+
clbLog.Info("clb api rate limit", "api", apiName, "limit", vv)
29+
}
30+
}
1131
}
1232
}

0 commit comments

Comments
 (0)