2019-10-31 09:27:28 +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.
|
|
|
|
#
|
2019-09-10 09:42:55 +08:00
|
|
|
use t::APISIX 'no_plan';
|
2019-08-20 22:17:37 +08:00
|
|
|
|
|
|
|
repeat_each(1);
|
|
|
|
no_long_string();
|
|
|
|
no_root_location();
|
|
|
|
no_shuffle();
|
|
|
|
log_level("info");
|
|
|
|
workers(2);
|
|
|
|
|
2020-11-03 13:46:24 +08:00
|
|
|
add_block_preprocessor(sub {
|
|
|
|
my ($block) = @_;
|
|
|
|
|
2021-03-30 09:54:18 +08:00
|
|
|
if (!defined $block->no_error_log) {
|
|
|
|
$block->set_value("no_error_log", "[error]");
|
|
|
|
}
|
2020-11-03 13:46:24 +08:00
|
|
|
|
|
|
|
$block;
|
|
|
|
});
|
|
|
|
|
2019-08-20 22:17:37 +08:00
|
|
|
run_tests;
|
|
|
|
|
|
|
|
__DATA__
|
|
|
|
|
|
|
|
=== TEST 1: reload plugins
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, _, org_body = t('/apisix/admin/plugins/reload',
|
|
|
|
ngx.HTTP_PUT)
|
|
|
|
|
|
|
|
ngx.status = code
|
2020-02-18 15:19:12 +08:00
|
|
|
ngx.say(org_body)
|
2019-08-20 22:17:37 +08:00
|
|
|
ngx.sleep(0.2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
done
|
|
|
|
--- error_log
|
|
|
|
load plugin times: 1
|
|
|
|
load plugin times: 1
|
|
|
|
start to hot reload plugins
|
|
|
|
start to hot reload plugins
|
2020-11-03 13:46:24 +08:00
|
|
|
load(): plugins not changed
|
|
|
|
load_stream(): plugins not changed
|
|
|
|
load(): plugins not changed
|
|
|
|
load_stream(): plugins not changed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 2: reload plugins triggers plugin list sync
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local core = require "apisix.core"
|
|
|
|
local config_util = require("apisix.core.config_util")
|
2021-01-26 00:01:48 +08:00
|
|
|
ngx.sleep(0.5) -- make sure the sync happened when admin starts is already finished
|
2020-11-03 13:46:24 +08:00
|
|
|
|
2021-01-11 15:49:11 +08:00
|
|
|
local before_reload = true
|
2020-11-03 13:46:24 +08:00
|
|
|
local plugins_conf, err
|
|
|
|
plugins_conf, err = core.config.new("/plugins", {
|
|
|
|
automatic = true,
|
|
|
|
single_item = true,
|
2021-03-12 09:09:19 +08:00
|
|
|
filter = function(item)
|
|
|
|
-- called twice before reload,
|
|
|
|
-- one for worker start, another for sync data from admin
|
2021-01-11 15:49:11 +08:00
|
|
|
ngx.log(ngx.WARN, "reload plugins on node ",
|
|
|
|
before_reload and "before reload" or "after reload")
|
2021-03-12 09:09:19 +08:00
|
|
|
ngx.log(ngx.WARN, require("toolkit.json").encode(item.value))
|
2020-11-03 13:46:24 +08:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
if not plugins_conf then
|
|
|
|
error("failed to create etcd instance for fetching /plugins : "
|
|
|
|
.. err)
|
|
|
|
end
|
2021-01-11 15:49:11 +08:00
|
|
|
ngx.sleep(0.5)
|
2020-11-03 13:46:24 +08:00
|
|
|
|
|
|
|
local data = [[
|
|
|
|
apisix:
|
|
|
|
node_listen: 1984
|
|
|
|
admin_key: null
|
|
|
|
plugins:
|
|
|
|
- jwt-auth
|
|
|
|
stream_plugins:
|
|
|
|
- mqtt-proxy
|
|
|
|
]]
|
|
|
|
require("lib.test_admin").set_config_yaml(data)
|
|
|
|
|
2021-01-11 15:49:11 +08:00
|
|
|
before_reload = false
|
2020-11-03 13:46:24 +08:00
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, _, org_body = t('/apisix/admin/plugins/reload',
|
|
|
|
ngx.HTTP_PUT)
|
|
|
|
|
|
|
|
ngx.status = code
|
|
|
|
ngx.say(org_body)
|
2020-11-27 17:36:58 +08:00
|
|
|
ngx.sleep(1)
|
2020-11-03 13:46:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
done
|
|
|
|
--- grep_error_log eval
|
2021-01-11 15:49:11 +08:00
|
|
|
qr/reload plugins on node \w+ reload/
|
2020-11-03 13:46:24 +08:00
|
|
|
--- grep_error_log_out
|
2021-01-11 15:49:11 +08:00
|
|
|
reload plugins on node before reload
|
2021-03-12 09:09:19 +08:00
|
|
|
reload plugins on node before reload
|
2021-01-11 15:49:11 +08:00
|
|
|
reload plugins on node after reload
|
2020-11-03 13:46:24 +08:00
|
|
|
--- error_log
|
|
|
|
filter(): [{"name":"jwt-auth"},{"name":"mqtt-proxy","stream":true}]
|
2020-11-13 00:23:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 3: reload plugins when attributes changed
|
|
|
|
--- yaml_config
|
|
|
|
apisix:
|
|
|
|
node_listen: 1984
|
|
|
|
admin_key: null
|
|
|
|
plugins:
|
|
|
|
- example-plugin
|
|
|
|
plugin_attr:
|
|
|
|
example-plugin:
|
|
|
|
val: 0
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local core = require "apisix.core"
|
2020-11-17 18:00:30 +08:00
|
|
|
ngx.sleep(0.1)
|
2020-11-13 00:23:30 +08:00
|
|
|
local data = [[
|
|
|
|
apisix:
|
|
|
|
node_listen: 1984
|
|
|
|
admin_key: null
|
|
|
|
plugins:
|
|
|
|
- example-plugin
|
|
|
|
plugin_attr:
|
|
|
|
example-plugin:
|
|
|
|
val: 1
|
|
|
|
]]
|
|
|
|
require("lib.test_admin").set_config_yaml(data)
|
|
|
|
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, _, org_body = t('/apisix/admin/plugins/reload',
|
|
|
|
ngx.HTTP_PUT)
|
|
|
|
|
|
|
|
ngx.status = code
|
|
|
|
ngx.say(org_body)
|
|
|
|
ngx.sleep(0.1)
|
|
|
|
|
|
|
|
local data = [[
|
|
|
|
apisix:
|
|
|
|
node_listen: 1984
|
|
|
|
admin_key: null
|
|
|
|
plugins:
|
|
|
|
- example-plugin
|
|
|
|
plugin_attr:
|
|
|
|
example-plugin:
|
|
|
|
val: 1
|
|
|
|
]]
|
|
|
|
require("lib.test_admin").set_config_yaml(data)
|
|
|
|
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, _, org_body = t('/apisix/admin/plugins/reload',
|
|
|
|
ngx.HTTP_PUT)
|
|
|
|
ngx.say(org_body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
done
|
|
|
|
done
|
|
|
|
--- grep_error_log eval
|
|
|
|
qr/example-plugin get plugin attr val: \d+/
|
|
|
|
--- grep_error_log_out
|
|
|
|
example-plugin get plugin attr val: 0
|
|
|
|
example-plugin get plugin attr val: 0
|
|
|
|
example-plugin get plugin attr val: 0
|
|
|
|
example-plugin get plugin attr val: 1
|
|
|
|
example-plugin get plugin attr val: 1
|
|
|
|
example-plugin get plugin attr val: 1
|
|
|
|
--- error_log
|
|
|
|
plugin_attr of example-plugin changed
|
|
|
|
plugins not changed
|
2020-11-30 14:35:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 4: reload plugins to change prometheus' export uri
|
|
|
|
--- yaml_config
|
|
|
|
apisix:
|
|
|
|
node_listen: 1984
|
|
|
|
admin_key: null
|
|
|
|
plugins:
|
|
|
|
- prometheus
|
|
|
|
plugin_attr:
|
|
|
|
prometheus:
|
|
|
|
export_uri: /metrics
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local core = require "apisix.core"
|
|
|
|
ngx.sleep(0.1)
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, _, org_body = t('/apisix/metrics',
|
|
|
|
ngx.HTTP_GET)
|
|
|
|
ngx.say(code)
|
|
|
|
|
|
|
|
local data = [[
|
|
|
|
apisix:
|
|
|
|
node_listen: 1984
|
|
|
|
admin_key: null
|
|
|
|
plugins:
|
|
|
|
- prometheus
|
|
|
|
plugin_attr:
|
|
|
|
prometheus:
|
|
|
|
export_uri: /apisix/metrics
|
|
|
|
]]
|
|
|
|
require("lib.test_admin").set_config_yaml(data)
|
|
|
|
|
|
|
|
local code, _, org_body = t('/apisix/admin/plugins/reload',
|
|
|
|
ngx.HTTP_PUT)
|
|
|
|
|
|
|
|
ngx.say(org_body)
|
|
|
|
|
|
|
|
ngx.sleep(0.1)
|
|
|
|
local code, _, org_body = t('/apisix/metrics',
|
|
|
|
ngx.HTTP_GET)
|
|
|
|
ngx.say(code)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
404
|
|
|
|
done
|
|
|
|
200
|
2021-03-30 09:54:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 5: reload plugins to disable skywalking
|
|
|
|
--- yaml_config
|
|
|
|
apisix:
|
|
|
|
node_listen: 1984
|
|
|
|
admin_key: null
|
|
|
|
plugins:
|
|
|
|
- skywalking
|
|
|
|
plugin_attr:
|
|
|
|
skywalking:
|
|
|
|
service_name: APISIX
|
|
|
|
service_instance_name: "APISIX Instance Name"
|
|
|
|
endpoint_addr: http://127.0.0.1:12801
|
|
|
|
report_interval: 1
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local core = require "apisix.core"
|
|
|
|
ngx.sleep(1.2)
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
|
|
|
|
local data = [[
|
|
|
|
apisix:
|
|
|
|
node_listen: 1984
|
|
|
|
admin_key: null
|
|
|
|
plugins:
|
|
|
|
- prometheus
|
|
|
|
]]
|
|
|
|
require("lib.test_admin").set_config_yaml(data)
|
|
|
|
|
|
|
|
local code, _, org_body = t('/apisix/admin/plugins/reload',
|
|
|
|
ngx.HTTP_PUT)
|
|
|
|
|
|
|
|
ngx.say(org_body)
|
|
|
|
|
|
|
|
ngx.sleep(2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
done
|
|
|
|
--- no_error_log
|
|
|
|
[alert]
|
|
|
|
--- grep_error_log eval
|
|
|
|
qr/Instance report fails/
|
|
|
|
--- grep_error_log_out
|
|
|
|
Instance report fails
|