diff --git a/apisix/plugins/http-logger.lua b/apisix/plugins/http-logger.lua index d796eea2..e4e403c6 100644 --- a/apisix/plugins/http-logger.lua +++ b/apisix/plugins/http-logger.lua @@ -41,10 +41,7 @@ local schema = { type = "array", minItems = 1, items = { - type = "array", - items = { - type = "string" - } + type = "array" } }, concat_method = {type = "string", default = "json", diff --git a/apisix/plugins/kafka-logger.lua b/apisix/plugins/kafka-logger.lua index 5b6e9038..2947d145 100644 --- a/apisix/plugins/kafka-logger.lua +++ b/apisix/plugins/kafka-logger.lua @@ -69,10 +69,7 @@ local schema = { type = "array", minItems = 1, items = { - type = "array", - items = { - type = "string" - } + type = "array" } }, include_resp_body = {type = "boolean", default = false}, @@ -80,10 +77,7 @@ local schema = { type = "array", minItems = 1, items = { - type = "array", - items = { - type = "string" - } + type = "array" } }, -- in lua-resty-kafka, cluster_name is defined as number diff --git a/apisix/plugins/rocketmq-logger.lua b/apisix/plugins/rocketmq-logger.lua index 247c8488..447960ba 100644 --- a/apisix/plugins/rocketmq-logger.lua +++ b/apisix/plugins/rocketmq-logger.lua @@ -57,10 +57,7 @@ local schema = { type = "array", minItems = 1, items = { - type = "array", - items = { - type = "string" - } + type = "array" } }, include_resp_body = {type = "boolean", default = false}, @@ -68,10 +65,7 @@ local schema = { type = "array", minItems = 1, items = { - type = "array", - items = { - type = "string" - } + type = "array" } }, }, diff --git a/t/plugin/http-logger-log-format.t b/t/plugin/http-logger-log-format.t index 07978f5c..a9d05b27 100644 --- a/t/plugin/http-logger-log-format.t +++ b/t/plugin/http-logger-log-format.t @@ -433,3 +433,31 @@ qr/request log: \{.+\}/ --- grep_error_log_out eval qr/\Q{"client_ip":"127.0.0.1","consumer":{"username":"jack"},"latency":\E[^,]+\Q,"request":{"headers":{"apikey":"auth-one","connection":"close","host":"localhost"},"method":"GET","querystring":{},"size":\E\d+\Q,"uri":"\/hello","url":"http:\/\/localhost:1984\/hello"},"response":{"headers":{"connection":"close","content-length":"\E\d+\Q","content-type":"text\/plain","server":"\E[^"]+\Q"},"size":\E\d+\Q,"status":200},"route_id":"1","server":{"hostname":"\E[^"]+\Q","version":"\E[^"]+\Q"},"service_id":"","start_time":\E\d+\Q,"upstream":"127.0.0.1:1982"}\E/ --- wait: 0.5 + + + +=== TEST 14: multi level nested expr conditions +--- config + location /t { + content_by_lua_block { + local plugin = require("apisix.plugins.http-logger") + local ok, err = plugin.check_schema({ + uri = "http://127.0.0.1", + include_resp_body = true, + include_resp_body_expr = { + {"http_content_length", "<", 1024}, + {"http_content_type", "in", {"application/xml", "application/json", "text/plain", "text/xml"}} + } + }) + if not ok then + ngx.say(err) + end + ngx.say("done") + } + } +--- request +GET /t +--- response_body +done +--- no_error_log +[error] diff --git a/t/plugin/kafka-logger2.t b/t/plugin/kafka-logger2.t index 73ffec52..c78da6f5 100644 --- a/t/plugin/kafka-logger2.t +++ b/t/plugin/kafka-logger2.t @@ -609,3 +609,109 @@ hello world --- no_error_log eval qr/send data to kafka: \{.*"body":"hello world\\n"/ --- wait: 2 + + + +=== TEST 15: multi level nested expr conditions +--- config + location /t { + content_by_lua_block { + local core = require("apisix.core") + local t = require("lib.test_admin").test + local kafka = { + kafka_topic = "test2", + key = "key1", + batch_max_size = 1, + broker_list = { + ["127.0.0.1"] = 9092 + }, + timeout = 3, + include_req_body = true, + include_req_body_expr = { + {"request_length", "<", 1054}, + {"arg_name", "in", {"qwerty", "asdfgh"}} + }, + include_resp_body = true, + include_resp_body_expr = { + {"http_content_length", "<", 1054}, + {"arg_name", "in", {"qwerty", "zxcvbn"}} + } + } + local plugins = {} + plugins["kafka-logger"] = kafka + local data = { + plugins = plugins + } + data.upstream = { + type = "roundrobin", + nodes = { + ["127.0.0.1:1980"] = 1 + } + } + data.uri = "/hello" + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + core.json.encode(data) + ) + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- response_body +passed + + + +=== TEST 16: hit route, req_body_expr and resp_body_expr both eval success +--- request +POST /hello?name=qwerty +abcdef +--- response_body +hello world +--- error_log eval +[qr/send data to kafka: \{.*"body":"abcdef"/, +qr/send data to kafka: \{.*"body":"hello world\\n"/] +--- wait: 2 + + + +=== TEST 17: hit route, req_body_expr eval success, resp_body_expr both eval failed +--- request +POST /hello?name=asdfgh +abcdef +--- response_body +hello world +--- error_log eval +qr/send data to kafka: \{.*"body":"abcdef"/ +--- no_error_log eval +qr/send data to kafka: \{.*"body":"hello world\\n"/ +--- wait: 2 + + + +=== TEST 18: hit route, req_body_expr eval failed, resp_body_expr both eval success +--- request +POST /hello?name=zxcvbn +abcdef +--- response_body +hello world +--- error_log eval +qr/send data to kafka: \{.*"body":"hello world\\n"/ +--- no_error_log eval +qr/send data to kafka: \{.*"body":"abcdef"/ +--- wait: 2 + + + +=== TEST 19: hit route, req_body_expr eval success, resp_body_expr both eval failed +--- request +POST /hello?name=xxxxxx +abcdef +--- response_body +hello world +--- no_error_log eval +[qr/send data to kafka: \{.*"body":"abcdef"/, +qr/send data to kafka: \{.*"body":"hello world\\n"/] +--- wait: 2 diff --git a/t/plugin/rocketmq-logger2.t b/t/plugin/rocketmq-logger2.t index fcc378b7..286d3cad 100644 --- a/t/plugin/rocketmq-logger2.t +++ b/t/plugin/rocketmq-logger2.t @@ -412,3 +412,36 @@ hello world --- no_error_log eval qr/send data to rocketmq: \{.*"body":"hello world\\n"/ --- wait: 2 + + + +=== TEST 13: multi level nested expr conditions +--- config + location /t { + content_by_lua_block { + local plugin = require("apisix.plugins.rocketmq-logger") + local ok, err = plugin.check_schema({ + topic = "test", + key = "key1", + nameserver_list = { + "127.0.0.1:3" + }, + include_req_body = true, + include_req_body_expr = { + {"request_length", "<", 1024}, + {"http_content_type", "in", {"application/xml", "application/json", "text/plain", "text/xml"}} + }, + include_resp_body = true, + include_resp_body_expr = { + {"http_content_length", "<", 1024}, + {"http_content_type", "in", {"application/xml", "application/json", "text/plain", "text/xml"}} + } + }) + if not ok then + ngx.say(err) + end + ngx.say("done") + } + } +--- response_body +done