spacewander commented on a change in pull request #4633:
URL: https://github.com/apache/apisix/pull/4633#discussion_r674452676
##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -36,23 +38,40 @@ local lrucache = core.lrucache.new({
local metadata_schema = {
type = "object",
properties = {
- host = schema_def.host_def,
Review comment:
We need to keep the old fields and mark them as deprecated (at least in
the doc), like:
https://github.com/apache/apisix/blob/71bc27cc41cf52ba1a41816311412527ae278045/apisix/plugins/authz-keycloak.lua#L34
##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -94,33 +121,109 @@ local function send_to_server(data)
sock:settimeout(config.timeout * 1000)
- local ok, err = sock:connect(config.host, config.port)
+ local tcp_config = config.tcp
+ local ok, err = sock:connect(tcp_config.host, tcp_config.port)
if not ok then
- return false, "failed to connect the TCP server: host[" .. config.host
- .. "] port[" .. tostring(config.port) .. "] err: " .. err
+ return false, "failed to connect the TCP server: host[" ..
tcp_config.host
+ .. "] port[" .. tostring(tcp_config.port) .. "] err: " .. err
end
- if config.tls then
- ok, err = sock:sslhandshake(false, config.tls_server_name, false)
+ if tcp_config.tls then
+ ok, err = sock:sslhandshake(false, tcp_config.tls_server_name, false)
if not ok then
sock:close()
return false, "failed to perform TLS handshake to TCP server:
host["
- .. config.host .. "] port[" .. tostring(config.port) .. "]
err: " .. err
+ .. tcp_config.host .. "] port[" .. tostring(tcp_config.port)
.. "] err: " .. err
end
end
local bytes, err = sock:send(data)
if not bytes then
sock:close()
- return false, "failed to send data to TCP server: host[" .. config.host
- .. "] port[" .. tostring(config.port) .. "] err: " .. err
+ return false, "failed to send data to TCP server: host[" ..
tcp_config.host
+ .. "] port[" .. tostring(tcp_config.port) .. "] err: " .. err
end
- sock:setkeepalive(config.keepalive * 1000)
+ sock:setkeepalive(tcp_config.keepalive * 1000)
return true
end
+local function send_to_skywalking(log_message)
+ local err_msg
+ local res = true
+ local url_decoded = url.parse(config.skywalking.endpoint_addr)
+ local host = url_decoded.host
+ local port = url_decoded.port
+
+ core.log.info("sending a batch logs to ", config.skywalking.endpoint_addr)
+
+ if ((not port) and url_decoded.scheme == "https") then
+ port = 443
+ elseif not port then
+ port = 80
+ end
+
+ local httpc = http.new()
+ httpc:set_timeout(config.timeout * 1000)
+ local ok, err = httpc:connect(host, port)
+
+ if not ok then
+ return false, "failed to connect to host[" .. host .. "] port["
+ .. tostring(port) .. "] " .. err
+ end
+
+ if url_decoded.scheme == "https" then
+ ok, err = httpc:ssl_handshake(true, host, false)
+ if not ok then
+ return nil, "failed to perform SSL with host[" .. host .. "] "
+ .. "port[" .. tostring(port) .. "] " .. err
+ end
+ end
+
+ local entries = {}
+ for i = 1, #log_message, 2 do
+ local content = {
+ service = config.skywalking.service_name,
+ serviceInstance = config.skywalking.service_instance_name,
+ endpoint = "",
+ body = {
+ text = {
+ text = log_message[i]
+ }
+ }
+ }
+ table.insert(entries, content)
+ end
+
+ local httpc_res, httpc_err = httpc:request({
Review comment:
Why not use `httpc:request_uri` directly?
##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -36,23 +38,40 @@ local lrucache = core.lrucache.new({
local metadata_schema = {
type = "object",
properties = {
- host = schema_def.host_def,
- port = {type = "integer", minimum = 0},
- tls = {type = "boolean", default = false},
- tls_server_name = {type = "string"},
- timeout = {type = "integer", minimum = 1, default = 3},
- keepalive = {type = "integer", minimum = 1, default = 30},
+ type = {type = "string", default = "TCP", enum = {"TCP",
"SKYWALKING"}},
+ tcp = {
+ type = "object",
+ properties = {
+ host = schema_def.host_def,
+ port = {type = "integer", minimum = 0},
+ tls = {type = "boolean", default = false},
+ tls_server_name = {type = "string"},
+ keepalive = {type = "integer", minimum = 1, default = 30},
+ },
+ required = {"host", "port"}
Review comment:
Please don't mix tab with space
##########
File path: apisix/plugins/error-log-logger.lua
##########
@@ -204,4 +316,4 @@ function _M.destroy()
end
-return _M
+return _M
Review comment:
Need newline at the end of file
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]