Merge pull request #5749 from Bo0km4n/feat-configurable-max-batch-size

[Fix/metrics] Be configurable max batch size of metrics
This commit is contained in:
Kubernetes Prow Robot 2020-06-22 22:07:40 -07:00 committed by GitHub
commit 803a76cf8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 2 deletions

View file

@ -70,7 +70,14 @@ local function flush(premature)
send(payload)
end
function _M.init_worker()
local function set_metrics_max_batch_size(max_batch_size)
if max_batch_size > 10000 then
MAX_BATCH_SIZE = max_batch_size
end
end
function _M.init_worker(max_batch_size)
set_metrics_max_batch_size(max_batch_size)
local _, err = ngx.timer.every(FLUSH_INTERVAL, flush)
if err then
ngx.log(ngx.ERR, string.format("error when setting up timer.every: %s", tostring(err)))
@ -89,6 +96,7 @@ end
setmetatable(_M, {__index = {
flush = flush,
set_metrics_max_batch_size = set_metrics_max_batch_size,
get_metrics_batch = function() return metrics_batch end,
}})

View file

@ -29,6 +29,18 @@ describe("Monitor", function()
package.loaded["monitor"] = nil
end)
it("extended batch size", function()
mock_ngx({ var = {} })
local monitor = require("monitor")
monitor.set_metrics_max_batch_size(20000)
for i = 1,20000,1 do
monitor.call()
end
assert.equal(20000, #monitor.get_metrics_batch())
end)
it("batches metrics", function()
mock_ngx({ var = {} })
local monitor = require("monitor")

View file

@ -111,7 +111,7 @@ http {
lua_ingress.init_worker()
balancer.init_worker()
{{ if $all.EnableMetrics }}
monitor.init_worker()
monitor.init_worker({{ $all.MonitorMaxBatchSize }})
{{ end }}
plugins.run()