@@ -32,7 +32,7 @@ var tracer = otel.Tracer("ratelimit")
32
32
33
33
type RateLimitServiceServer interface {
34
34
pb.RateLimitServiceServer
35
- GetCurrentConfig () config.RateLimitConfig
35
+ GetCurrentConfig () ( config.RateLimitConfig , bool )
36
36
}
37
37
38
38
type service struct {
@@ -107,8 +107,7 @@ func checkServiceErr(something bool, msg string) {
107
107
}
108
108
}
109
109
110
- func (this * service ) constructLimitsToCheck (request * pb.RateLimitRequest , ctx context.Context ) ([]* config.RateLimit , []bool ) {
111
- snappedConfig := this .GetCurrentConfig ()
110
+ func (this * service ) constructLimitsToCheck (request * pb.RateLimitRequest , ctx context.Context , snappedConfig config.RateLimitConfig ) ([]* config.RateLimit , []bool ) {
112
111
checkServiceErr (snappedConfig != nil , "no rate limit configuration loaded" )
113
112
114
113
limitsToCheck := make ([]* config.RateLimit , len (request .Descriptors ))
@@ -180,7 +179,8 @@ func (this *service) shouldRateLimitWorker(
180
179
checkServiceErr (request .Domain != "" , "rate limit domain must not be empty" )
181
180
checkServiceErr (len (request .Descriptors ) != 0 , "rate limit descriptor list must not be empty" )
182
181
183
- limitsToCheck , isUnlimited := this .constructLimitsToCheck (request , ctx )
182
+ snappedConfig , globalShadowMode := this .GetCurrentConfig ()
183
+ limitsToCheck , isUnlimited := this .constructLimitsToCheck (request , ctx , snappedConfig )
184
184
185
185
responseDescriptorStatuses := this .cache .DoLimit (ctx , request , limitsToCheck )
186
186
assert .Assert (len (limitsToCheck ) == len (responseDescriptorStatuses ))
@@ -228,7 +228,7 @@ func (this *service) shouldRateLimitWorker(
228
228
}
229
229
230
230
// If there is a global shadow_mode, it should always return OK
231
- if finalCode == pb .RateLimitResponse_OVER_LIMIT && this . globalShadowMode {
231
+ if finalCode == pb .RateLimitResponse_OVER_LIMIT && globalShadowMode {
232
232
finalCode = pb .RateLimitResponse_OK
233
233
this .stats .GlobalShadowMode .Inc ()
234
234
}
@@ -306,10 +306,10 @@ func (this *service) ShouldRateLimit(
306
306
return response , nil
307
307
}
308
308
309
- func (this * service ) GetCurrentConfig () config.RateLimitConfig {
309
+ func (this * service ) GetCurrentConfig () ( config.RateLimitConfig , bool ) {
310
310
this .configLock .RLock ()
311
311
defer this .configLock .RUnlock ()
312
- return this .config
312
+ return this .config , this . globalShadowMode
313
313
}
314
314
315
315
func NewService (runtime loader.IFace , cache limiter.RateLimitCache ,
0 commit comments