tzssangglass commented on a change in pull request #5501:
URL: https://github.com/apache/apisix/pull/5501#discussion_r749939229



##########
File path: docs/zh/latest/plugins/kafka-logger.md
##########
@@ -57,6 +57,7 @@ title: kafka-logger
 | max_retry_count  | integer | 可选   | 0              | [0,...] | 
从处理管道中移除之前的最大重试次数。             |
 | retry_delay      | integer | 可选   | 1              | [0,...] | 
如果执行失败,则应延迟执行流程的秒数。           |
 | include_req_body | boolean | 可选   | false          | [false, true] | 是否包括请求 
body。false: 表示不包含请求的 body ; true: 表示包含请求的 body 。|
+| include_req_body_expr | array  | 可选    |           |         | 
是否采集请求body,基于[lua-resty-expr](https://github.com/api7/lua-resty-expr)。 该选项需要开启 
`include_req_body`|

Review comment:
       ```suggestion
   | include_req_body_expr | array  | 可选    |           |         | 
是否采集请求body,基于 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。 该选项需要开启 
`include_req_body`|
   ```

##########
File path: t/plugin/kafka-logger.t
##########
@@ -1114,3 +1114,80 @@ GET /t
 --- error_log_like eval
 qr/create new kafka producer instance, brokers: 
\[\{"port":9092,"host":"127.0.0.127"}]/
 qr/failed to send data to Kafka topic: .*, brokers: \{"127.0.0.127":9092}/
+
+
+
+=== TEST 26: set route(id: 1,include_req_body = true,include_req_body_expr = 
array)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "plugins": {
+                            "kafka-logger": {
+                                "broker_list" :
+                                  {
+                                    "127.0.0.1":9092
+                                  },
+                                "kafka_topic" : "test2",
+                                "key" : "key1",
+                                "timeout" : 1,
+                                "include_req_body": true,
+                                "include_req_body_expr": [
+                                    [
+                                      "arg_name",
+                                      "==",
+                                      "qwerty"
+                                    ]
+                                ],
+                                "batch_max_size": 1
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/hello"
+                }]]
+                )
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+=== TEST 27: hit route, expr eval success
+--- request
+POST /hello?name=qwerty
+abcdef
+--- response_body
+hello world
+--- no_error_log
+[error]
+--- error_log eval
+qr/send data to kafka: \{.*"body":"abcdef"/
+--- wait: 2
+
+
+=== TEST 28: hit route,expr eval fail

Review comment:
       ```suggestion
   --- wait: 2
   
   
   
   === TEST 28: hit route,expr eval fail
   ```

##########
File path: docs/en/latest/plugins/kafka-logger.md
##########
@@ -57,6 +57,7 @@ For more info on Batch-Processor in Apache APISIX please 
refer.
 | max_retry_count  | integer | optional    | 0              | [0,...] | 
Maximum number of retries before removing from the processing pipe line.        
         |
 | retry_delay      | integer | optional    | 1              | [0,...] | Number 
of seconds the process execution should be delayed if the execution fails.      
  |
 | include_req_body | boolean | optional    | false          | [false, true] | 
Whether to include the request body. false: indicates that the requested body 
is not included; true: indicates that the requested body is included. |
+| include_req_body_expr  | array  | optional    |          |         | Whether 
to logging request body,based on 
[lua-resty-expr](https://github.com/api7/lua-resty-expr), this option require 
to turn on `include_req_body` option.             |

Review comment:
       ```suggestion
   | include_req_body_expr  | array  | optional    |          |         | 
Whether to logging request body, based on 
[lua-resty-expr](https://github.com/api7/lua-resty-expr), this option require 
to turn on `include_req_body` option.             |
   ```

##########
File path: t/plugin/kafka-logger.t
##########
@@ -1114,3 +1114,80 @@ GET /t
 --- error_log_like eval
 qr/create new kafka producer instance, brokers: 
\[\{"port":9092,"host":"127.0.0.127"}]/
 qr/failed to send data to Kafka topic: .*, brokers: \{"127.0.0.127":9092}/
+
+
+
+=== TEST 26: set route(id: 1,include_req_body = true,include_req_body_expr = 
array)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                        "plugins": {
+                            "kafka-logger": {
+                                "broker_list" :
+                                  {
+                                    "127.0.0.1":9092
+                                  },
+                                "kafka_topic" : "test2",
+                                "key" : "key1",
+                                "timeout" : 1,
+                                "include_req_body": true,
+                                "include_req_body_expr": [
+                                    [
+                                      "arg_name",
+                                      "==",
+                                      "qwerty"
+                                    ]
+                                ],
+                                "batch_max_size": 1
+                            }
+                        },
+                        "upstream": {
+                            "nodes": {
+                                "127.0.0.1:1980": 1
+                            },
+                            "type": "roundrobin"
+                        },
+                        "uri": "/hello"
+                }]]
+                )
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+=== TEST 27: hit route, expr eval success

Review comment:
       ```suggestion
   [error]
   
   
   
   === TEST 27: hit route, expr eval success
   ```




-- 
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]


Reply via email to