@@ -45,15 +45,9 @@ type Option func(string, *Limiter) UpdateStatus
45
45
// AddLabelAllowList adds a label into allow list.
46
46
// It means the given label will not be limited
47
47
func AddLabelAllowList () Option {
48
- << << << < HEAD
49
48
return func (label string , l * Limiter ) UpdateStatus {
50
49
l .labelAllowList [label ] = struct {}{}
51
50
return 0
52
- == == == =
53
- return func (label string , c * Controller ) UpdateStatus {
54
- c .labelAllowList [label ] = struct {}{}
55
- return InAllowList
56
- >> >> >> > 604 b0d6d4 (pkg : avoid make channel every time (#9009 ))
57
51
}
58
52
}
59
53
@@ -91,82 +85,32 @@ func updateQPSConfig(l *Limiter, label string, limit float64, burst int) UpdateS
91
85
92
86
// UpdateConcurrencyLimiter creates a concurrency limiter for a given label if it doesn't exist.
93
87
func UpdateConcurrencyLimiter (limit uint64 ) Option {
94
- << << << < HEAD
95
88
return func (label string , l * Limiter ) UpdateStatus {
96
89
if _ , allow := l .labelAllowList [label ]; allow {
97
90
return InAllowList
98
91
}
99
92
return updateConcurrencyConfig (l , label , limit )
100
- == == == =
101
- return func (label string , c * Controller ) UpdateStatus {
102
- if _ , allow := c .labelAllowList [label ]; allow {
103
- return InAllowList
104
- }
105
- lim , loaded := c .limiters .Load (label )
106
- if ! loaded {
107
- lim , _ = c .limiters .LoadOrStore (label , newLimiter ())
108
- }
109
- return lim .(* limiter ).updateConcurrencyConfig (limit )
110
- >> >> >> > 604 b0d6d4 (pkg : avoid make channel every time (#9009 ))
111
93
}
112
94
}
113
95
114
96
// UpdateQPSLimiter creates a QPS limiter for a given label if it doesn't exist.
115
97
func UpdateQPSLimiter (limit float64 , burst int ) Option {
116
- << << << < HEAD
117
98
return func (label string , l * Limiter ) UpdateStatus {
118
99
if _ , allow := l .labelAllowList [label ]; allow {
119
100
return InAllowList
120
101
}
121
102
return updateQPSConfig (l , label , limit , burst )
122
- == == == =
123
- return func (label string , c * Controller ) UpdateStatus {
124
- if _ , allow := c .labelAllowList [label ]; allow {
125
- return InAllowList
126
- }
127
- lim , loaded := c .limiters .Load (label )
128
- if ! loaded {
129
- lim , _ = c .limiters .LoadOrStore (label , newLimiter ())
130
- }
131
- return lim .(* limiter ).updateQPSConfig (limit , burst )
132
- >> >> >> > 604 b0d6d4 (pkg : avoid make channel every time (#9009 ))
133
103
}
134
104
}
135
105
136
106
// UpdateDimensionConfig creates QPS limiter and concurrency limiter for a given label by config if it doesn't exist.
137
107
func UpdateDimensionConfig (cfg * DimensionConfig ) Option {
138
- << << << < HEAD
139
108
return func (label string , l * Limiter ) UpdateStatus {
140
109
if _ , allow := l .labelAllowList [label ]; allow {
141
110
return InAllowList
142
111
}
143
112
status := updateQPSConfig (l , label , cfg .QPS , cfg .QPSBurst )
144
113
status |= updateConcurrencyConfig (l , label , cfg .ConcurrencyLimit )
145
114
return status
146
- == == == =
147
- return func (label string , c * Controller ) UpdateStatus {
148
- if _ , allow := c .labelAllowList [label ]; allow {
149
- return InAllowList
150
- }
151
- lim , loaded := c .limiters .Load (label )
152
- if ! loaded {
153
- lim , _ = c .limiters .LoadOrStore (label , newLimiter ())
154
- }
155
- return lim .(* limiter ).updateDimensionConfig (cfg )
156
- }
157
- }
158
-
159
- // InitLimiter creates empty concurrency limiter for a given label by config if it doesn't exist.
160
- func InitLimiter () Option {
161
- return func (label string , c * Controller ) UpdateStatus {
162
- if _ , allow := c .labelAllowList [label ]; allow {
163
- return InAllowList
164
- }
165
- _ , loaded := c .limiters .Load (label )
166
- if ! loaded {
167
- c .limiters .LoadOrStore (label , newLimiter ())
168
- }
169
- return LimiterNotChanged
170
- >> >> >> > 604 b0d6d4 (pkg : avoid make channel every time (#9009 ))
171
115
}
172
116
}
0 commit comments