feat: implement error-log-logger plug-in#2592
Conversation
error-log-logger plug-in
|
|
||
| if not sock then | ||
| err_msg = "failed to init the socket " .. soc_err | ||
| return res, err_msg |
There was a problem hiding this comment.
style: return false, "failed to init the socket " .. soc_err, it is simpler
| if not ok then | ||
| err_msg = "failed to connect the TCP server: host[" .. config.host | ||
| .. "] port[" .. tostring(config.port) .. "] err: " .. err | ||
| return res, err_msg |
|
|
||
|
|
||
| local function send_to_server(data) | ||
| local res = false |
There was a problem hiding this comment.
it seems useless, can we delete it?
| sock:close() | ||
| err_msg = "failed to send data to TCP server: host[" .. config.host | ||
| .. "] port[" .. tostring(config.port) .. "] err: " .. err | ||
| return res, err_msg |
|
|
||
|
|
||
| local function process() | ||
| if not loaded_flag then |
|
|
||
| local function process() | ||
| if not loaded_flag then | ||
| local code, body = plugin_metadata.get(plugin_name) |
There was a problem hiding this comment.
this way is wrong, please take a look at: https://github.com/apache/apisix/blob/master/apisix/plugins/http-logger.lua#L166
|
|
||
| local log_buffer = buffers[id] | ||
| if log_buffer then | ||
| for i = 1, #entries do |
There was a problem hiding this comment.
for i,v in ipairs(table_name) do this style is better for this case
| end | ||
|
|
||
| buffers[id] = log_buffer | ||
| for i = 1, #entries do |
| local config = { | ||
| } |
There was a problem hiding this comment.
I think this local _M = {} format will look better, what do you think?
error-log-logger plug-inerror-log-logger plug-in
error-log-logger plug-inerror-log-logger plug-in
error-log-logger plug-inerror-log-logger plug-in
|
@membphis please review. |
5360ec3 to
7285c3a
Compare
|
|
||
| ```yaml | ||
| plugins: # plugin list | ||
| - error-log-logger |
There was a problem hiding this comment.
plugins: # plugin list
... ...
- request-id
- hmac-auth
- api-breaker
- error-log-logger # enable plugin `error-log-logger`| timeout = {type = "integer", minimum = 1, default = 3}, | ||
| keepalive = {type = "integer", minimum = 1, default = 30}, | ||
| name = {type = "string", default = plugin_name}, | ||
| level = {type = "string", default = "WARN"}, |
There was a problem hiding this comment.
Need to validate with enum, like this: enum = {"GET", "POST", "PUT", "DELETE", "PATCH",
80c2b13 to
028a454
Compare
|
@membphis @spacewander please review again, thx. |
| end | ||
|
|
||
| if config.tls then | ||
| ok, err = sock:sslhandshake(true, config.tls_options, false) |
There was a problem hiding this comment.
The name tls_options is bad, in fact it isn't related with any options. Would be better to use tls_sni or tls_server_name.
d1e2d4d to
0cad3ab
Compare
|
@dabue you need to rebase your branch |
0cad3ab to
6eaba11
Compare
|
@membphis @spacewander please review again, thx. |
|
@dabue many thx for your nice job |
What this PR does / why we need it:
add a plugin to collect error log and report to remote TCP server .
fix #2410
you can set the plugin's config in config-default.yaml, likes below:
plugins: # plugin list
and update it links below:
step 1: update the attributes of the plugin
curl http://127.0.0.1:9080//apisix/admin/plugin_metadata/error-log-logger -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"host": "127.0.0.1",
"port": 1999,
"inactive_timeout": 1
}'