Skip to content

feat: implement error-log-logger plug-in#2592

Merged
spacewander merged 11 commits into
apache:masterfrom
dabue:error_log_plugin
Nov 30, 2020
Merged

feat: implement error-log-logger plug-in#2592
spacewander merged 11 commits into
apache:masterfrom
dabue:error_log_plugin

Conversation

@dabue

@dabue dabue commented Nov 1, 2020

Copy link
Copy Markdown
Contributor

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

  • error-log-logger

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
}'

@membphis membphis changed the title feat: add error-log-logger plug-in feat: implement error-log-logger plug-in Nov 1, 2020
Comment thread apisix/plugins/error-log-logger.lua Outdated

if not sock then
err_msg = "failed to init the socket " .. soc_err
return res, err_msg

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: return false, "failed to init the socket " .. soc_err, it is simpler

Comment thread apisix/plugins/error-log-logger.lua Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread apisix/plugins/error-log-logger.lua Outdated


local function send_to_server(data)
local res = false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems useless, can we delete it?

Comment thread apisix/plugins/error-log-logger.lua Outdated
sock:close()
err_msg = "failed to send data to TCP server: host[" .. config.host
.. "] port[" .. tostring(config.port) .. "] err: " .. err
return res, err_msg

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread apisix/plugins/error-log-logger.lua Outdated


local function process()
if not loaded_flag then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loaded is enough

Comment thread apisix/plugins/error-log-logger.lua Outdated

local function process()
if not loaded_flag then
local code, body = plugin_metadata.get(plugin_name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread apisix/plugins/error-log-logger.lua Outdated

local log_buffer = buffers[id]
if log_buffer then
for i = 1, #entries do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for i,v in ipairs(table_name) do this style is better for this case

Comment thread apisix/plugins/error-log-logger.lua Outdated
end

buffers[id] = log_buffer
for i = 1, #entries do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread apisix/plugins/error-log-logger.lua
Comment thread apisix/plugins/error-log-logger.lua Outdated
Comment on lines +67 to +68
local config = {
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this local _M = {} format will look better, what do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it

@dabue dabue changed the title feat: implement error-log-logger plug-in [WIP]feat: implement error-log-logger plug-in Nov 6, 2020
@dabue dabue changed the title [WIP]feat: implement error-log-logger plug-in [wip]feat: implement error-log-logger plug-in Nov 6, 2020
@dabue dabue changed the title [wip]feat: implement error-log-logger plug-in feat: implement error-log-logger plug-in Nov 7, 2020
@dabue

dabue commented Nov 8, 2020

Copy link
Copy Markdown
Contributor Author

@membphis please review.

@membphis

membphis commented Nov 8, 2020

Copy link
Copy Markdown
Member

@dabue we can merge this PR after #2596 merged.

I think this plugin depends on this PR.

@dabue

dabue commented Nov 8, 2020

Copy link
Copy Markdown
Contributor Author

@membphis agree it. After #2596 merged, I can use the backgroud timer to update this pr.

@dabue

dabue commented Nov 9, 2020

Copy link
Copy Markdown
Contributor Author

@membphis this pr has been updated after #2596 and used the new timer, please have a review.

@membphis

Copy link
Copy Markdown
Member

@membphis this pr has been updated after #2596 and used the new timer, please have a review.

got it, let me take a look ^_^

Comment thread doc/plugins/error-log-logger.md Outdated

```yaml
plugins: # plugin list
- error-log-logger

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugins:                          # plugin list
  ... ...
  - request-id
  - hmac-auth
  - api-breaker
  - error-log-logger              # enable plugin `error-log-logger`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread doc/plugins/error-log-logger.md Outdated
Comment thread doc/plugins/error-log-logger.md Outdated
Comment thread doc/plugins/error-log-logger.md
Comment thread doc/plugins/error-log-logger.md Outdated
Comment thread apisix/cli/ngx_tpl.lua Outdated

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@membphis

Copy link
Copy Markdown
Member

@dabue for the doc thing, we need to update the doc index, like this issue: #2790

We can also do this after this PR merge.

Comment thread apisix/plugins/error-log-logger.lua
Comment thread apisix/plugins/error-log-logger.lua Outdated
Comment thread doc/plugins/error-log-logger.md Outdated
Comment thread apisix/plugins/error-log-logger.lua Outdated
Comment thread apisix/plugins/error-log-logger.lua Outdated
Comment thread apisix/plugins/error-log-logger.lua Outdated
Comment thread doc/plugins/error-log-logger.md Outdated
Comment thread apisix/plugins/error-log-logger.lua Outdated
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"},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to validate with enum, like this: enum = {"GET", "POST", "PUT", "DELETE", "PATCH",

Comment thread apisix/plugins/error-log-logger.lua Outdated
@dabue

dabue commented Nov 28, 2020

Copy link
Copy Markdown
Contributor Author

@membphis @spacewander please review again, thx.

Comment thread .travis/apisix_cli_test.sh.bak Outdated
Comment thread doc/plugins/error-log-logger.md Outdated
Comment thread doc/plugins/error-log-logger.md Outdated
Comment thread apisix/plugins/error-log-logger.lua Outdated
end

if config.tls then
ok, err = sock:sslhandshake(true, config.tls_options, false)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

Comment thread doc/plugins/error-log-logger.md Outdated
@membphis

Copy link
Copy Markdown
Member

@dabue you need to rebase your branch

@dabue

dabue commented Nov 29, 2020

Copy link
Copy Markdown
Contributor Author

@membphis @spacewander please review again, thx.

@spacewander
spacewander merged commit e66dd9a into apache:master Nov 30, 2020
@membphis

Copy link
Copy Markdown
Member

@dabue many thx for your nice job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: plugin error-log-logger, collect error log and report to remote server by cosocket

4 participants