bugfix: removed stale object in sys log. (#1557)

This commit is contained in:
Ayeshmantha Perera 2020-05-11 10:28:24 +02:00 committed by GitHub
parent 0300304011
commit 3300f4d19b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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