From 3bce568535f71abca2c03e8c8c79ffcfa4b19299 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Mon, 14 Dec 2020 14:55:52 -0500 Subject: [PATCH] rate limit: fix initialize defaults (#10536) --- changelog/10536.txt | 4 ++++ vault/quotas/quotas_rate_limit.go | 11 +++++++++++ 2 files changed, 15 insertions(+) create mode 100644 changelog/10536.txt diff --git a/changelog/10536.txt b/changelog/10536.txt new file mode 100644 index 000000000..483b823b2 --- /dev/null +++ b/changelog/10536.txt @@ -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. +``` diff --git a/vault/quotas/quotas_rate_limit.go b/vault/quotas/quotas_rate_limit.go index fc5a49975..1899af6b0 100644 --- a/vault/quotas/quotas_rate_limit.go +++ b/vault/quotas/quotas_rate_limit.go @@ -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