Merge pull request #3803 from ElvinEfendi/use-table-nkeys

use nkeys for counting lua table elements
This commit is contained in:
Kubernetes Prow Robot 2019-05-27 01:41:51 -07:00 committed by GitHub
commit 24cb0e5d0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ local assert = assert
local new_tab = require "table.new" local new_tab = require "table.new"
local clear_tab = require "table.clear" local clear_tab = require "table.clear"
local clone_tab = require "table.clone" 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 -- if an Nginx worker processes more than (MAX_BATCH_SIZE/FLUSH_INTERVAL) RPS then it will start dropping metrics
local MAX_BATCH_SIZE = 10000 local MAX_BATCH_SIZE = 10000
@ -70,7 +71,7 @@ function _M.init_worker()
end end
function _M.call() function _M.call()
local metrics_size = #metrics_batch local metrics_size = nkeys(metrics_batch)
if metrics_size >= MAX_BATCH_SIZE then if metrics_size >= MAX_BATCH_SIZE then
ngx.log(ngx.WARN, "omitting metrics for the request, current batch is full") ngx.log(ngx.WARN, "omitting metrics for the request, current batch is full")
return return