feat: server info#2926
Conversation
| ## Test Plugin | ||
|
|
||
| ```bash | ||
| curl http://127.0.0.1:9080/apisix/admin/server_info -s | jq |
There was a problem hiding this comment.
the URI should be /apisix/server_info
| ## 测试插件 | ||
|
|
||
| ```bash | ||
| curl http://127.0.0.1:9080/apisix/admin/server_info -s | jq |
| type = "integer", | ||
| description = "server info reporting interval (unit: second)", | ||
| default = 60, | ||
| minimum = 5, |
There was a problem hiding this comment.
need to specify a maximum value
| { | ||
| methods = {"GET"}, | ||
| uri = "/apisix/server_info", | ||
| handler = get_server_info, |
There was a problem hiding this comment.
@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.
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.
Yes, except we can expose it via etcd.
| -- 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.
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.
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.
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.
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.
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.
| 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.
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.
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.
What if APISIX runs under standalone mode?
There was a problem hiding this comment.
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.
| - uri-blocker | ||
| - wolf-rbac | ||
| - zipkin | ||
| - server-info |
There was a problem hiding this comment.
we should disable this plugin by default
There was a problem hiding this comment.
What's the reason for disabling this plugin by default? Users are no feeling about the behavior of server-info.
| | 名称 | 类型 | 描述 | | ||
| |---------|------|-------------| | ||
| | up_time | integer | APISIX 服务实例当前的运行时间, 如果对 APSIX | ||
| 进行热更新操作,该值将被重置;普通的 reload 操作不会影响该值。 | |
There was a problem hiding this comment.
need a test case to confirm this
| hostname = ffi_string(buf, ffi.C.strlen(buf)) | ||
|
|
||
| else | ||
| log.alert("ffi.C.gethostname() failed") |
There was a problem hiding this comment.
make a try:
use io.popen("/bin/hostname") to fetch the host name
There was a problem hiding this comment.
That'd be concise, i will try it.
|
@tokers CI is broken. You need to fix it: |
What this PR does / why we need it:
Close #2821.
Pre-submission checklist: