From 0e9e40a60b6a6493b47e6c971e461b783eeffff2 Mon Sep 17 00:00:00 2001 From: Elvin Efendi Date: Fri, 22 Feb 2019 21:38:07 -0500 Subject: [PATCH] use nkeys for counting lua table elements --- rootfs/etc/nginx/lua/monitor.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rootfs/etc/nginx/lua/monitor.lua b/rootfs/etc/nginx/lua/monitor.lua index cefae7335..014113b44 100644 --- a/rootfs/etc/nginx/lua/monitor.lua +++ b/rootfs/etc/nginx/lua/monitor.lua @@ -4,6 +4,7 @@ local assert = assert local new_tab = require "table.new" local clear_tab = require "table.clear" local clone_tab = require "table.clone" +local nkeys = require "table.nkeys" -- if an Nginx worker processes more than (MAX_BATCH_SIZE/FLUSH_INTERVAL) RPS then it will start dropping metrics local MAX_BATCH_SIZE = 10000 @@ -70,7 +71,7 @@ function _M.init_worker() end function _M.call() - local metrics_size = #metrics_batch + local metrics_size = nkeys(metrics_batch) if metrics_size >= MAX_BATCH_SIZE then ngx.log(ngx.WARN, "omitting metrics for the request, current batch is full") return