[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-16 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367753240
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,83 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "integer", minimum = 0},
+timeout = {type = "integer", minimum = 1, default= 1000} -- timeout in 
milliseconds
+},
+required = {"host", "port"}
+}
+
+
+local _M = {
+version = 0.1,
+priority = 400,
+name = plugin_name,
+schema = schema,
+}
+
+function _M.check_schema(conf)
+
+if not conf.timeout then
+conf.timeout = 3
+end
+
+return core.schema.check(schema, conf)
+end
+
+local function log(premature, conf, log_message)
+if premature then
+return
+end
+
+local sock = udp()
+sock:settimeout(conf.timeout)
+
+local ok, err = sock:setpeername(conf.host, conf.port)
+if not ok then
+core.log.error("Failed to connect to UDP server: host[", conf.host, "] 
port[", conf.port, "] ", err)
+return
+end
+
+ok, err = sock:send(log_message)
+if not ok then
+core.log.error("Failed to send data to UDP server: host[", conf.host, 
"] port[", conf.port, "] ", err)
 
 Review comment:
   You are right, sorry for this.


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-16 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367748401
 
 

 ##
 File path: lua/apisix/plugins/log-util.lua
 ##
 @@ -0,0 +1,62 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+
+local _M = {}
+
+local function get_full_log(ngx)
+
+local ctx = ngx.ctx.api_ctx
+local var = ctx.var
+
+local url = var.scheme .. "://" .. var.host .. ":" .. var.server_port .. 
var.request_uri
+
+local service_name
+local vars = var
+if ctx.matched_route and ctx.matched_route.value then
+service_name = ctx.matched_route.value.desc or
 
 Review comment:
   It should not be `service_name`, it is the description of `route`. 
   We need a better name here.
   
   
https://github.com/apache/incubator-apisix/blob/master/lua/apisix/plugins/prometheus/exporter.lua#L71


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-16 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367747767
 
 

 ##
 File path: lua/apisix/plugins/log-util.lua
 ##
 @@ -0,0 +1,62 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+
+local _M = {}
+
+local function get_full_log(ngx)
+
 
 Review comment:
   Code style: between the function and the code, this blank line is not 
needed, and please fix other similar places.


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-16 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367748970
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,83 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "integer", minimum = 0},
+timeout = {type = "integer", minimum = 1, default= 1000} -- timeout in 
milliseconds
+},
+required = {"host", "port"}
+}
+
+
+local _M = {
+version = 0.1,
+priority = 400,
+name = plugin_name,
+schema = schema,
+}
+
+function _M.check_schema(conf)
+
+if not conf.timeout then
 
 Review comment:
   We should delete this logic because we have specified the default value 
through `schema`.
   
   
https://github.com/apache/incubator-apisix/pull/1070/files#diff-7e79d5b9c98bca193773cd21898e449cR30


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-16 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367748401
 
 

 ##
 File path: lua/apisix/plugins/log-util.lua
 ##
 @@ -0,0 +1,62 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+
+local _M = {}
+
+local function get_full_log(ngx)
+
+local ctx = ngx.ctx.api_ctx
+local var = ctx.var
+
+local url = var.scheme .. "://" .. var.host .. ":" .. var.server_port .. 
var.request_uri
+
+local service_name
+local vars = var
+if ctx.matched_route and ctx.matched_route.value then
+service_name = ctx.matched_route.value.desc or
 
 Review comment:
   that should not be `service_name`, it should be the description of `route`. 
   We need a better name here.
   
   
https://github.com/apache/incubator-apisix/blob/master/lua/apisix/plugins/prometheus/exporter.lua#L71


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-16 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367749246
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,83 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "integer", minimum = 0},
+timeout = {type = "integer", minimum = 1, default= 1000} -- timeout in 
milliseconds
+},
+required = {"host", "port"}
+}
+
+
+local _M = {
+version = 0.1,
+priority = 400,
+name = plugin_name,
+schema = schema,
+}
+
+function _M.check_schema(conf)
+
+if not conf.timeout then
+conf.timeout = 3
+end
+
+return core.schema.check(schema, conf)
+end
+
+local function log(premature, conf, log_message)
+if premature then
+return
+end
+
+local sock = udp()
+sock:settimeout(conf.timeout)
+
+local ok, err = sock:setpeername(conf.host, conf.port)
+if not ok then
+core.log.error("Failed to connect to UDP server: host[", conf.host, "] 
port[", conf.port, "] ", err)
+return
+end
+
+ok, err = sock:send(log_message)
+if not ok then
+core.log.error("Failed to send data to UDP server: host[", conf.host, 
"] port[", conf.port, "] ", err)
 
 Review comment:
   `Failed to send data` to `failed to send data`


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-16 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367749155
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,83 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "integer", minimum = 0},
+timeout = {type = "integer", minimum = 1, default= 1000} -- timeout in 
milliseconds
+},
+required = {"host", "port"}
+}
+
+
+local _M = {
+version = 0.1,
+priority = 400,
+name = plugin_name,
+schema = schema,
+}
+
+function _M.check_schema(conf)
+
+if not conf.timeout then
+conf.timeout = 3
+end
+
+return core.schema.check(schema, conf)
+end
+
+local function log(premature, conf, log_message)
+if premature then
+return
+end
+
+local sock = udp()
+sock:settimeout(conf.timeout)
+
+local ok, err = sock:setpeername(conf.host, conf.port)
+if not ok then
+core.log.error("Failed to connect to UDP server: host[", conf.host, "] 
port[", conf.port, "] ", err)
+return
+end
+
+ok, err = sock:send(log_message)
+if not ok then
+core.log.error("Failed to send data to UDP server: host[", conf.host, 
"] port[", conf.port, "] ", err)
 
 Review comment:
   need to return directly here


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-16 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367731644
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,87 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "number"},
+timeout = {type = "number", minimum = 1} --default is 3 seconds
+},
+required = {"host", "port"}
+}
+
+
+local _M = {
+version = 0.1,
+priority = 400,
+name = plugin_name,
+schema = schema,
+}
+
+function _M.check_schema(conf)
+
+if not conf.timeout then
+conf.timeout = 3
+end
+
+return core.schema.check(schema, conf)
+end
+
+local function log(premature, conf, log_message)
+if premature then
+return
+end
+
+local sock = udp()
+sock:settimeout(conf.timeout)
+local ok, err = sock:setpeername(conf.host, conf.port)
+
+if not ok then
+core.log.error("Failed to connect to UDP server: host[", conf.host, "] 
port[", conf.port, "] ", err)
+return
+end
+
+ok, err = sock:send(log_message)
 
 Review comment:
   You can ignore this message. that is a UDP connection, we do not need to use 
a separator between different log messages.


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-15 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367254876
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,87 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "number"},
+timeout = {type = "number", minimum = 1} --default is 3 seconds
+},
+required = {"host", "port"}
+}
+
+
+local _M = {
+version = 0.1,
+priority = 400,
+name = plugin_name,
+schema = schema,
+}
+
+function _M.check_schema(conf)
+
+if not conf.timeout then
+conf.timeout = 3
+end
+
+return core.schema.check(schema, conf)
+end
+
+local function log(premature, conf, log_message)
+if premature then
+return
+end
+
+local sock = udp()
+sock:settimeout(conf.timeout)
+local ok, err = sock:setpeername(conf.host, conf.port)
+
+if not ok then
+core.log.error("Failed to connect to UDP server: host[", conf.host, "] 
port[", conf.port, "] ", err)
+return
+end
+
+ok, err = sock:send(log_message)
+
 
 Review comment:
   please remove this blank line


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-15 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367255035
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,87 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "number"},
+timeout = {type = "number", minimum = 1} --default is 3 seconds
+},
+required = {"host", "port"}
+}
+
+
+local _M = {
+version = 0.1,
+priority = 400,
+name = plugin_name,
+schema = schema,
+}
+
+function _M.check_schema(conf)
+
+if not conf.timeout then
+conf.timeout = 3
+end
+
+return core.schema.check(schema, conf)
+end
+
+local function log(premature, conf, log_message)
+if premature then
+return
+end
+
+local sock = udp()
+sock:settimeout(conf.timeout)
+local ok, err = sock:setpeername(conf.host, conf.port)
+
+if not ok then
+core.log.error("Failed to connect to UDP server: host[", conf.host, "] 
port[", conf.port, "] ", err)
+return
+end
+
+ok, err = sock:send(log_message)
+
+if not ok then
+core.log.error("Failed to send data to UDP server: host[", conf.host, 
"] port[", conf.port, "] ", err)
+end
+
+ok, err = sock:close()
+
+if not ok then
+core.log.error("Failed to close the UDP connection, host[", conf.host, 
"] port[", conf.port, "] ", err)
+end
+end
+
+
+function _M.log(conf)
+
+return timer_at(0, log, conf, core.json.encode(log_util.get_full_log(ngx)))
+
 
 Review comment:
   ditto


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-15 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367254647
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,87 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "number"},
+timeout = {type = "number", minimum = 1} --default is 3 seconds
 
 Review comment:
   we can specify the default value directly.


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-15 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367254302
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,87 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "number"},
 
 Review comment:
   It should be 'integer', and the value should more than `0`.


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-15 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367254331
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,87 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "number"},
+timeout = {type = "number", minimum = 1} --default is 3 seconds
 
 Review comment:
   ditto


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-15 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367256569
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,87 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "number"},
+timeout = {type = "number", minimum = 1} --default is 3 seconds
+},
+required = {"host", "port"}
+}
+
+
+local _M = {
+version = 0.1,
+priority = 400,
+name = plugin_name,
+schema = schema,
+}
+
+function _M.check_schema(conf)
+
+if not conf.timeout then
+conf.timeout = 3
+end
+
+return core.schema.check(schema, conf)
+end
+
+local function log(premature, conf, log_message)
+if premature then
+return
+end
+
+local sock = udp()
+sock:settimeout(conf.timeout)
+local ok, err = sock:setpeername(conf.host, conf.port)
+
+if not ok then
+core.log.error("Failed to connect to UDP server: host[", conf.host, "] 
port[", conf.port, "] ", err)
+return
+end
+
+ok, err = sock:send(log_message)
 
 Review comment:
   I think we'd better add a tail `\r\n` or `\n` for each log message.


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


[GitHub] [incubator-apisix] membphis commented on a change in pull request #1070: Adding UDP logger plugin

2020-01-15 Thread GitBox
membphis commented on a change in pull request #1070: Adding UDP logger plugin
URL: https://github.com/apache/incubator-apisix/pull/1070#discussion_r367255006
 
 

 ##
 File path: lua/apisix/plugins/udp-logger.lua
 ##
 @@ -0,0 +1,87 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local log_util = require("apisix.plugins.log-util")
+local plugin_name = "udp-logger"
+local ngx = ngx
+
+local timer_at = ngx.timer.at
+local udp = ngx.socket.udp
+
+local schema = {
+type = "object",
+properties = {
+host = {type = "string"},
+port = {type = "number"},
+timeout = {type = "number", minimum = 1} --default is 3 seconds
+},
+required = {"host", "port"}
+}
+
+
+local _M = {
+version = 0.1,
+priority = 400,
+name = plugin_name,
+schema = schema,
+}
+
+function _M.check_schema(conf)
+
+if not conf.timeout then
+conf.timeout = 3
+end
+
+return core.schema.check(schema, conf)
+end
+
+local function log(premature, conf, log_message)
+if premature then
+return
+end
+
+local sock = udp()
+sock:settimeout(conf.timeout)
+local ok, err = sock:setpeername(conf.host, conf.port)
+
+if not ok then
+core.log.error("Failed to connect to UDP server: host[", conf.host, "] 
port[", conf.port, "] ", err)
+return
+end
+
+ok, err = sock:send(log_message)
+
+if not ok then
+core.log.error("Failed to send data to UDP server: host[", conf.host, 
"] port[", conf.port, "] ", err)
+end
+
+ok, err = sock:close()
+
+if not ok then
+core.log.error("Failed to close the UDP connection, host[", conf.host, 
"] port[", conf.port, "] ", err)
+end
+end
+
+
+function _M.log(conf)
+
 
 Review comment:
   delete this blank line


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