Skip to content

feat: server info#2926

Merged
membphis merged 19 commits into
apache:masterfrom
tokers:feat/status
Dec 9, 2020
Merged

feat: server info#2926
membphis merged 19 commits into
apache:masterfrom
tokers:feat/status

Conversation

@tokers

@tokers tokers commented Dec 2, 2020

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Close #2821.

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@tokers tokers mentioned this pull request Dec 2, 2020
4 tasks
@juzhiyuan
juzhiyuan requested review from liuxiran, membphis, moonming and spacewander and removed request for spacewander December 2, 2020 07:28
Comment thread doc/plugins/server-info.md Outdated
## Test Plugin

```bash
curl http://127.0.0.1:9080/apisix/admin/server_info -s | jq

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 URI should be /apisix/server_info

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.

Comment thread doc/zh-cn/plugins/server-info.md Outdated
## 测试插件

```bash
curl http://127.0.0.1:9080/apisix/admin/server_info -s | jq

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

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.

@membphis FIxed.

Comment thread apisix/plugins/server-info.lua Outdated
type = "integer",
description = "server info reporting interval (unit: second)",
default = 60,
minimum = 5,

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 specify a maximum value

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.

Comment thread apisix/plugins/server-info.lua Outdated
{
methods = {"GET"},
uri = "/apisix/server_info",
handler = get_server_info,

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.

@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!

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.

That is to say we haven't a way to expose these data in data plane, at least for now.

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.

Yes, except we can expose it via etcd.

Comment thread 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

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 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?

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.

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.

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.

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.

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.

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.

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.

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.

Comment thread 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)

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.

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.

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.

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.

Comment thread apisix/plugins/server-info.lua
return
end

if server_info.etcd_version == "unknown" 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.

What if APISIX runs under standalone mode?

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.

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.

@tokers

tokers commented Dec 6, 2020

Copy link
Copy Markdown
Contributor Author

@membphis @moonming Please take a look when you have time~

Comment thread conf/config-default.yaml Outdated
- uri-blocker
- wolf-rbac
- zipkin
- server-info

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.

we should disable this plugin by default

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.

What's the reason for disabling this plugin by default? Users are no feeling about the behavior of server-info.

Comment thread doc/zh-cn/plugins/server-info.md Outdated
| 名称 | 类型 | 描述 |
|---------|------|-------------|
| up_time | integer | APISIX 服务实例当前的运行时间, 如果对 APSIX
进行热更新操作,该值将被重置;普通的 reload 操作不会影响该值。 |

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 a test case to confirm this

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.

OK.

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.

Added.

Comment thread apisix/core/utils.lua Outdated
hostname = ffi_string(buf, ffi.C.strlen(buf))

else
log.alert("ffi.C.gethostname() failed")

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.

make a try:

use io.popen("/bin/hostname") to fetch the host 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.

That'd be concise, i will try it.

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.

Changed.

@membphis membphis added this to the 2.2 milestone Dec 7, 2020
@membphis

membphis commented Dec 7, 2020

Copy link
Copy Markdown
Member

@tokers CI is broken. You need to fix it:

https://github.com/apache/apisix/pull/2926/checks?check_run_id=1509266841#step:11:286

#   Failed test 'TEST 3: fix: ensure only one timer is running - response_body - response is expected (repeated req 0, req 0)'
#   at /home/runner/work/apisix/apisix/test-nginx/lib/Test/Nginx/Socket.pm line 1589.
#          got: 'done
# not a single rotater run at the same time: 2020-12-07_08-05-09__error.log
# '
#     expected: 'done
# '
# Looks like you failed 1 test of 12.
t/plugin/log-rotate.t ..................... 

@membphis membphis added the enhancement New feature or request label Dec 7, 2020
Comment thread doc/plugins/server-info.md Outdated
Comment thread apisix/plugins/server-info.lua
Comment thread apisix/plugins/server-info.lua Outdated
Comment thread apisix/plugins/server-info.lua
Comment thread doc/plugins/server-info.md 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
membphis merged commit 7855d9e into apache:master Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement status API

4 participants