Skip to content

Commit

Permalink
bugfix: removed stale object in sys log. (#1557)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayeshmantha Perera committed May 11, 2020
1 parent 0300304 commit 3300f4d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apisix/plugins/kafka-logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions apisix/plugins/syslog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apisix/plugins/tcp-logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apisix/plugins/udp-logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3300f4d

Please sign in to comment.