diff --git a/README.md b/README.md index b781c664..3b2b218c 100644 --- a/README.md +++ b/README.md @@ -339,7 +339,6 @@ domain: internal descriptors: - key: ldap rate_limit: - unit: second unlimited: true - key: azure diff --git a/examples/ratelimit/config/example.yaml b/examples/ratelimit/config/example.yaml index 1eb6256f..64bacdf0 100644 --- a/examples/ratelimit/config/example.yaml +++ b/examples/ratelimit/config/example.yaml @@ -29,9 +29,7 @@ descriptors: requests_per_unit: 1 - key: bay rate_limit: - unit: second unlimited: true - key: qux rate_limit: - unit: minute unlimited: true diff --git a/src/config/config_impl.go b/src/config/config_impl.go index a678b111..20d30a6c 100644 --- a/src/config/config_impl.go +++ b/src/config/config_impl.go @@ -115,16 +115,18 @@ func (this *rateLimitDescriptor) loadDescriptors(config RateLimitConfigToLoad, p var rateLimit *RateLimit = nil var rateLimitDebugString string = "" if descriptorConfig.RateLimit != nil { + unlimited := descriptorConfig.RateLimit.Unlimited + value, present := pb.RateLimitResponse_RateLimit_Unit_value[strings.ToUpper(descriptorConfig.RateLimit.Unit)] - if !present || value == int32(pb.RateLimitResponse_RateLimit_UNKNOWN) { + if (!present || value == int32(pb.RateLimitResponse_RateLimit_UNKNOWN)) && !unlimited { panic(newRateLimitConfigError( config, fmt.Sprintf("invalid rate limit unit '%s'", descriptorConfig.RateLimit.Unit))) } rateLimit = NewRateLimit( - descriptorConfig.RateLimit.RequestsPerUnit, pb.RateLimitResponse_RateLimit_Unit(value), statsManager.NewStats(newParentKey), descriptorConfig.RateLimit.Unlimited) + descriptorConfig.RateLimit.RequestsPerUnit, pb.RateLimitResponse_RateLimit_Unit(value), statsManager.NewStats(newParentKey), unlimited) rateLimitDebugString = fmt.Sprintf( " ratelimit={requests_per_unit=%d, unit=%s, unlimited=%t}", rateLimit.Limit.RequestsPerUnit, rateLimit.Limit.Unit.String(), rateLimit.Unlimited) diff --git a/test/config/basic_config.yaml b/test/config/basic_config.yaml index 21c98d82..33772366 100644 --- a/test/config/basic_config.yaml +++ b/test/config/basic_config.yaml @@ -59,5 +59,4 @@ descriptors: - key: key6 rate_limit: - unit: day unlimited: true diff --git a/test/config/config_test.go b/test/config/config_test.go index f63419fb..7bc05be7 100644 --- a/test/config/config_test.go +++ b/test/config/config_test.go @@ -172,7 +172,6 @@ func TestBasicConfig(t *testing.T) { }) rl.Stats.TotalHits.Inc() rl.Stats.WithinLimit.Inc() - assert.Equal(pb.RateLimitResponse_RateLimit_DAY, rl.Limit.Unit) assert.True(rl.Unlimited) assert.EqualValues(1, stats.NewCounter("test-domain.key6.total_hits").Value()) assert.EqualValues(1, stats.NewCounter("test-domain.key6.within_limit").Value())