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 1 commit
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 then
return false
end

return debug_yaml.enable_debug
end


function _M.init_worker()
local process = require("ngx.process")
if process.type() ~= "worker" then
return
end
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
1 change: 1 addition & 0 deletions conf/debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
enable_debug: false
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
enable_debug: false
basic:
enable: false

would be better?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks better, but this enable will conflict with

$debug_config =~ s/enable: false/enable: true/;

I don't know how to modify this with perl.

Copy link
Member

Choose a reason for hiding this comment

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

Let me do it for you 😃

hook_conf:
enable: false # enable or disable this feature
name: hook_phase # the name of module and function list
Expand Down
2 changes: 1 addition & 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,7 @@ 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 just by setting `enable_debug = true` in `conf/debug.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
2 changes: 1 addition & 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,7 @@ title: Debug Mode

### 基本调试模式

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

Choose a reason for hiding this comment

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

Hi, for those who using apisix versions before 2.9.0, this document may be confused

Copy link
Member

Choose a reason for hiding this comment

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

We can add a note for the version before 2.10.0?


比如对 `/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
2 changes: 0 additions & 2 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 Down Expand Up @@ -88,7 +87,6 @@ apisix:
node_listen: 1984
config_center: yaml
enable_admin: false
enable_debug: true
plugins:
- ip-restriction
- jwt-auth
Expand Down
26 changes: 16 additions & 10 deletions t/debug/debug-mode.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,31 @@ repeat_each(1);
no_long_string();
no_root_location();

our $yaml_config = <<_EOC_;
apisix:
node_listen: 1984
enable_debug: true
_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/enable_debug: false/enable_debug: 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 +133,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 +195,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 +259,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,7 +355,7 @@ 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"
Expand Down