You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/09/07 17:52:23 UTC

[GitHub] [apisix] tzssangglass opened a new pull request #5012: feat(debug-mode): add dynamic debug mode

tzssangglass opened a new pull request #5012:
URL: https://github.com/apache/apisix/pull/5012


   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   Add dynamic debug mode. In scenarios where write file permissions are tightly controlled, advanced debugging mode can be dynamically enabled or disabled via the API to help debug production environments.
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   ### Pre-submission checklist:
   
   * [x] Did you explain what problem does this PR solve? Or what new features have been added?
   * [x] Have you added corresponding test cases?
   * [x] Have you modified the corresponding document?
   * [x] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander merged pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #5012:
URL: https://github.com/apache/apisix/pull/5012


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r708823483



##########
File path: conf/debug.yaml
##########
@@ -14,6 +14,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+http:
+  dynamic: false         # enable or disable this feature

Review comment:
       update, use `enable`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] nic-chen commented on pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
nic-chen commented on pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#issuecomment-922850768


   > I have a question. After `debug.yaml` is changed, do we need to restart APISIX for it?
   > For example, enable/disable debug mode.
   
   ignore it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r711094971



##########
File path: apisix/init.lua
##########
@@ -355,6 +356,8 @@ function _M.http_access_phase()
 
     core.ctx.set_vars_meta(api_ctx)
 
+    debug.dynamic_debug()

Review comment:
       done

##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -83,3 +83,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Enable Advanced Debug Mode Dynamically
+
+The advanced debug mode can be enabled dynamically by a single request and turned off automatically when the request ends.

Review comment:
       done

##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -83,3 +83,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Enable Advanced Debug Mode Dynamically
+
+The advanced debug mode can be enabled dynamically by a single request and turned off automatically when the request ends.
+
+Example:
+
+```yaml
+http_filter:
+  enable: true # Enable/Disable Advanced Debug Mode Dynamically
+  enable_header_name: X-APISIX-Dynamic-Debug # Trace for the request with this header
+......
+#END
+```
+
+Dynamically enable advanced debugging mode, example:
+
+```shell
+curl 127.0.0.1:9090/hello --header 'X-APISIX-Dynamic-Debug: foo'
+```
+
+Notice: Dynamic advanced debug mode cannot hook the `apisix.http_access_phase` module (because the request enters the `apisix.http_access_phase` module before it determines whether advanced debug mode is dynamically enabled).

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r709804565



##########
File path: apisix/debug.lua
##########
@@ -123,15 +124,35 @@ local function apple_new_fun(module, fun_name, file_path, hook_conf)
 
     function mt.__call(self, ...)
         local arg = {...}
+        local http_filter = debug_yaml.http_filter
+        local api_ctx = ngx.ctx.api_ctx
         if hook_conf.is_print_input_args then
-            log[log_level]("call require(\"", file_path, "\").", fun_name,
-                           "() args:", json.delay_encode(arg, true))
+            if not (http_filter and http_filter.enable)
+                    or (api_ctx and api_ctx.enable_dynamic_debug) then

Review comment:
       Better to refactor the complex expression to a boolean variable

##########
File path: t/debug/dynamic-hook.t
##########
@@ -0,0 +1,300 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+log_level('info');
+no_root_location();
+no_shuffle();
+
+sub read_file($) {

Review comment:
       It is already done in the master branch. Let's merge the master.

##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -83,3 +83,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Enable Advanced Debug Mode Dynamically
+
+The advanced debug mode can be enabled dynamically by a single request and turned off automatically when the request ends.

Review comment:
       ```suggestion
   The advanced debug mode can take effect in particular requests by dynamic rule.
   ```

##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -83,3 +83,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Enable Advanced Debug Mode Dynamically
+
+The advanced debug mode can be enabled dynamically by a single request and turned off automatically when the request ends.
+
+Example:
+
+```yaml
+http_filter:
+  enable: true # Enable/Disable Advanced Debug Mode Dynamically
+  enable_header_name: X-APISIX-Dynamic-Debug # Trace for the request with this header
+......
+#END
+```
+
+Dynamically enable advanced debugging mode, example:

Review comment:
       ```suggestion
   Dynamically enable advanced debugging mode in a particular request like this:
   ```

##########
File path: apisix/init.lua
##########
@@ -355,6 +356,8 @@ function _M.http_access_phase()
 
     core.ctx.set_vars_meta(api_ctx)
 
+    debug.dynamic_debug()

Review comment:
       the api_ctx can be passed as argument

##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -83,3 +83,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Enable Advanced Debug Mode Dynamically
+
+The advanced debug mode can be enabled dynamically by a single request and turned off automatically when the request ends.
+
+Example:
+
+```yaml
+http_filter:
+  enable: true # Enable/Disable Advanced Debug Mode Dynamically
+  enable_header_name: X-APISIX-Dynamic-Debug # Trace for the request with this header
+......
+#END
+```
+
+Dynamically enable advanced debugging mode, example:
+
+```shell
+curl 127.0.0.1:9090/hello --header 'X-APISIX-Dynamic-Debug: foo'
+```
+
+Notice: Dynamic advanced debug mode cannot hook the `apisix.http_access_phase` module (because the request enters the `apisix.http_access_phase` module before it determines whether advanced debug mode is dynamically enabled).

Review comment:
       ```suggestion
   Notice: We can not only hook the `apisix.http_access_phase` module in particular requests. Because the request enters the `apisix.http_access_phase` module before it determines whether advanced debug mode is dynamically enabled.
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r707528522



##########
File path: apisix/debug.lua
##########
@@ -30,6 +29,7 @@ local setmetatable = setmetatable
 local pcall        = pcall
 local ipairs       = ipairs
 local unpack       = unpack
+local inspect      = require "inspect"

Review comment:
       `require("apisix.debug")` in `init.lua` --> `require("ngx.process")` in `debug.lua`, will result in error as `process.lua:5: unsupported subsystem: stream`, see: https://github.com/apache/apisix/runs/3578221555
   
   ngx.process API for stream subsystem is not implemented on openresty 1.19.3.2(but is implemented on 1.19.9.1), so I move `require("ngx.process")` to function.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tokers commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r712861888



##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -83,3 +83,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Enable Advanced Debug Mode Dynamically
+
+The advanced debug mode can take effect in particular requests by dynamic rule.
+
+Example:
+
+```yaml
+http_filter:
+  enable: true # Enable/Disable Advanced Debug Mode Dynamically
+  enable_header_name: X-APISIX-Dynamic-Debug # Trace for the request with this header
+......
+#END
+```
+
+Dynamically enable advanced debugging mode in a particular request like this:
+
+```shell
+curl 127.0.0.1:9090/hello --header 'X-APISIX-Dynamic-Debug: foo'
+```
+
+Notice: We can not only hook the `apisix.http_access_phase` module in particular requests. Because the request enters the `apisix.http_access_phase` module before it determines whether advanced debug mode is dynamically enabled.

Review comment:
       The meaning of this sentence is tough to understand, but I got the correct one from its Chinese version. Maybe the following one is better:
   
   ```suggestion
   Notice: We can not hook the `apisix.http_access_phase` module for particular requests, since whether the advanced debug mode is enabled is determined after these requests enter such phase```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r708831143



##########
File path: t/debug/dynamic-hook.t
##########
@@ -0,0 +1,300 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+log_level('info');
+no_root_location();
+no_shuffle();
+
+sub read_file($) {

Review comment:
       I prefer to open another PR to do this, which is used in several test cases.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r711094863



##########
File path: apisix/debug.lua
##########
@@ -123,15 +124,35 @@ local function apple_new_fun(module, fun_name, file_path, hook_conf)
 
     function mt.__call(self, ...)
         local arg = {...}
+        local http_filter = debug_yaml.http_filter
+        local api_ctx = ngx.ctx.api_ctx
         if hook_conf.is_print_input_args then
-            log[log_level]("call require(\"", file_path, "\").", fun_name,
-                           "() args:", json.delay_encode(arg, true))
+            if not (http_filter and http_filter.enable)
+                    or (api_ctx and api_ctx.enable_dynamic_debug) then

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r711421451



##########
File path: docs/zh/latest/architecture-design/debug-mode.md
##########
@@ -85,3 +85,25 @@ hook_phase: # 模块函数列表,名字:hook_phase
     - http_log_phase
 #END
 ```
+
+### 动态高级调试模式
+
+动态高级调试模式是基于高级调试模式,可以由单个请求动态开启高级调试模式,请求结束后自动关闭。设置 `conf/debug.yaml` 中的选项。

Review comment:
       We don't disable it when the request is finished, better not to mention it.

##########
File path: apisix/debug.lua
##########
@@ -123,15 +124,35 @@ local function apple_new_fun(module, fun_name, file_path, hook_conf)
 
     function mt.__call(self, ...)
         local arg = {...}
+        local http_filter = debug_yaml.http_filter
+        local api_ctx = ngx.ctx.api_ctx
+        local enable_by_hook = not (http_filter and http_filter.enable)
+                or (api_ctx and api_ctx.enable_dynamic_debug)

Review comment:
       We don't need this part. When not http_filter, there won't be api_ctx.enable_dynamic_debug too

##########
File path: apisix/debug.lua
##########
@@ -123,15 +124,35 @@ local function apple_new_fun(module, fun_name, file_path, hook_conf)
 
     function mt.__call(self, ...)
         local arg = {...}
+        local http_filter = debug_yaml.http_filter
+        local api_ctx = ngx.ctx.api_ctx
+        local enable_by_hook = not (http_filter and http_filter.enable)
+                or (api_ctx and api_ctx.enable_dynamic_debug)
+        local enable_by_header_filter = (http_filter and http_filter.enable)
+                and (api_ctx and api_ctx.enable_dynamic_debug)
         if hook_conf.is_print_input_args then
-            log[log_level]("call require(\"", file_path, "\").", fun_name,
-                           "() args:", json.delay_encode(arg, true))
+            if enable_by_hook then

Review comment:
       ```suggestion
               if enable_by_hook or enable_by_header_filter then
   ```

##########
File path: apisix/debug.lua
##########
@@ -30,6 +29,7 @@ local setmetatable = setmetatable
 local pcall        = pcall
 local ipairs       = ipairs
 local unpack       = unpack
+local inspect      = require "inspect"

Review comment:
       Actually I mean to use `require("inspect")`, the `require("ngx.process")` is just an example.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r711432352



##########
File path: apisix/debug.lua
##########
@@ -17,18 +17,19 @@
 local require      = require
 local yaml         = require("tinyyaml")
 local log          = require("apisix.core.log")
-local json         = require("apisix.core.json")
 local profile      = require("apisix.core.profile")
 local lfs          = require("lfs")
 local io           = io
 local ngx          = ngx
 local re_find      = ngx.re.find
+local get_headers  = ngx.req.get_headers
 local type         = type
 local pairs        = pairs
 local setmetatable = setmetatable
 local pcall        = pcall
 local ipairs       = ipairs
 local unpack       = unpack
+local inspect      = require("inspect")

Review comment:
       This module should be grouped into other requirements.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r708823282



##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -76,3 +76,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Dynamic Advanced Debug Mode
+
+Dynamic advanced debug mode is based on advanced debug mode, which can be enabled dynamically by a single request and turned off automatically when the request ends.
+
+Example:
+
+```yaml
+http:
+  dynamic: true # 是否动态开启高级调试模式
+  enable_header_name: X-APISIX-Dynamic-Debug # 对携带此 header 的请求开启高级调试模式
+......
+#END
+```
+
+Dynamically enable advanced debugging mode, example:
+
+```shell
+curl 127.0.0.1:9090/hello --header 'X-APISIX-Dynamic-Debug: foo'
+```
+
+Notice: Dynamic advanced debug mode cannot debug the `apisix.http_access_phase` module (because the request enters the `apisix.http_access_phase` module before it determines whether advanced debug mode is dynamically enabled).

Review comment:
       done

##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -76,3 +76,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Dynamic Advanced Debug Mode

Review comment:
       done

##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -76,3 +76,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Dynamic Advanced Debug Mode
+
+Dynamic advanced debug mode is based on advanced debug mode, which can be enabled dynamically by a single request and turned off automatically when the request ends.

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r713177767



##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -83,3 +83,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Enable Advanced Debug Mode Dynamically
+
+The advanced debug mode can take effect in particular requests by dynamic rule.
+
+Example:
+
+```yaml
+http_filter:
+  enable: true # Enable/Disable Advanced Debug Mode Dynamically
+  enable_header_name: X-APISIX-Dynamic-Debug # Trace for the request with this header
+......
+#END
+```
+
+Dynamically enable advanced debugging mode in a particular request like this:
+
+```shell
+curl 127.0.0.1:9090/hello --header 'X-APISIX-Dynamic-Debug: foo'
+```
+
+Notice: We can not only hook the `apisix.http_access_phase` module in particular requests. Because the request enters the `apisix.http_access_phase` module before it determines whether advanced debug mode is dynamically enabled.

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r711095253



##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -83,3 +83,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Enable Advanced Debug Mode Dynamically
+
+The advanced debug mode can be enabled dynamically by a single request and turned off automatically when the request ends.
+
+Example:
+
+```yaml
+http_filter:
+  enable: true # Enable/Disable Advanced Debug Mode Dynamically
+  enable_header_name: X-APISIX-Dynamic-Debug # Trace for the request with this header
+......
+#END
+```
+
+Dynamically enable advanced debugging mode, example:

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #5012: feat(debug-mode): add dynamic debug mode

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #5012:
URL: https://github.com/apache/apisix/pull/5012#discussion_r707140742



##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -76,3 +76,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Dynamic Advanced Debug Mode
+
+Dynamic advanced debug mode is based on advanced debug mode, which can be enabled dynamically by a single request and turned off automatically when the request ends.
+
+Example:
+
+```yaml
+http:
+  dynamic: true # 是否动态开启高级调试模式
+  enable_header_name: X-APISIX-Dynamic-Debug # 对携带此 header 的请求开启高级调试模式
+......
+#END
+```
+
+Dynamically enable advanced debugging mode, example:
+
+```shell
+curl 127.0.0.1:9090/hello --header 'X-APISIX-Dynamic-Debug: foo'
+```
+
+Notice: Dynamic advanced debug mode cannot debug the `apisix.http_access_phase` module (because the request enters the `apisix.http_access_phase` module before it determines whether advanced debug mode is dynamically enabled).

Review comment:
       ```suggestion
   Notice: Dynamic advanced debug mode cannot hook the `apisix.http_access_phase` module (because the request enters the `apisix.http_access_phase` module before it determines whether advanced debug mode is dynamically enabled).
   ```

##########
File path: t/debug/dynamic-hook.t
##########
@@ -0,0 +1,300 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+log_level('info');
+no_root_location();
+no_shuffle();
+
+sub read_file($) {

Review comment:
       Could we move the read_file into APISIX.pm?

##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -76,3 +76,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Dynamic Advanced Debug Mode
+
+Dynamic advanced debug mode is based on advanced debug mode, which can be enabled dynamically by a single request and turned off automatically when the request ends.
+
+Example:
+
+```yaml
+http:
+  dynamic: true # 是否动态开启高级调试模式

Review comment:
       Need English comment in English doc

##########
File path: apisix/debug.lua
##########
@@ -200,7 +202,43 @@ local function sync_debug_status(premature)
 end
 
 
+local function check()
+    if not debug_yaml or not debug_yaml.http then
+        return false
+    end
+
+    local http = debug_yaml.http
+    if not http or not http.enable_header_name or not http.dynamic then
+        return false
+    end
+
+    return true
+end
+
+function _M.dynamic_enable(api_ctx)

Review comment:
       This function is called in the request level, but it changes a field at the module level. Look like it will affect other requests?

##########
File path: apisix/debug.lua
##########
@@ -30,6 +29,7 @@ local setmetatable = setmetatable
 local pcall        = pcall
 local ipairs       = ipairs
 local unpack       = unpack
+local inspect      = require "inspect"

Review comment:
       Better to put all require together, and in the form `require("ngx.process")`

##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -76,3 +76,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Dynamic Advanced Debug Mode
+
+Dynamic advanced debug mode is based on advanced debug mode, which can be enabled dynamically by a single request and turned off automatically when the request ends.

Review comment:
       ```suggestion
   The advanced debug mode can be enabled dynamically by a single request and turned off automatically when the request ends.
   ```

##########
File path: conf/debug.yaml
##########
@@ -14,6 +14,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+http:
+  dynamic: false         # enable or disable this feature

Review comment:
       The name "dynamic" is not good enough, better to use a verb instead of an adjective as field name.

##########
File path: docs/en/latest/architecture-design/debug-mode.md
##########
@@ -76,3 +76,25 @@ hook_phase: # Module Function List, Name: hook_phase
     - http_log_phase
 #END
 ```
+
+### Dynamic Advanced Debug Mode

Review comment:
       ```suggestion
   ### Enable Advanced Debug Mode Dynamically
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org