rate limit: fix initialize defaults (#10536)

This commit is contained in:
Aleksandr Bezobchuk 2020-12-14 14:55:52 -05:00 committed by GitHub
parent 058532406b
commit 3bce568535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

4
changelog/10536.txt Normal file
View File

@ -0,0 +1,4 @@
```release-note:bug
core: Fix rate limit resource quota migration from 1.5.x to 1.6.x by ensuring `purgeInterval` and
`staleAge` are set appropriately.
```

View File

@ -138,6 +138,17 @@ func (rlq *RateLimitQuota) initialize(logger log.Logger, ms *metricsutil.Cluster
rlq.ID = id
}
// Set purgeInterval if coming from a previous version where purgeInterval was
// not defined.
if rlq.purgeInterval == 0 {
rlq.purgeInterval = DefaultRateLimitPurgeInterval
}
// Set staleAge if coming from a previous version where staleAge was not defined.
if rlq.staleAge == 0 {
rlq.staleAge = DefaultRateLimitStaleAge
}
rlStore, err := memorystore.New(&memorystore.Config{
Tokens: uint64(math.Round(rlq.Rate)), // allow 'rlq.Rate' number of requests per 'Interval'
Interval: rlq.Interval, // time interval in which to enforce rate limiting