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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]