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/13 09:10:29 UTC

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

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