You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/03/29 19:24:43 UTC

[GitHub] [incubator-apisix] sshniro commented on a change in pull request #1356: Updating TCP logger to use the batch processor util

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_r399841423
 
 

 ##########
 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
 
 Review comment:
   @membphis we cannot return here as we need to close the socket in the following lines.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services