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

change(debug): move 'enable_debug' form config.yaml to debug.yaml #5046

Merged
merged 5 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion apisix/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ local yaml = require("tinyyaml")
local log = require("apisix.core.log")
local json = require("apisix.core.json")
local profile = require("apisix.core.profile")
local process = require("ngx.process")
local lfs = require("lfs")
local io = io
local ngx = ngx
Expand Down Expand Up @@ -200,7 +199,17 @@ local function sync_debug_status(premature)
end


function _M.enable_debug()
if not debug_yaml or not debug_yaml.basic then
return false
end

return debug_yaml.basic.enable
end


function _M.init_worker()
local process = require("ngx.process")
if process.type() ~= "worker" then
return
end
Expand Down
3 changes: 2 additions & 1 deletion apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ function _M.http_init_worker()

require("apisix.timers").init_worker()

require("apisix.debug").init_worker()

plugin.init_worker()
router.http_init_worker()
require("apisix.http.service").init_worker()
Expand All @@ -123,7 +125,6 @@ function _M.http_init_worker()
core.config.init_worker()
end

require("apisix.debug").init_worker()
apisix_upstream.init_worker()
require("apisix.plugins.ext-plugin.init").init_worker()

Expand Down
9 changes: 4 additions & 5 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
local require = require
local core = require("apisix.core")
local config_util = require("apisix.core.config_util")
local enable_debug = require("apisix.debug").enable_debug
local ngx_exit = ngx.exit
local pkg_loaded = package.loaded
local sort_tab = table.sort
Expand Down Expand Up @@ -167,8 +168,7 @@ local function load(plugin_names)

for i, plugin in ipairs(local_plugins) do
local_plugins_hash[plugin.name] = plugin
if local_conf and local_conf.apisix
and local_conf.apisix.enable_debug then
if enable_debug() then
core.log.warn("loaded plugin and sort by priority:",
" ", plugin.priority,
" name: ", plugin.name)
Expand Down Expand Up @@ -209,8 +209,7 @@ local function load_stream(plugin_names)

for i, plugin in ipairs(stream_local_plugins) do
stream_local_plugins_hash[plugin.name] = plugin
if local_conf and local_conf.apisix
and local_conf.apisix.enable_debug then
if enable_debug() then
core.log.warn("loaded stream plugin and sort by priority:",
" ", plugin.priority,
" name: ", plugin.name)
Expand Down Expand Up @@ -280,7 +279,7 @@ end


local function trace_plugins_info_for_debug(ctx, plugins)
if not (local_conf and local_conf.apisix.enable_debug) then
if not enable_debug() then
return
end

Expand Down
1 change: 0 additions & 1 deletion conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ apisix:
# enable_http2: true
enable_admin: true
enable_admin_cors: true # Admin API support CORS response headers.
enable_debug: false
enable_dev_mode: false # Sets nginx worker_processes to 1 if set to true
enable_reuseport: true # Enable nginx SO_REUSEPORT switch if set to true.
enable_ipv6: true
Expand Down
2 changes: 2 additions & 0 deletions conf/debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
basic:
enable: false
hook_conf:
enable: false # enable or disable this feature
name: hook_phase # the name of module and function list
Expand Down
9 changes: 8 additions & 1 deletion docs/en/latest/architecture-design/debug-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ title: Debug Mode

### Basic Debug Mode

Enable basic debug mode just by setting `apisix.enable_debug = true` in `conf/config.yaml` file.
Enable basic debug mode via `conf/debug.yaml` file:

```
basic:
enable: true
```

Note: before APISIX 2.10, we enabled basic debug mode by setting `apisix.enable_debug = true` in `conf/config.yaml` file.

e.g Using both `limit-conn` and `limit-count` plugins for a `/hello` request, there will have a response header called `Apisix-Plugins: limit-conn, limit-count`.

Expand Down
9 changes: 8 additions & 1 deletion docs/zh/latest/architecture-design/debug-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ title: Debug Mode

### 基本调试模式

设置 `conf/config.yaml` 中的 `apisix.enable_debug` 为 `true`,即可开启基本调试模式。
设置 `conf/debug.yaml` 即可开启基本调试模式:

```
basic:
enable: true
```

注意:在 APISIX 2.10 之前,开启基本调试模式曾经是设置 `conf/config.yaml` 中的 `apisix.enable_debug` 为 `true`。

比如对 `/hello` 开启了 `limit-conn`和`limit-count`插件,这时候应答头中会有 `Apisix-Plugins: limit-conn, limit-count`。

Expand Down
1 change: 0 additions & 1 deletion t/config-center-yaml/consumer.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ apisix:
node_listen: 1984
config_center: yaml
enable_admin: false
enable_debug: true
_EOC_

$block->set_value("yaml_config", $yaml_config);
Expand Down
46 changes: 42 additions & 4 deletions t/config-center-yaml/plugin.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ apisix:
node_listen: 1984
config_center: yaml
enable_admin: false
enable_debug: true
_EOC_

$block->set_value("yaml_config", $yaml_config);
Expand All @@ -52,6 +51,18 @@ _EOC_
}
});

sub read_file($) {
my $infile = shift;
open my $in, $infile
or die "cannot open $infile for reading: $!";
my $cert = do { local $/; <$in> };
close $in;
$cert;
}

our $debug_config = read_file("conf/debug.yaml");
$debug_config =~ s/basic:\n enable: false/basic:\n enable: true/;

run_tests();

__DATA__
Expand All @@ -63,8 +74,22 @@ plugins:
- name: jwt-auth
- name: mqtt-proxy
stream: true
--- debug_config eval: $::debug_config
--- config
location /t {
content_by_lua_block {
ngx.sleep(0.3)
local http = require "resty.http"
local httpc = http.new()
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
local res, err = httpc:request_uri(uri, {
method = "GET",
})
ngx.print(res.body)
}
}
--- request
GET /hello
GET /t
--- response_body
hello world
--- error_log
Expand All @@ -88,7 +113,6 @@ apisix:
node_listen: 1984
config_center: yaml
enable_admin: false
enable_debug: true
plugins:
- ip-restriction
- jwt-auth
Expand All @@ -100,8 +124,22 @@ plugins:
- name: jwt-auth
- name: mqtt-proxy
stream: true
--- debug_config eval: $::debug_config
--- config
location /t {
content_by_lua_block {
ngx.sleep(0.3)
local http = require "resty.http"
local httpc = http.new()
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
local res, err = httpc:request_uri(uri, {
method = "GET",
})
ngx.print(res.body)
}
}
--- request
GET /hello
GET /t
--- response_body
hello world
--- grep_error_log eval
Expand Down
19 changes: 8 additions & 11 deletions t/debug/debug-mode.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,22 @@ repeat_each(1);
no_long_string();
no_root_location();

our $yaml_config = <<_EOC_;
apisix:
node_listen: 1984
enable_debug: true
_EOC_
our $debug_config = t::APISIX::read_file("conf/debug.yaml");
$debug_config =~ s/basic:\n enable: false/basic:\n enable: true/;

run_tests;

__DATA__

=== TEST 1: loaded plugin
--- debug_config eval: $::debug_config
--- config
location /t {
content_by_lua_block {
ngx.sleep(0.3)
ngx.say("done")
}
}
--- yaml_config eval: $::yaml_config
--- request
GET /t
--- response_body
Expand Down Expand Up @@ -127,9 +124,9 @@ passed


=== TEST 3: hit routes
--- debug_config eval: $::debug_config
--- request
GET /hello
--- yaml_config eval: $::yaml_config
--- response_body
hello world
--- response_headers
Expand Down Expand Up @@ -189,7 +186,7 @@ passed


=== TEST 5: hit routes
--- yaml_config eval: $::yaml_config
--- debug_config eval: $::debug_config
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -253,7 +250,7 @@ passed


=== TEST 7: hit routes
--- yaml_config eval: $::yaml_config
--- debug_config eval: $::debug_config
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -349,13 +346,13 @@ passed


=== TEST 10: hit route
--- yaml_config eval: $::yaml_config
--- debug_config eval: $::debug_config
--- stream_enable
--- stream_request eval
"\x10\x0f\x00\x04\x4d\x51\x54\x54\x04\x02\x00\x3c\x00\x03\x66\x6f\x6f"
--- stream_response
hello world
--- error_log
Apisix-Plugins: mqtt-proxy
mqtt client id: foo while prereading client data
--- no_error_log
[error]
2 changes: 1 addition & 1 deletion t/debug/hook.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sub read_file($) {
}

our $debug_config = read_file("conf/debug.yaml");
$debug_config =~ s/enable: false/enable: true/;
$debug_config =~ s/hook_conf:\n enable: false/hook_conf:\n enable: true/;

run_tests();

Expand Down