@@ -31,6 +31,7 @@ type YamlDescriptor struct {
3131 RateLimit * YamlRateLimit `yaml:"rate_limit"`
3232 Descriptors []YamlDescriptor
3333 ShadowMode bool `yaml:"shadow_mode"`
34+ QuotaMode bool `yaml:"quota_mode"`
3435 DetailedMetric bool `yaml:"detailed_metric"`
3536 ValueToMetric bool `yaml:"value_to_metric"`
3637 ShareThreshold bool `yaml:"share_threshold"`
@@ -70,6 +71,7 @@ var validKeys = map[string]bool{
7071 "requests_per_unit" : true ,
7172 "unlimited" : true ,
7273 "shadow_mode" : true ,
74+ "quota_mode" : true ,
7375 "name" : true ,
7476 "replaces" : true ,
7577 "detailed_metric" : true ,
@@ -84,7 +86,7 @@ var validKeys = map[string]bool{
8486// @param unlimited supplies whether the rate limit is unlimited
8587// @return the new config entry.
8688func NewRateLimit (requestsPerUnit uint32 , unit pb.RateLimitResponse_RateLimit_Unit , rlStats stats.RateLimitStats ,
87- unlimited bool , shadowMode bool , name string , replaces []string , detailedMetric bool ,
89+ unlimited bool , shadowMode bool , quotaMode bool , name string , replaces []string , detailedMetric bool ,
8890) * RateLimit {
8991 return & RateLimit {
9092 FullKey : rlStats .GetKey (),
@@ -96,6 +98,7 @@ func NewRateLimit(requestsPerUnit uint32, unit pb.RateLimitResponse_RateLimit_Un
9698 },
9799 Unlimited : unlimited ,
98100 ShadowMode : shadowMode ,
101+ QuotaMode : quotaMode ,
99102 Name : name ,
100103 Replaces : replaces ,
101104 DetailedMetric : detailedMetric ,
@@ -108,8 +111,8 @@ func (this *rateLimitDescriptor) dump() string {
108111 ret := ""
109112 if this .limit != nil {
110113 ret += fmt .Sprintf (
111- "%s: unit=%s requests_per_unit=%d, shadow_mode: %t\n " , this .limit .FullKey ,
112- this .limit .Limit .Unit .String (), this .limit .Limit .RequestsPerUnit , this .limit .ShadowMode )
114+ "%s: unit=%s requests_per_unit=%d, shadow_mode: %t, quota_mode: %t \n " , this .limit .FullKey ,
115+ this .limit .Limit .Unit .String (), this .limit .Limit .RequestsPerUnit , this .limit .ShadowMode , this . limit . QuotaMode )
113116 }
114117 for _ , descriptor := range this .descriptors {
115118 ret += descriptor .dump ()
@@ -174,12 +177,12 @@ func (this *rateLimitDescriptor) loadDescriptors(config RateLimitConfigToLoad, p
174177
175178 rateLimit = NewRateLimit (
176179 descriptorConfig .RateLimit .RequestsPerUnit , pb .RateLimitResponse_RateLimit_Unit (value ),
177- statsManager .NewStats (newParentKey ), unlimited , descriptorConfig .ShadowMode ,
180+ statsManager .NewStats (newParentKey ), unlimited , descriptorConfig .ShadowMode , descriptorConfig . QuotaMode ,
178181 descriptorConfig .RateLimit .Name , replaces , descriptorConfig .DetailedMetric ,
179182 )
180183 rateLimitDebugString = fmt .Sprintf (
181- " ratelimit={requests_per_unit=%d, unit=%s, unlimited=%t, shadow_mode=%t}" , rateLimit .Limit .RequestsPerUnit ,
182- rateLimit .Limit .Unit .String (), rateLimit .Unlimited , rateLimit .ShadowMode )
184+ " ratelimit={requests_per_unit=%d, unit=%s, unlimited=%t, shadow_mode=%t, quota_mode=%t }" , rateLimit .Limit .RequestsPerUnit ,
185+ rateLimit .Limit .Unit .String (), rateLimit .Unlimited , rateLimit .ShadowMode , rateLimit . QuotaMode )
183186
184187 for _ , replaces := range descriptorConfig .RateLimit .Replaces {
185188 if replaces .Name == "" {
@@ -336,6 +339,7 @@ func (this *rateLimitConfigImpl) GetLimit(
336339 this .statsManager .NewStats (rateLimitKey ),
337340 false ,
338341 false ,
342+ false ,
339343 "" ,
340344 []string {},
341345 false ,
@@ -452,6 +456,7 @@ func (this *rateLimitConfigImpl) GetLimit(
452456 Limit : originalLimit .Limit ,
453457 Unlimited : originalLimit .Unlimited ,
454458 ShadowMode : originalLimit .ShadowMode ,
459+ QuotaMode : originalLimit .QuotaMode ,
455460 Name : originalLimit .Name ,
456461 Replaces : originalLimit .Replaces ,
457462 DetailedMetric : originalLimit .DetailedMetric ,
@@ -481,7 +486,7 @@ func (this *rateLimitConfigImpl) GetLimit(
481486 if rateLimit != nil && rateLimit .DetailedMetric {
482487 // Preserve ShareThresholdKeyPattern when recreating rate limit
483488 originalShareThresholdKeyPattern := rateLimit .ShareThresholdKeyPattern
484- rateLimit = NewRateLimit (rateLimit .Limit .RequestsPerUnit , rateLimit .Limit .Unit , this .statsManager .NewStats (rateLimit .FullKey ), rateLimit .Unlimited , rateLimit .ShadowMode , rateLimit .Name , rateLimit .Replaces , rateLimit .DetailedMetric )
489+ rateLimit = NewRateLimit (rateLimit .Limit .RequestsPerUnit , rateLimit .Limit .Unit , this .statsManager .NewStats (rateLimit .FullKey ), rateLimit .Unlimited , rateLimit .ShadowMode , rateLimit .QuotaMode , rateLimit . Name , rateLimit .Replaces , rateLimit .DetailedMetric )
485490 rateLimit .ShareThresholdKeyPattern = originalShareThresholdKeyPattern
486491 }
487492
@@ -531,7 +536,7 @@ func (this *rateLimitConfigImpl) GetLimit(
531536 if enhancedKey != rateLimit .FullKey {
532537 // Recreate to ensure a clean stats struct, then set to enhanced stats
533538 originalShareThresholdKeyPattern := rateLimit .ShareThresholdKeyPattern
534- rateLimit = NewRateLimit (rateLimit .Limit .RequestsPerUnit , rateLimit .Limit .Unit , this .statsManager .NewStats (enhancedKey ), rateLimit .Unlimited , rateLimit .ShadowMode , rateLimit .Name , rateLimit .Replaces , rateLimit .DetailedMetric )
539+ rateLimit = NewRateLimit (rateLimit .Limit .RequestsPerUnit , rateLimit .Limit .Unit , this .statsManager .NewStats (enhancedKey ), rateLimit .Unlimited , rateLimit .ShadowMode , rateLimit .QuotaMode , rateLimit . Name , rateLimit .Replaces , rateLimit .DetailedMetric )
535540 rateLimit .ShareThresholdKeyPattern = originalShareThresholdKeyPattern
536541 }
537542 }
0 commit comments