-
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: add control api for plugin server-info #3088
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,9 @@ Here is the supported API: | |
Introduced since `v2.2`. | ||
|
||
Return the jsonschema used by this APISIX instance. | ||
|
||
### GET /v1/server_info | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to put this to plugin's own section. So that the API in this page is builtin and will be provided whether you use the plugin or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
||
Introduced since `v2.2`. | ||
|
||
Return the server info generated by plugin [server-info](plugins/server-info.md). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,54 @@ integral | |
[error] | ||
--- error_log | ||
timer created to report server info, interval: 60 | ||
|
||
|
||
|
||
=== TEST 3: get server_info from plugin control API | ||
--- yaml_config | ||
apisix: | ||
id: 123456 | ||
enable_control: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This configuration may confuses beginner, because the control server in the test is hardcoded in APISIX.pm, instead of generating from config.yaml. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
control: | ||
port: 1984 | ||
plugins: | ||
- server-info | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local json_decode = require("apisix.core").json.decode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/api7/test-toolkit we can use this |
||
local t = require("lib.test_admin").test | ||
local code, _, body = t("/v1/server_info") | ||
if code >= 300 then | ||
ngx.status = code | ||
end | ||
|
||
local keys = {} | ||
local value, err = json_decode(body) | ||
if not value then | ||
ngx.say(err) | ||
return | ||
end | ||
for k in pairs(value) do | ||
keys[#keys + 1] = k | ||
end | ||
|
||
table.sort(keys) | ||
for i = 1, #keys do | ||
ngx.say(keys[i], ": ", value[keys[i]]) | ||
end | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body eval | ||
qr{^boot_time: \d+ | ||
etcd_version: [\d\.]+ | ||
hostname: [a-zA-Z\-0-9\.]+ | ||
id: [a-zA-Z\-0-9]+ | ||
last_report_time: \d+ | ||
up_time: \d+ | ||
version: [\d\.]+ | ||
$} | ||
--- no_error_log | ||
[error] |
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.
Look like we need to way to store the
boot_time
in shdict whenetcd
is not used. Otherwise theboot_time
will change when plugin reloads.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's really, i will change 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.
Fixed.