mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-14 00:41:35 +08:00
bugfix: removed stale object in sys log. (#1557)
This commit is contained in:
parent
0300304011
commit
3300f4d19b
@ -93,7 +93,7 @@ local function send_kafka_data(conf, log_message)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- remove stale objects from the memory after timer expires
|
||||
local function remove_stale_objects(premature)
|
||||
if premature then
|
||||
return
|
||||
|
@ -21,6 +21,10 @@ local logger_socket = require("resty.logger.socket")
|
||||
local plugin_name = "syslog"
|
||||
local ngx = ngx
|
||||
local buffers = {}
|
||||
local ipairs = ipairs
|
||||
local stale_timer_running = false;
|
||||
local timer_at = ngx.timer.at
|
||||
local tostring = tostring
|
||||
|
||||
local schema = {
|
||||
type = "object",
|
||||
@ -105,6 +109,22 @@ local function send_syslog_data(conf, log_message)
|
||||
return res, err_msg
|
||||
end
|
||||
|
||||
-- remove stale objects from the memory after timer expires
|
||||
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
|
||||
|
||||
-- log phase in APISIX
|
||||
function _M.log(conf)
|
||||
local entry = log_util.get_full_log(ngx)
|
||||
@ -116,6 +136,12 @@ function _M.log(conf)
|
||||
|
||||
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
|
||||
log_buffer:push(entry)
|
||||
return
|
||||
|
@ -97,7 +97,7 @@ local function send_tcp_data(conf, log_message)
|
||||
return res, err_msg
|
||||
end
|
||||
|
||||
|
||||
-- remove stale objects from the memory after timer expires
|
||||
local function remove_stale_objects(premature)
|
||||
if premature then
|
||||
return
|
||||
|
@ -80,7 +80,7 @@ local function send_udp_data(conf, log_message)
|
||||
return res, err_msg
|
||||
end
|
||||
|
||||
|
||||
-- remove stale objects from the memory after timer expires
|
||||
local function remove_stale_objects(premature)
|
||||
if premature then
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user