Skip to content
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

Merged
merged 19 commits into from
Dec 9, 2020
Merged

feat: server info #2926

merged 19 commits into from
Dec 9, 2020

Conversation

tokers
Copy link
Contributor

@tokers tokers commented Dec 2, 2020

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 spacewander, membphis, liuxiran and moonming and removed request for spacewander December 2, 2020 07:28
## Test Plugin

```bash
curl http://127.0.0.1:9080/apisix/admin/server_info -s | jq
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

## 测试插件

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

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@membphis FIxed.

type = "integer",
description = "server info reporting interval (unit: second)",
default = 60,
minimum = 5,
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

{
methods = {"GET"},
uri = "/apisix/server_info",
handler = get_server_info,
Copy link
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
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
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.

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

end

local key = "/data_plane/server_info/" .. server_info.id
local ok, err = core.etcd.set(key, data, 180)
Copy link
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
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.

return
end

if server_info.etcd_version == "unknown" then
Copy link
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
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
Copy link
Contributor Author

tokers commented Dec 6, 2020

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

@@ -238,6 +238,7 @@ plugins: # plugin list (sorted in alphabetical order)
- uri-blocker
- wolf-rbac
- zipkin
- server-info
Copy link
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
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.

| 名称 | 类型 | 描述 |
|---------|------|-------------|
| up_time | integer | APISIX 服务实例当前的运行时间, 如果对 APSIX
进行热更新操作,该值将被重置;普通的 reload 操作不会影响该值。 |
Copy link
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
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
Contributor Author

Choose a reason for hiding this comment

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

Added.

hostname = ffi_string(buf, ffi.C.strlen(buf))

else
log.alert("ffi.C.gethostname() failed")
Copy link
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
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
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
Copy link
Member

membphis commented Dec 7, 2020

@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
doc/plugins/server-info.md Outdated Show resolved Hide resolved
apisix/plugins/server-info.lua Show resolved Hide resolved
apisix/plugins/server-info.lua Outdated Show resolved Hide resolved
apisix/plugins/server-info.lua Show resolved Hide resolved
doc/plugins/server-info.md Outdated Show resolved Hide resolved
Copy link
Member

@membphis membphis left a comment

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