sshniro commented on a change in pull request #1356: Updating TCP logger to use 
the batch processor util
URL: https://github.com/apache/incubator-apisix/pull/1356#discussion_r399841448
 
 

 ##########
 File path: lua/apisix/plugins/tcp-logger.lua
 ##########
 @@ -48,51 +53,92 @@ function _M.check_schema(conf)
     return core.schema.check(schema, conf)
 end
 
-local function log(premature, conf, log_message)
-    if premature then
-        return
-    end
+local function send_tcp_data(conf, log_message)
+    local err_msg
+    local res = true
+    local sock, soc_err = tcp()
 
-    local sock,err = tcp()
     if not sock then
-        core.log.error("failed to init the socket", err)
-        return
+        return nil, "failed to init the socket" .. soc_err
     end
 
-    sock:settimeout(conf.timeout)
+    sock:settimeout(conf.timeout * 1000)
 
     local ok, err = sock:connect(conf.host, conf.port)
     if not ok then
-        core.log.error("failed to connect to TCP server: host[",
-                conf.host, "] port[", conf.port, "] ", err)
-        return
+        return nil, "failed to connect to TCP server: host[" ..
+            conf.host .. "] port[" .. tostring(conf.port) .. "] err: " .. err
     end
 
     if conf.tls then
         ok, err = sock:sslhandshake(true, conf.tls_options, false)
         if not ok then
-            core.log.error("failed to to perform TLS handshake to TCP server: 
host[",
-                    conf.host, "] port[", conf.port, "] ", err)
-            return
+            return nil, "failed to to perform TLS handshake to TCP server: 
host[" ..
+                conf.host .. "] port[" .. tostring(conf.port) .. "] err: " .. 
err
         end
     end
 
     ok, err = sock:send(log_message)
     if not ok then
-        core.log.error("failed to send data to TCP server: host[",
-                conf.host, "] port[", conf.port, "] ", err)
+        res = false
+        err_msg = "failed to send data to TCP server: host[" ..
+            conf.host .. "] port[" .. tostring(conf.port) .. "] err: " .. err
     end
 
     ok, err = sock:close()
     if not ok then
         core.log.error("failed to close the TCP connection, host[",
-                conf.host, "] port[", conf.port, "] ", err)
+            conf.host, "] port[", conf.port, "] ", err)
     end
+
+    return res, err_msg
 end
 
 
 function _M.log(conf)
-    return timer_at(0, log, conf, core.json.encode(log_util.get_full_log(ngx)))
+    local entry = log_util.get_full_log(ngx)
+
+    if not entry.route_id then
+        core.log.error("failed to obtain the route id for udp logger")
+        return
+    end
+
+    local log_buffer = buffers[entry.route_id]
 
 Review comment:
   Refactored.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to