2020-12-09 10:07:57 +08:00
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
|
|
|
our $SkipReason;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
if ($ENV{TEST_NGINX_CHECK_LEAK}) {
|
|
|
|
$SkipReason = "unavailable for the hup tests";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$ENV{TEST_NGINX_USE_HUP} = 1;
|
|
|
|
undef $ENV{TEST_NGINX_USE_STAP};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
use Test::Nginx::Socket::Lua $SkipReason ? (skip_all => $SkipReason) : ();
|
|
|
|
use t::APISIX 'no_plan';
|
|
|
|
|
|
|
|
repeat_each(1);
|
|
|
|
no_long_string();
|
|
|
|
no_root_location();
|
|
|
|
no_shuffle();
|
|
|
|
|
|
|
|
run_tests;
|
|
|
|
|
|
|
|
__DATA__
|
|
|
|
|
|
|
|
=== TEST 1: sanity check
|
|
|
|
--- yaml_config
|
|
|
|
apisix:
|
|
|
|
id: 123456
|
|
|
|
plugins:
|
|
|
|
- server-info
|
|
|
|
plugin_attr:
|
|
|
|
server-info:
|
|
|
|
report_interval: 60
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
ngx.sleep(2)
|
|
|
|
local core = require("apisix.core")
|
|
|
|
local key = "/data_plane/server_info/" .. core.id.get()
|
|
|
|
local res, err = core.etcd.get(key)
|
|
|
|
if err ~= nil then
|
|
|
|
ngx.status = 500
|
|
|
|
ngx.say(err)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-12-18 14:46:49 +08:00
|
|
|
local value = res.body.node.value
|
2020-12-28 20:51:56 +08:00
|
|
|
local json = require("toolkit.json")
|
|
|
|
ngx.say(json.encode(value))
|
2020-12-09 10:07:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body eval
|
2020-12-28 20:51:56 +08:00
|
|
|
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\.]+"}$/
|
2020-12-09 10:07:57 +08:00
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
--- error_log
|
|
|
|
timer created to report server info, interval: 60
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 2: verify the data integrity after reloading
|
|
|
|
--- yaml_config
|
|
|
|
apisix:
|
|
|
|
id: 123456
|
|
|
|
plugins:
|
|
|
|
- server-info
|
|
|
|
plugin_attr:
|
|
|
|
server-info:
|
|
|
|
report_interval: 60
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local core = require("apisix.core")
|
|
|
|
local key = "/data_plane/server_info/" .. core.id.get()
|
|
|
|
local res, err = core.etcd.get(key)
|
|
|
|
if err ~= nil then
|
|
|
|
ngx.status = 500
|
|
|
|
ngx.say(err)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-12-18 14:46:49 +08:00
|
|
|
local value = res.body.node.value
|
|
|
|
if value.up_time >= 2 then
|
2020-12-09 10:07:57 +08:00
|
|
|
ngx.say("integral")
|
|
|
|
else
|
|
|
|
ngx.say("reset")
|
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
integral
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
--- error_log
|
|
|
|
timer created to report server info, interval: 60
|
2020-12-22 11:04:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 3: get server_info from plugin control API
|
|
|
|
--- yaml_config
|
|
|
|
apisix:
|
|
|
|
id: 123456
|
|
|
|
plugins:
|
|
|
|
- server-info
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
2020-12-28 20:51:56 +08:00
|
|
|
local json = require("toolkit.json")
|
2020-12-22 11:04:56 +08:00
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, _, body = t("/v1/server_info")
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
|
2020-12-28 20:51:56 +08:00
|
|
|
body = json.decode(body)
|
|
|
|
ngx.say(json.encode(body))
|
2020-12-22 11:04:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body eval
|
2020-12-28 20:51:56 +08:00
|
|
|
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\.]+"}$/
|
2020-12-22 11:04:56 +08:00
|
|
|
--- no_error_log
|
|
|
|
[error]
|