You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/05/07 04:24:44 UTC
[incubator-apisix] branch master updated: bugfix: removing stale
objects from udp logger (#1544)
This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new a328fcc bugfix: removing stale objects from udp logger (#1544)
a328fcc is described below
commit a328fcce80ac6d45a5a135818672167971a78db0
Author: Nirojan Selvanathan <ss...@gmail.com>
AuthorDate: Thu May 7 06:24:37 2020 +0200
bugfix: removing stale objects from udp logger (#1544)
---
apisix/plugins/udp-logger.lua | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/apisix/plugins/udp-logger.lua b/apisix/plugins/udp-logger.lua
index b1b565f..957e732 100644
--- a/apisix/plugins/udp-logger.lua
+++ b/apisix/plugins/udp-logger.lua
@@ -22,6 +22,9 @@ local tostring = tostring
local buffers = {}
local ngx = ngx
local udp = ngx.socket.udp
+local ipairs = ipairs
+local stale_timer_running = false;
+local timer_at = ngx.timer.at
local schema = {
type = "object",
@@ -78,6 +81,22 @@ local function send_udp_data(conf, log_message)
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)
local entry = log_util.get_full_log(ngx)
@@ -88,6 +107,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