mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-15 01:11:58 +08:00
bugfix: removed stale objects from tcp logger (#1543)
This commit is contained in:
parent
fd626ae7e1
commit
5570e64356
@ -22,6 +22,9 @@ local tostring = tostring
|
|||||||
local buffers = {}
|
local buffers = {}
|
||||||
local ngx = ngx
|
local ngx = ngx
|
||||||
local tcp = ngx.socket.tcp
|
local tcp = ngx.socket.tcp
|
||||||
|
local ipairs = ipairs
|
||||||
|
local stale_timer_running = false;
|
||||||
|
local timer_at = ngx.timer.at
|
||||||
|
|
||||||
local schema = {
|
local schema = {
|
||||||
type = "object",
|
type = "object",
|
||||||
@ -95,6 +98,22 @@ local function send_tcp_data(conf, log_message)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function remove_stale_objects(premature)
|
||||||
|
if premature then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for key, batch in ipairs(buffers) do
|
||||||
|
if #batch.entry_buffer.entries == 0 and #batch.batch_to_process == 0 then
|
||||||
|
core.log.debug("removing batch processor stale object, route id:", tostring(key))
|
||||||
|
buffers[key] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
stale_timer_running = false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function _M.log(conf)
|
function _M.log(conf)
|
||||||
local entry = log_util.get_full_log(ngx)
|
local entry = log_util.get_full_log(ngx)
|
||||||
|
|
||||||
@ -105,6 +124,12 @@ function _M.log(conf)
|
|||||||
|
|
||||||
local log_buffer = buffers[entry.route_id]
|
local log_buffer = buffers[entry.route_id]
|
||||||
|
|
||||||
|
if not stale_timer_running then
|
||||||
|
-- run the timer every 30 mins if any log is present
|
||||||
|
timer_at(1800, remove_stale_objects)
|
||||||
|
stale_timer_running = true
|
||||||
|
end
|
||||||
|
|
||||||
if log_buffer then
|
if log_buffer then
|
||||||
log_buffer:push(entry)
|
log_buffer:push(entry)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user