-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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: server info #2926
feat: server info #2926
Conversation
doc/plugins/server-info.md
Outdated
## Test Plugin | ||
|
||
```bash | ||
curl http://127.0.0.1:9080/apisix/admin/server_info -s | jq |
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 URI should be /apisix/server_info
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/zh-cn/plugins/server-info.md
Outdated
## 测试插件 | ||
|
||
```bash | ||
curl http://127.0.0.1:9080/apisix/admin/server_info -s | jq |
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.
@membphis FIxed.
apisix/plugins/server-info.lua
Outdated
type = "integer", | ||
description = "server info reporting interval (unit: second)", | ||
default = 60, | ||
minimum = 5, |
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 to specify a maximum value
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.
apisix/plugins/server-info.lua
Outdated
{ | ||
methods = {"GET"}, | ||
uri = "/apisix/server_info", | ||
handler = get_server_info, |
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.
@tokers @membphis
As #2884 (comment), we should not expose the data from the route API.
plugin interceptor
is a hack, a fix! Don't rely on it any more!
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.
That is to say we haven't a way to expose these data in data plane, at least for now.
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.
Yes, except we can expose it via etcd.
apisix/plugins/server-info.lua
Outdated
-- 1. core.timer is not cancalable, timers will be leaked if plugin | ||
-- reloading happens. | ||
-- 2. the background timer in apisix.timers fires per 500 milliseconds, if | ||
-- report_interval is not multiple of 0.5, the real report interval will be |
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 unit of report_interval is second, and it is an integer. Do I miss some cases that an integer is not a multiple of 0.5?
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 forgot to remove the second comment.
But the backend timer is not suitable, we use backend timer without caring the fire period, if we use it here, we have to do some calculations according to the 500 milliseconds, which must be updated once the backend timer fire period changed.
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 have to do some calculations according to the 500 milliseconds, which must be updated once the backend timer fire period changed
We can expose the 0.5
as a constant, and used in this plugin. It would be better than inventing a new cycle.
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.
Well, if we do so, the interval must be a multiple of 0.2, 0.5. I think it should be done in another PR.
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.
Well, if we do so, the interval must be a multiple of 0.2, 0.5. I think it should be done in another PR.
All right, i changed my mind, i will also export the check interval in this PR.
apisix/plugins/server-info.lua
Outdated
end | ||
|
||
local key = "/data_plane/server_info/" .. server_info.id | ||
local ok, err = core.etcd.set(key, data, 180) |
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 think it would be better to let the CP clean up the data. For example, if the DP is just shutdowned for maintain, it would be better to keep the info data in etcd.
BTW, 180
is rather short compared with the 60 second report internal. And the number is undocumented. People will shout at us when they find their data is disappeared.
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 think it would be better to let the CP clean up the data. For example, if the DP is just shutdowned for maintain, it would be better to keep the info data in etcd.
That can be solved by a long TTL.
BTW, 180 is rather short compared with the 60 second report internal. And the number is undocumented. People will shout at us when they find their data is disappeared.
OK, we can add another item like report_ttl
in the plugin_attr.
return | ||
end | ||
|
||
if server_info.etcd_version == "unknown" then |
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.
What if APISIX runs under standalone mode?
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.
Since now server-info plugin only reports the basic info to etcd, when APISIX runs under standalone mode, we don't need to launch the timer.
conf/config-default.yaml
Outdated
@@ -238,6 +238,7 @@ plugins: # plugin list (sorted in alphabetical order) | |||
- uri-blocker | |||
- wolf-rbac | |||
- zipkin | |||
- server-info |
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 disable this plugin by default
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.
What's the reason for disabling this plugin by default? Users are no feeling about the behavior of server-info.
doc/zh-cn/plugins/server-info.md
Outdated
| 名称 | 类型 | 描述 | | ||
|---------|------|-------------| | ||
| up_time | integer | APISIX 服务实例当前的运行时间, 如果对 APSIX | ||
进行热更新操作,该值将被重置;普通的 reload 操作不会影响该值。 | |
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 test case to confirm this
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.
OK.
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.
Added.
apisix/core/utils.lua
Outdated
hostname = ffi_string(buf, ffi.C.strlen(buf)) | ||
|
||
else | ||
log.alert("ffi.C.gethostname() failed") |
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.
make a try:
use io.popen("/bin/hostname")
to fetch the host name
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.
That'd be concise, i will try 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.
Changed.
@tokers CI is broken. You need to fix it: https://github.com/apache/apisix/pull/2926/checks?check_run_id=1509266841#step:11:286
|
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:
Close #2821.
Pre-submission checklist: