-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support plugin for "aliyun" log service #2177
feat: Support plugin for "aliyun" log service #2177
Conversation
…9535/incubator-apisix into feature/support-alicloud-sls * 'feature/support-alicloud-sls' of https://github.com/gy09535/incubator-apisix: doc: fixed typo in `health-check.md` (#2200) bugfix: grpc-transcode plugin converts http/json parameters abnormally (#2139) chore: add string utility for simplicity and correctness (#2181) improve: cache parsed certs and pkeys to LRU cache (#2163) bugfix: serverless plugin not work in header_filter phase (#2148)
|
||
|
||
|
||
=== TEST 4: add plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to verify the response of Alibaba Cloud?
If not, we can mock Alibaba Cloud
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The aliyun log service can not response anything. I can just send it to collector node and then verify it on log service UI, for collector not response anything.I think if the message is send successful with no error log, sending message is success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add a comment in the source code, and mark this plugin is experiment
. we'll remove this after the community confirm this plugin is stable
@gy09535 Apache APISIX already has the syslog plugin, can these two plugins be combined into one? |
For combined into one I think the aliyun has some special config, we should has different plugin to config it and I reference tcp logger plugin to implement it, I think I can refactor tcp logger and sls logger plugin , change the common code into one module, For sys-logger plugin I think some code is duplicate , for example the batch processor has retry the "resty.logger.socket" also has retry etc. so I prefer use cosocket . |
@liuhengloveyou please take a look at this PR |
working on it. |
any update? |
you can rebase your branch first. conflicted |
@gy09535 I think we need to way to confirm this plugin can work fine with aliyun. if we can check this in the test, it should be great. |
change space
change space
apisix/plugins/sls-logger.lua
Outdated
|
||
if not sock then | ||
err_msg = "failed to init the socket" .. soc_err | ||
core.log.error(err_msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should avoid to concat string in Lua land, it'll make the GC busy.
we should use this style:
core.log.error("failed to init the socket", soc_err)
please fix the similar points.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
apisix/plugins/sls-logger.lua
Outdated
return | ||
end | ||
|
||
local rf5424_data = rf5424.encode("SYSLOG", "INFO", ngx.var.host |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in APISIX, we shuold use ctx.var.****
to fetch nginx variable.
here is an example: https://github.com/apache/apisix/blob/master/apisix/plugins/limit-count.lua#L166
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
apisix/plugins/slslog/rfc5424.lua
Outdated
end | ||
|
||
return string_format(rfc5424_format, pri, t, hostname, appname, pid, project, | ||
logstore, access_key_id, access_key_secret, msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think is my format is right, I reference this doc: https://github.com/apache/apisix/blob/master/CODE_STYLE.md#fromHistory
please review |
apisix/plugins/sls-logger.lua
Outdated
ok, err = sock:setkeepalive(120 * 1000, 20) | ||
if not ok then | ||
can_close = true | ||
core.log.warn("failed to set socket keepalive: host[" .. route_conf.host |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad performance, avoid concat string in Lua land.
core.log.warn("xxxx [", conf.host, "] port[", ...)
, please use this way. and please update other similar points
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
apisix/plugins/sls-logger.lua
Outdated
end | ||
|
||
data = data .. entry.data | ||
core.log.info(entry.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need a simple description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
apisix/plugins/sls-logger.lua
Outdated
end | ||
|
||
local rf5424_data = rf5424.encode("SYSLOG", "INFO", ctx.var.host,"apisix", | ||
ngx.var.pid, conf.project, conf.logstore, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use ctx.var.***
instead of ngx.var.***
ctx.var.***
is better performance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix other similar poitns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
apisix/plugins/slslog/rfc5424.lua
Outdated
local string_format = string.format | ||
local rfc5424_timestamp_format = "!%Y-%m-%dT%H:%M:%S.000Z" | ||
local rfc5424_format = "<%d>1 %s %s %s %d - [logservice project=\"%s\" logstore=\"%s\"" .. | ||
" access-key-id=\"%s\" access-key-secret=\"%s\"] %s\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
doc/plugins/sls-logger.md
Outdated
```shell | ||
curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' | ||
{ | ||
"plugins": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the indentation should be 4
spaces here. please update it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
doc/plugins/sls-logger.md
Outdated
|
||
* check log in ali cloud log service | ||
|
||
 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[****]
please set a title, when failed to load the image, it will show the title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
doc/plugins/sls-logger.md
Outdated
```shell | ||
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d value=' | ||
{ | ||
"methods": ["GET"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this useless line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and please update the Chinese doc too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it.
@membphis please check test cases and feature first, we can put code style issues at the end. |
I read the doc and feature before, they are fine. sure about this. |
style fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, except minor doc and style things
apisix/plugins/slslog/rfc5424.lua
Outdated
local LOG_LOCAL7 = 23 -- reserved for local use | ||
|
||
local Facility = { | ||
["KERN"] = LOG_KERN, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code style:
change to KERN = LOG_KERN
, which is clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
doc/plugins/sls-logger.md
Outdated
"access_key_id": "your_access_key_id", | ||
"access_key_secret": "your_access_key_secret", | ||
"timeout": 30000 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
doc/plugins/sls-logger.md
Outdated
"access_key_secret": "your_access_key_secret", | ||
"timeout": 30000 | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
|
||
|
||
|
||
=== TEST 4: add plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add a comment in the source code, and mark this plugin is experiment
. we'll remove this after the community confirm this plugin is stable
Please review CC @moonming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What this PR does / why we need it:
Fix:#2169
Pre-submission checklist: