Skip to content

Commit f979f63

Browse files
committed
log_ratelimit: allow to completely disable
From now on log_ratelimiter can be completely disabled by setting `vshard.consts.LOG_RATELIMIT_INTERVAL` to 0. It's done for users, who don't want to use ratelimiter at all. Part of #606 NO_DOC=internal
1 parent 60ae7bb commit f979f63

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

test/unit-luatest/log_ratelimit_test.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local t = require('luatest')
22
local server = require('test.luatest_helpers.server')
33
local verror = require('vshard.error')
4+
local vconsts = require('vshard.consts')
45
local vratelimit = require('vshard.log_ratelimit')
56

67
local test_group = t.group('log_ratelimit')
@@ -76,3 +77,24 @@ test_group.test_garbage_collection = function()
7677
collectgarbage()
7778
t.assert_not(vratelimit.internal.limiters[name])
7879
end
80+
81+
test_group.test_disable_ratelimit = function()
82+
local old_interval = vconsts.LOG_RATELIMIT_INTERVAL
83+
vconsts.LOG_RATELIMIT_INTERVAL = 0.1
84+
local limiter = vratelimit.create({name = 'test_disable_ratelimit'})
85+
86+
local err = verror.box(box.error.new(box.error.NO_CONNECTION))
87+
limiter:log_error(err)
88+
t.assert(limiter.map[err.type][err.code])
89+
limiter:log_error(err)
90+
t.assert_equals(limiter.map[err.type][err.code].suppressed, 1)
91+
-- Now limiter is disabled right in the middle of work.
92+
vconsts.LOG_RATELIMIT_INTERVAL = 0
93+
t.helpers.retrying({}, function()
94+
-- Errors are not suppressed, old suppressed entries are flushed.
95+
limiter:log_error(err)
96+
t.assert_not(limiter.map[err.type])
97+
end)
98+
99+
vconsts.LOG_RATELIMIT_INTERVAL = old_interval
100+
end

vshard/log_ratelimit.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ end
110110
local function ratelimit_log_template(log_lvl)
111111
return function (limiter, entry, format, ...)
112112
ratelimit_flush(limiter)
113+
if consts.LOG_RATELIMIT_INTERVAL <= 0 then
114+
-- Ratelimiter is disabled.
115+
log[log_lvl](format, ...)
116+
return
117+
end
113118
local level = 'verbose'
114119
local signed_entry = ratelimit_sign_entry(entry)
115120
if signed_entry.type and signed_entry.code then

0 commit comments

Comments
 (0)