]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Various fixes to Clickhouse exporter
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Aug 2018 14:36:12 +0000 (15:36 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 7 Aug 2018 14:36:12 +0000 (15:36 +0100)
lualib/lua_clickhouse.lua
src/plugins/lua/clickhouse.lua

index 37c9ebb7a32e834c403107d299d2e56d438f5e4c..3f3c4de4045ea488f5d9b4ea222919b997f10f9b 100644 (file)
@@ -27,6 +27,15 @@ local function escape_spaces(query)
   return query:gsub('%s', '%%20')
 end
 
+local function ch_number(a)
+  if (a+2^52)-2^52 == a then
+    -- Integer
+    return tostring(math.floor(a))
+  end
+
+  return tostring(a)
+end
+
 local function clickhouse_quote(str)
   if str then
     return str:gsub('[\'\\]', '\\%1'):lower()
@@ -40,8 +49,8 @@ local function array_to_string(ar)
   for i,elt in ipairs(ar) do
     if type(elt) == 'string' then
       ar[i] = '\'' .. clickhouse_quote(elt) .. '\''
-    else
-      ar[i] = tostring(elt)
+    elseif type(elt) == 'number' then
+      ar[i] = ch_number(elt)
     end
   end
 
@@ -54,8 +63,8 @@ local function row_to_tsv(row)
   for i,elt in ipairs(row) do
     if type(elt) == 'table' then
       row[i] = '[' .. array_to_string(elt) .. ']'
-    else
-      row[i] = tostring(elt) -- Assume there are no tabs there
+    elseif type(elt) == 'number' then
+      row[i] = ch_number(elt)
     end
   end
 
index b54c1a2163a96e889bea4c1f6976f23abe27e123..444465814b69363f8a9d0a00e252b853c78bffbb 100644 (file)
@@ -488,6 +488,7 @@ local function clickhouse_collect(task)
   })
 
   local action = task:get_metric_action('default')
+  local digest = task:get_digest()
 
   table.insert(main_rows, {
     today(timestamp),
@@ -552,7 +553,7 @@ local function clickhouse_collect(task)
   if #attachments_fnames > 0 then
     table.insert(attachment_rows, {
       today(timestamp),
-      task:get_digest(),
+      digest,
       attachments_fnames,
       attachments_ctypes,
       attachments_lengths,
@@ -577,7 +578,7 @@ local function clickhouse_collect(task)
   if #urls_tlds > 0 then
     table.insert(urls_rows, {
       today(timestamp),
-      task:get_digest(),
+      digest,
       urls_tlds,
       urls_urls
     })
@@ -595,7 +596,7 @@ local function clickhouse_collect(task)
   if #emails > 0 then
     table.insert(emails_rows, {
       today(timestamp),
-      task:get_digest(),
+      digest,
       emails,
     })
   end
@@ -618,7 +619,7 @@ local function clickhouse_collect(task)
     end
     table.insert(asn_rows, {
       today(timestamp),
-      task:get_digest(),
+      digest,
       asn,
       country,
       ipnet
@@ -639,12 +640,13 @@ local function clickhouse_collect(task)
       if s.options then
         table.insert(options_tab, table.concat(s.options, ','))
       else
-        table.insert(options_tab, "''");
+        table.insert(options_tab, '');
       end
     end
 
     table.insert(symbols_rows, {
       today(timestamp),
+      digest,
       syms_tab,
       scores_tab,
       options_tab