commit c92f84d: [Feature] Store Clickhouse data outside of lua alloc
Vsevolod Stakhov
vsevolod at highsecure.ru
Thu Oct 10 10:35:06 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-10-10 11:29:55 +0100
URL: https://github.com/rspamd/rspamd/commit/c92f84d76e32100d6f5e1767a468cf3fe49a5db7 (HEAD -> master)
[Feature] Store Clickhouse data outside of lua alloc
---
lualib/lua_clickhouse.lua | 9 +++++----
src/plugins/lua/clickhouse.lua | 11 ++++++-----
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/lualib/lua_clickhouse.lua b/lualib/lua_clickhouse.lua
index 4a57afd3f..2a75326d4 100644
--- a/lualib/lua_clickhouse.lua
+++ b/lualib/lua_clickhouse.lua
@@ -23,6 +23,7 @@ limitations under the License.
local rspamd_logger = require "rspamd_logger"
local rspamd_http = require "rspamd_http"
local lua_util = require "lua_util"
+local rspamd_text = require "rspamd_text"
local exports = {}
local N = 'clickhouse'
@@ -81,9 +82,11 @@ local function row_to_tsv(row)
end
end
- return table.concat(row, '\t')
+ return rspamd_text.fromtable(row, '\t')
end
+exports.row_to_tsv = row_to_tsv
+
-- Parses JSONEachRow reply from CH
local function parse_clickhouse_response_json_eachrow(params, data)
local ucl = require "ucl"
@@ -373,9 +376,7 @@ exports.insert = function (upstream, settings, params, query, rows,
http_params.user = settings.user
http_params.password = settings.password
http_params.method = 'POST'
- http_params.body = {table.concat(fun.totable(fun.map(function(row)
- return row_to_tsv(row)
- end, rows)), '\n'), '\n'}
+ http_params.body = {rspamd_text.from_table(rows, '\n'), '\n'}
http_params.log_obj = params.task or params.config
if not http_params.url then
diff --git a/src/plugins/lua/clickhouse.lua b/src/plugins/lua/clickhouse.lua
index 1505b51aa..45c555460 100644
--- a/src/plugins/lua/clickhouse.lua
+++ b/src/plugins/lua/clickhouse.lua
@@ -421,12 +421,13 @@ local function clickhouse_send_data(task, ev_base)
end
send_data('generic data', data_rows,
- string.format('INSERT INTO rspamd (%s)', table.concat(fields, ',')))
+ string.format('INSERT INTO rspamd (%s)',
+ table.concat(fields, ',')))
for k,crows in pairs(custom_rows) do
if #crows > 1 then
- send_data('custom data ('..k..')', settings.custom_rules[k].first_row(),
- crows)
+ send_data('custom data ('..k..')', crows,
+ settings.custom_rules[k].first_row())
end
end
end
@@ -823,11 +824,11 @@ local function clickhouse_collect(task)
-- Custom data
for k,rule in pairs(settings.custom_rules) do
if not custom_rows[k] then custom_rows[k] = {} end
- table.insert(custom_rows[k], rule.get_row(task))
+ table.insert(custom_rows[k], lua_clickhouse.row_to_tsv(rule.get_row(task)))
end
nrows = nrows + 1
- table.insert(data_rows, row)
+ data_rows[#data_rows + 1] = lua_clickhouse.row_to_tsv(row)
lua_util.debugm(N, task, "add clickhouse row %s / %s", nrows, settings.limit)
if nrows >= settings['limit'] then
More information about the Commits
mailing list