This is an automated email from the ASF dual-hosted git repository.
monkeydluffy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 07c4aa3a4 feat: add option to include request body and response body
in log util (#10888)
07c4aa3a4 is described below
commit 07c4aa3a4287b4a829b76ae529705b51de56f8aa
Author: baiyun <[email protected]>
AuthorDate: Fri Feb 2 11:13:10 2024 +0800
feat: add option to include request body and response body in log util
(#10888)
---
apisix/plugins/elasticsearch-logger.lua | 23 ++++++-
apisix/plugins/skywalking-logger.lua | 20 ++++++
apisix/plugins/sls-logger.lua | 23 ++++++-
apisix/plugins/syslog.lua | 22 +++++-
apisix/plugins/syslog/init.lua | 2 +-
apisix/plugins/tcp-logger.lua | 23 ++++++-
apisix/plugins/udp-logger.lua | 23 ++++++-
docs/en/latest/plugins/elasticsearch-logger.md | 4 ++
docs/en/latest/plugins/skywalking-logger.md | 3 +
docs/en/latest/plugins/sls-logger.md | 3 +
docs/en/latest/plugins/syslog.md | 5 +-
docs/en/latest/plugins/tcp-logger.md | 5 +-
docs/en/latest/plugins/udp-logger.md | 5 +-
docs/zh/latest/plugins/elasticsearch-logger.md | 4 ++
docs/zh/latest/plugins/loggly.md | 1 +
docs/zh/latest/plugins/skywalking-logger.md | 3 +
docs/zh/latest/plugins/sls-logger.md | 3 +
docs/zh/latest/plugins/syslog.md | 5 +-
docs/zh/latest/plugins/tcp-logger.md | 5 +-
docs/zh/latest/plugins/tencent-cloud-cls.md | 2 +
docs/zh/latest/plugins/udp-logger.md | 5 +-
t/plugin/elasticsearch-logger.t | 81 +++++++++++++++++++++++
t/plugin/skywalking-logger.t | 92 +++++++++++++++++++++++++-
t/plugin/sls-logger.t | 87 ++++++++++++++++++++++++
t/plugin/syslog.t | 92 ++++++++++++++++++++++++++
t/plugin/tcp-logger.t | 88 ++++++++++++++++++++++++
t/plugin/udp-logger.t | 92 ++++++++++++++++++++++++++
27 files changed, 708 insertions(+), 13 deletions(-)
diff --git a/apisix/plugins/elasticsearch-logger.lua
b/apisix/plugins/elasticsearch-logger.lua
index 81fdc157d..38bc884ed 100644
--- a/apisix/plugins/elasticsearch-logger.lua
+++ b/apisix/plugins/elasticsearch-logger.lua
@@ -75,7 +75,23 @@ local schema = {
ssl_verify = {
type = "boolean",
default = true
- }
+ },
+ include_req_body = {type = "boolean", default = false},
+ include_req_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
+ include_resp_body = { type = "boolean", default = false },
+ include_resp_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
},
encrypt_fields = {"auth.password"},
oneOf = {
@@ -171,6 +187,11 @@ local function send_to_elasticsearch(conf, entries)
end
+function _M.body_filter(conf, ctx)
+ log_util.collect_body(conf, ctx)
+end
+
+
function _M.log(conf, ctx)
local entry = get_logger_entry(conf, ctx)
diff --git a/apisix/plugins/skywalking-logger.lua
b/apisix/plugins/skywalking-logger.lua
index 136b9dec1..94ba65534 100644
--- a/apisix/plugins/skywalking-logger.lua
+++ b/apisix/plugins/skywalking-logger.lua
@@ -39,6 +39,21 @@ local schema = {
log_format = {type = "object"},
timeout = {type = "integer", minimum = 1, default = 3},
include_req_body = {type = "boolean", default = false},
+ include_req_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
+ include_resp_body = { type = "boolean", default = false },
+ include_resp_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
},
required = {"endpoint_addr"},
}
@@ -116,6 +131,11 @@ local function send_http_data(conf, log_message)
end
+function _M.body_filter(conf, ctx)
+ log_util.collect_body(conf, ctx)
+end
+
+
function _M.log(conf, ctx)
local log_body = log_util.get_log_entry(plugin_name, conf, ctx)
local trace_context
diff --git a/apisix/plugins/sls-logger.lua b/apisix/plugins/sls-logger.lua
index de2fbae67..114a20969 100644
--- a/apisix/plugins/sls-logger.lua
+++ b/apisix/plugins/sls-logger.lua
@@ -33,6 +33,21 @@ local schema = {
type = "object",
properties = {
include_req_body = {type = "boolean", default = false},
+ include_req_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
+ include_resp_body = { type = "boolean", default = false },
+ include_resp_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
timeout = {type = "integer", minimum = 1, default= 5000},
log_format = {type = "object"},
host = {type = "string"},
@@ -129,6 +144,12 @@ local function handle_log(entries)
return send_tcp_data(entries[1].route_conf, data)
end
+
+function _M.body_filter(conf, ctx)
+ log_util.collect_body(conf, ctx)
+end
+
+
-- log phase in APISIX
function _M.log(conf, ctx)
local entry = log_util.get_log_entry(plugin_name, conf, ctx)
@@ -146,7 +167,7 @@ function _M.log(conf, ctx)
}
local rf5424_data = rf5424.encode("SYSLOG", "INFO", ctx.var.host, "apisix",
ctx.var.pid, json_str, structured_data)
-
+ core.log.info("collect_data:" .. rf5424_data)
local process_context = {
data = rf5424_data,
route_conf = conf
diff --git a/apisix/plugins/syslog.lua b/apisix/plugins/syslog.lua
index 155ea7b41..fa160feeb 100644
--- a/apisix/plugins/syslog.lua
+++ b/apisix/plugins/syslog.lua
@@ -34,7 +34,22 @@ local schema = {
pool_size = {type = "integer", minimum = 5, default = 5},
tls = {type = "boolean", default = false},
log_format = {type = "object"},
- include_req_body = {type = "boolean", default = false}
+ include_req_body = {type = "boolean", default = false},
+ include_req_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
+ include_resp_body = { type = "boolean", default = false },
+ include_resp_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
},
required = {"host", "port"}
}
@@ -69,6 +84,11 @@ function _M.check_schema(conf, schema_type)
end
+function _M.body_filter(conf, ctx)
+ log_util.collect_body(conf, ctx)
+end
+
+
function _M.log(conf, ctx)
local entry = log_util.get_log_entry(plugin_name, conf, ctx)
syslog.push_entry(conf, ctx, entry)
diff --git a/apisix/plugins/syslog/init.lua b/apisix/plugins/syslog/init.lua
index 0ab34f805..8a3d90e38 100644
--- a/apisix/plugins/syslog/init.lua
+++ b/apisix/plugins/syslog/init.lua
@@ -88,7 +88,7 @@ function _M.push_entry(conf, ctx, entry)
local rfc5424_data = rfc5424.encode("SYSLOG", "INFO", ctx.var.host,
"apisix", ctx.var.pid, json_str)
-
+ core.log.info("collect_data:" .. rfc5424_data)
if batch_processor_manager:add_entry(conf, rfc5424_data) then
return
end
diff --git a/apisix/plugins/tcp-logger.lua b/apisix/plugins/tcp-logger.lua
index 444afe1d9..e95ba9339 100644
--- a/apisix/plugins/tcp-logger.lua
+++ b/apisix/plugins/tcp-logger.lua
@@ -33,7 +33,22 @@ local schema = {
tls_options = {type = "string"},
timeout = {type = "integer", minimum = 1, default= 1000},
log_format = {type = "object"},
- include_req_body = {type = "boolean", default = false}
+ include_req_body = {type = "boolean", default = false},
+ include_req_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
+ include_resp_body = { type = "boolean", default = false },
+ include_resp_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
},
required = {"host", "port"}
}
@@ -77,6 +92,7 @@ local function send_tcp_data(conf, log_message)
sock:settimeout(conf.timeout)
core.log.info("sending a batch logs to ", conf.host, ":", conf.port)
+ core.log.info("sending log_message: ", log_message)
local ok, err = sock:connect(conf.host, conf.port)
if not ok then
@@ -109,6 +125,11 @@ local function send_tcp_data(conf, log_message)
end
+function _M.body_filter(conf, ctx)
+ log_util.collect_body(conf, ctx)
+end
+
+
function _M.log(conf, ctx)
local entry = log_util.get_log_entry(plugin_name, conf, ctx)
diff --git a/apisix/plugins/udp-logger.lua b/apisix/plugins/udp-logger.lua
index 7d76a4b02..75e8bba31 100644
--- a/apisix/plugins/udp-logger.lua
+++ b/apisix/plugins/udp-logger.lua
@@ -31,7 +31,22 @@ local schema = {
port = {type = "integer", minimum = 0},
timeout = {type = "integer", minimum = 1, default = 3},
log_format = {type = "object"},
- include_req_body = {type = "boolean", default = false}
+ include_req_body = {type = "boolean", default = false},
+ include_req_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
+ include_resp_body = { type = "boolean", default = false },
+ include_resp_body_expr = {
+ type = "array",
+ minItems = 1,
+ items = {
+ type = "array"
+ }
+ },
},
required = {"host", "port"}
}
@@ -70,6 +85,7 @@ local function send_udp_data(conf, log_message)
sock:settimeout(conf.timeout * 1000)
core.log.info("sending a batch logs to ", conf.host, ":", conf.port)
+ core.log.info("sending log_message: ", log_message)
local ok, err = sock:setpeername(conf.host, conf.port)
@@ -95,6 +111,11 @@ local function send_udp_data(conf, log_message)
end
+function _M.body_filter(conf, ctx)
+ log_util.collect_body(conf, ctx)
+end
+
+
function _M.log(conf, ctx)
local entry = log_util.get_log_entry(plugin_name, conf, ctx)
diff --git a/docs/en/latest/plugins/elasticsearch-logger.md
b/docs/en/latest/plugins/elasticsearch-logger.md
index 06f70354f..098dc27d3 100644
--- a/docs/en/latest/plugins/elasticsearch-logger.md
+++ b/docs/en/latest/plugins/elasticsearch-logger.md
@@ -48,6 +48,10 @@ When the Plugin is enabled, APISIX will serialize the
request context informatio
| auth.password | string | True | |
Elasticsearch
[authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html)
password. |
| ssl_verify | boolean | False | true | When set
to `true` enables SSL verification as per [OpenResty
docs](https://github.com/openresty/lua-nginx-module#tcpsocksslhandshake). |
| timeout | integer | False | 10 |
Elasticsearch send data timeout in seconds. |
+| include_req_body | boolean | False | false | When set to
`true` includes the request body in the log. If the request body is too big to
be kept in the memory, it can't be logged due to Nginx's limitations.
|
+| include_req_body_expr | array | False | | Filter for
when the `include_req_body` attribute is set to `true`. Request body is only
logged when the expression set here evaluates to `true`. See
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more. |
+| include_resp_body | boolean | False | false | When set to
`true` includes the response body in the log.
|
+| include_resp_body_expr | array | False | | When the
`include_resp_body` attribute is set to `true`, use this to filter based on
[lua-resty-expr](https://github.com/api7/lua-resty-expr). If present, only logs
the response if the expression evaluates to `true`. |
NOTE: `encrypt_fields = {"auth.password"}` is also defined in the schema,
which means that the field will be stored encrypted in etcd. See [encrypted
storage fields](../plugin-develop.md#encrypted-storage-fields).
diff --git a/docs/en/latest/plugins/skywalking-logger.md
b/docs/en/latest/plugins/skywalking-logger.md
index b72ec5577..7150c0bb2 100644
--- a/docs/en/latest/plugins/skywalking-logger.md
+++ b/docs/en/latest/plugins/skywalking-logger.md
@@ -44,6 +44,9 @@ If there is an existing tracing context, it sets up the
trace-log correlation au
| timeout | integer | False | 3 |
[1,...] | Time to keep the connection alive for after sending a request.
|
| name | string | False | "skywalking logger" |
| Unique identifier to identify the logger. If you use Prometheus to
monitor APISIX metrics, the name is exported in `apisix_batch_process_entries`.
|
| include_req_body | boolean | False | false |
[false, true] | When set to `true` includes the request body in the log.
|
+| include_req_body_expr | array | False | |
| Filter for when the `include_req_body` attribute is set to `true`. Request
body is only logged when the expression set here evaluates to `true`. See
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more. |
+| include_resp_body | boolean | False | false | [false, true]
| When set to `true` includes the response body in the log.
|
+| include_resp_body_expr | array | False | |
| When the `include_resp_body` attribute is set to `true`, use this to filter
based on [lua-resty-expr](https://github.com/api7/lua-resty-expr). If present,
only logs the response if the expression evaluates to `true`. |
This Plugin supports using batch processors to aggregate and process entries
(logs/data) in a batch. This avoids the need for frequently submitting the
data. The batch processor submits data every `5` seconds or when the data in
the queue reaches `1000`. See [Batch
Processor](../batch-processor.md#configuration) for more information or setting
your custom configuration.
diff --git a/docs/en/latest/plugins/sls-logger.md
b/docs/en/latest/plugins/sls-logger.md
index 47dc9449b..94199a856 100644
--- a/docs/en/latest/plugins/sls-logger.md
+++ b/docs/en/latest/plugins/sls-logger.md
@@ -46,6 +46,9 @@ It might take some time to receive the log data. It will be
automatically sent a
| access_key_id | True | AccessKey ID in Alibaba Cloud. See
[Authorization](https://www.alibabacloud.com/help/en/log-service/latest/create-a-ram-user-and-authorize-the-ram-user-to-access-log-service)
for more details.
|
| access_key_secret | True | AccessKey Secret in Alibaba Cloud. See
[Authorization](https://www.alibabacloud.com/help/en/log-service/latest/create-a-ram-user-and-authorize-the-ram-user-to-access-log-service)
for more details.
|
| include_req_body | True | When set to `true`, includes the request body
in the log.
|
+| include_req_body_expr | No | Filter for when the `include_req_body`
attribute is set to `true`. Request body is only logged when the expression set
here evaluates to `true`. See
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more.
|
+| include_resp_body | No | When set to `true` includes the response body in
the log.
|
+| include_resp_body_expr | No | Filter for when the `include_resp_body`
attribute is set to `true`. Response body is only logged when the expression
set here evaluates to `true`. See
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more.
|
| name | False | Unique identifier for the batch processor. If
you use Prometheus to monitor APISIX metrics, the name is exported in
`apisix_batch_process_entries`.
|
NOTE: `encrypt_fields = {"access_key_secret"}` is also defined in the schema,
which means that the field will be stored encrypted in etcd. See [encrypted
storage fields](../plugin-develop.md#encrypted-storage-fields).
diff --git a/docs/en/latest/plugins/syslog.md b/docs/en/latest/plugins/syslog.md
index 1a7e5e4a8..11142807d 100644
--- a/docs/en/latest/plugins/syslog.md
+++ b/docs/en/latest/plugins/syslog.md
@@ -46,7 +46,10 @@ Logs can be set as JSON objects.
| sock_type | string | False | "tcp" | ["tcp", "udp] |
Transport layer protocol to use.
|
| pool_size | integer | False | 5 | [5, ...] |
Keep-alive pool size used by `sock:keepalive`.
|
| log_format | object | False | | | Log format
declared as key value pairs in JSON format. Values only support strings.
[APISIX](../apisix-variable.md) or
[Nginx](http://nginx.org/en/docs/varindex.html) variables can be used by
prefixing the string with `$`. |
-| include_req_body | boolean | False | false | | When
set to `true` includes the request body in the log.
|
+| include_req_body | boolean | False | false | [false, true] | When
set to `true` includes the request body in the log.
|
+| include_req_body_expr | array | False | |
| Filter for when the `include_req_body` attribute is set to `true`. Request
body is only logged when the expression set here evaluates to `true`. See
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more. |
+| include_resp_body | boolean | False | false | [false, true]
| When set to `true` includes the response body in the log.
|
+| include_resp_body_expr | array | False | |
| When the `include_resp_body` attribute is set to `true`, use this to filter
based on [lua-resty-expr](https://github.com/api7/lua-resty-expr). If present,
only logs the response if the expression evaluates to `true`. |
This Plugin supports using batch processors to aggregate and process entries
(logs/data) in a batch. This avoids the need for frequently submitting the
data. The batch processor submits data every `5` seconds or when the data in
the queue reaches `1000`. See [Batch
Processor](../batch-processor.md#configuration) for more information or setting
your custom configuration.
diff --git a/docs/en/latest/plugins/tcp-logger.md
b/docs/en/latest/plugins/tcp-logger.md
index e5bffac35..b163029cd 100644
--- a/docs/en/latest/plugins/tcp-logger.md
+++ b/docs/en/latest/plugins/tcp-logger.md
@@ -46,7 +46,10 @@ This plugin also allows to push logs as a batch to your
external TCP server. It
| log_format | object | False | | | Log format
declared as key value pairs in JSON format. Values only support strings.
[APISIX](../apisix-variable.md) or
[Nginx](http://nginx.org/en/docs/varindex.html) variables can be used by
prefixing the string with `$`. |
| tls | boolean | False | false | | When set to
`true` performs SSL verification. |
| tls_options | string | False | | | TLS
options. |
-| include_req_body | boolean | False | false | | When set to
`true` includes the request body in the log. |
+| include_req_body | boolean | False | false | [false, true] | When set
to `true` includes the request body in the log. |
+| include_req_body_expr | array | No | | |
Filter for when the `include_req_body` attribute is set to `true`. Request body
is only logged when the expression set here evaluates to `true`. See
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more.
|
+| include_resp_body | boolean | No | false | [false, true] | When set
to `true` includes the response body in the log.
|
+| include_resp_body_expr | array | No | | | Filter
for when the `include_resp_body` attribute is set to `true`. Response body is
only logged when the expression set here evaluates to `true`. See
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more.
|
This Plugin supports using batch processors to aggregate and process entries
(logs/data) in a batch. This avoids the need for frequently submitting the
data. The batch processor submits data every `5` seconds or when the data in
the queue reaches `1000`. See [Batch
Processor](../batch-processor.md#configuration) for more information or setting
your custom configuration.
diff --git a/docs/en/latest/plugins/udp-logger.md
b/docs/en/latest/plugins/udp-logger.md
index e3acd0030..9af8c98de 100644
--- a/docs/en/latest/plugins/udp-logger.md
+++ b/docs/en/latest/plugins/udp-logger.md
@@ -44,7 +44,10 @@ This plugin also allows to push logs as a batch to your
external UDP server. It
| timeout | integer | False | 3 | [1,...] |
Timeout for the upstream to send data. |
| log_format | object | False | | | Log format
declared as key value pairs in JSON format. Values only support strings.
[APISIX](../apisix-variable.md) or
[Nginx](http://nginx.org/en/docs/varindex.html) variables can be used by
prefixing the string with `$`. |
| name | string | False | "udp logger" | | Unique
identifier for the batch processor. If you use Prometheus to monitor APISIX
metrics, the name is exported in `apisix_batch_process_entries`. processor.
|
-| include_req_body | boolean | False | false | | When
set to `true` includes the request body in the log. |
+| include_req_body | boolean | False | false | [false, true] | When
set to `true` includes the request body in the log. |
+| include_req_body_expr | array | No | | |
Filter for when the `include_req_body` attribute is set to `true`. Request body
is only logged when the expression set here evaluates to `true`. See
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more.
|
+| include_resp_body | boolean | No | false | [false, true] | When set
to `true` includes the response body in the log.
|
+| include_resp_body_expr | array | No | | | Filter
for when the `include_resp_body` attribute is set to `true`. Response body is
only logged when the expression set here evaluates to `true`. See
[lua-resty-expr](https://github.com/api7/lua-resty-expr) for more.
|
This Plugin supports using batch processors to aggregate and process entries
(logs/data) in a batch. This avoids the need for frequently submitting the
data. The batch processor submits data every `5` seconds or when the data in
the queue reaches `1000`. See [Batch
Processor](../batch-processor.md#configuration) for more information or setting
your custom configuration.
diff --git a/docs/zh/latest/plugins/elasticsearch-logger.md
b/docs/zh/latest/plugins/elasticsearch-logger.md
index d97311b17..7b0022e29 100644
--- a/docs/zh/latest/plugins/elasticsearch-logger.md
+++ b/docs/zh/latest/plugins/elasticsearch-logger.md
@@ -49,6 +49,10 @@ description: 本文介绍了 API 网关 Apache APISIX 的
elasticsearch-logger
| auth.password | string | 是 | | Elasticsearch
[authentication](https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html)
密码。 |
| ssl_verify | boolean | 否 | true | 当设置为 `true` 时则启用
SSL 验证。更多信息请参考
[lua-nginx-module](https://github.com/openresty/lua-nginx-module#tcpsocksslhandshake)。
|
| timeout | integer | 否 | 10 | 发送给 Elasticsearch
请求超时时间。 |
+| include_req_body | boolean | 否 | false | 当设置为 `true`
时,包含请求体。**注意**:如果请求体无法完全存放在内存中,由于 NGINX 的限制,APISIX 无法将它记录下来。 |
+| include_req_body_expr | array | 否 | | 当 `include_req_body`
属性设置为 `true` 时的过滤器。只有当此处设置的表达式求值为 `true` 时,才会记录请求体。有关更多信息,请参阅
[lua-resty-expr](https://github.com/api7/lua-resty-expr) 。 |
+| include_resp_body | boolean | 否 | false | 当设置为 `true` 时,包含响应体。
|
+| include_resp_body_expr | array | 否 | | 当
`include_resp_body` 属性设置为 `true` 时进行过滤响应体,并且只有当此处设置的表达式计算结果为 `true`
时,才会记录响应体。更多信息,请参考 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。 |
注意:schema 中还定义了 `encrypt_fields = {"auth.password"}`,这意味着该字段将会被加密存储在 etcd
中。具体参考 [加密存储字段](../plugin-develop.md#加密存储字段)。
diff --git a/docs/zh/latest/plugins/loggly.md b/docs/zh/latest/plugins/loggly.md
index 27d813c4a..5bf92cf5a 100644
--- a/docs/zh/latest/plugins/loggly.md
+++ b/docs/zh/latest/plugins/loggly.md
@@ -43,6 +43,7 @@ description: API 网关 Apache APISIX loggly 插件可用于将日志转发到 S
| tags | array | 否 | |
元数据将包含在任何事件日志中,以帮助进行分段和过滤。
|
| log_format | object | 否 | | | 以 JSON
格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 [APISIX
变量](../apisix-variable.md) 或 [NGINX
内置变量](http://nginx.org/en/docs/varindex.html)。 |
| include_req_body | boolean | 否 | false | 当设置为 `true`
时,包含请求体。**注意**:如果请求体无法完全存放在内存中,由于 NGINX 的限制,APISIX 无法将它记录下来。 |
+| include_req_body_expr | array | 否 | | 当 `include_req_body`
属性设置为 `true` 时的过滤器。只有当此处设置的表达式求值为 `true` 时,才会记录请求体。有关更多信息,请参阅
[lua-resty-expr](https://github.com/api7/lua-resty-expr) 。 |
| include_resp_body | boolean | 否 | false | 当设置为 `true`
时,包含响应体。 |
| include_resp_body_expr | array | 否 | | 当
`include_resp_body` 属性设置为 `true` 时进行过滤响应体,并且只有当此处设置的表达式计算结果为 `true`
时,才会记录响应体。更多信息,请参考 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。 |
diff --git a/docs/zh/latest/plugins/skywalking-logger.md
b/docs/zh/latest/plugins/skywalking-logger.md
index 87cabb3b4..8ef741758 100644
--- a/docs/zh/latest/plugins/skywalking-logger.md
+++ b/docs/zh/latest/plugins/skywalking-logger.md
@@ -46,6 +46,9 @@ description: 本文将介绍 API 网关 Apache APISIX 如何通过 skywalking-lo
| timeout | integer | 否 | 3 | [1,...]
| 发送请求后保持连接活动的时间。 |
| name | string | 否 | "skywalking logger" |
| 标识 logger 的唯一标识符。如果您使用 Prometheus 监视 APISIX 指标,名称将以
`apisix_batch_process_entries` 导出。 |
| include_req_body | boolean | 否 | false | [false,
true] | 当设置为 `true` 时,将请求正文包含在日志中。 |
+| include_req_body_expr | array | 否 | | | 当
`include_req_body` 属性设置为 `true` 时的过滤器。只有当此处设置的表达式求值为 `true`
时,才会记录请求体。有关更多信息,请参阅 [lua-resty-expr](https://github.com/api7/lua-resty-expr) 。
|
+| include_resp_body | boolean | 否 | false | [false, true] | 当设置为
`true` 时,包含响应体。
|
+| include_resp_body_expr | array | 否 | | | 当
`include_resp_body` 属性设置为 `true` 时进行过滤响应体,并且只有当此处设置的表达式计算结果为 `true`
时,才会记录响应体。更多信息,请参考 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。 |
该插件支持使用批处理器来聚合并批量处理条目(日志/数据)。这样可以避免插件频繁地提交数据,默认设置情况下批处理器会每 `5` 秒钟或队列中的数据达到
`1000` 条时提交数据,如需了解批处理器相关参数设置,请参考 [Batch-Processor](../batch-processor.md#配置)。
diff --git a/docs/zh/latest/plugins/sls-logger.md
b/docs/zh/latest/plugins/sls-logger.md
index 7bd85c81b..64613a34a 100644
--- a/docs/zh/latest/plugins/sls-logger.md
+++ b/docs/zh/latest/plugins/sls-logger.md
@@ -43,6 +43,9 @@ title: sls-logger
| access_key_id | 必须的 | AccessKey ID。建议使用阿里云子账号 AK,详情请参见
[授权](https://help.aliyun.com/document_detail/47664.html?spm=a2c4g.11186623.2.15.49301b47lfvxXP#task-xsk-ttc-ry)。|
| access_key_secret | 必须的 | AccessKey Secret。建议使用阿里云子账号 AK,详情请参见
[授权](https://help.aliyun.com/document_detail/47664.html?spm=a2c4g.11186623.2.15.49301b47lfvxXP#task-xsk-ttc-ry)。|
| include_req_body | 可选的 | 是否包含请求体。|
+| include_req_body_expr | 可选的 | 当 `include_req_body` 属性设置为 `true`
时的过滤器。只有当此处设置的表达式求值为 `true` 时,才会记录请求体。有关更多信息,请参阅
[lua-resty-expr](https://github.com/api7/lua-resty-expr) 。 |
+| include_resp_body | 可选的 | 当设置为 `true` 时,日志中将包含响应体。
|
+| include_resp_body_expr | 可选的 | 当 `include_resp_body` 属性设置为 `true`
时进行过滤响应体,并且只有当此处设置的表达式计算结果为 `true` 时,才会记录响应体。更多信息,请参考
[lua-resty-expr](https://github.com/api7/lua-resty-expr)。 |
|name| 可选的 | 批处理名字。如果您使用 Prometheus 监视 APISIX 指标,名称将以
`apisix_batch_process_entries` 导出。|
注意:schema 中还定义了 `encrypt_fields = {"access_key_secret"}`,这意味着该字段将会被加密存储在 etcd
中。具体参考 [加密存储字段](../plugin-develop.md#加密存储字段)。
diff --git a/docs/zh/latest/plugins/syslog.md b/docs/zh/latest/plugins/syslog.md
index 4707bba8b..fd847f122 100644
--- a/docs/zh/latest/plugins/syslog.md
+++ b/docs/zh/latest/plugins/syslog.md
@@ -49,7 +49,10 @@ description: API 网关 Apache APISIX syslog 插件可用于将日志推送到 S
| retry_delay | integer | 否 | | [0, ...] |
重试连接到日志服务器或重试向日志服务器发送日志消息之前的时间延迟(以毫秒为单位)。
|
| pool_size | integer | 否 | 5 | [5, ...] |
`sock:keepalive` 使用的 Keepalive 池大小。
|
| log_format | object | 否 | | | 以 JSON
格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 [APISIX
变量](../apisix-variable.md) 或 [NGINX
内置变量](http://nginx.org/en/docs/varindex.html)。 |
-| include_req_body | boolean | 否 | false | | 当设置为
`true` 时包括请求体。
|
+| include_req_body | boolean | 否 | false | [false, true] | 当设置为
`true` 时包括请求体。
|
+| include_req_body_expr | array | 否 | | | 当
`include_req_body` 属性设置为 `true` 时的过滤器。只有当此处设置的表达式求值为 `true`
时,才会记录请求体。有关更多信息,请参阅 [lua-resty-expr](https://github.com/api7/lua-resty-expr) 。
|
+| include_resp_body | boolean | 否 | false | [false, true] | 当设置为
`true` 时,包含响应体。
|
+| include_resp_body_expr | array | 否 | | | 当
`include_resp_body` 属性设置为 `true` 时进行过滤响应体,并且只有当此处设置的表达式计算结果为 `true`
时,才会记录响应体。更多信息,请参考 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。 |
该插件支持使用批处理器来聚合并批量处理条目(日志/数据)。这样可以避免插件频繁地提交数据,默认情况下批处理器每 `5` 秒钟或队列中的数据达到 `1000`
条时提交数据,如需了解批处理器相关参数设置,请参考 [Batch-Processor](../batch-processor.md#配置)。
diff --git a/docs/zh/latest/plugins/tcp-logger.md
b/docs/zh/latest/plugins/tcp-logger.md
index 3984fb1d4..17203a3e5 100644
--- a/docs/zh/latest/plugins/tcp-logger.md
+++ b/docs/zh/latest/plugins/tcp-logger.md
@@ -43,7 +43,10 @@ description: 本文介绍了 API 网关 Apache APISIX 如何使用 tcp-logger
| log_format | object | 否 | | | 以 JSON
格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 [APISIX
变量](../apisix-variable.md) 或 [NGINX
内置变量](http://nginx.org/en/docs/varindex.html)。 |
| tls | boolean | 否 | false | | 用于控制是否执行 SSL 验证。
|
| tls_options | string | 否 | | | TLS 选项。
|
-| include_req_body | boolean | 否 | | | 当设置为 `true`
时,日志中将包含请求体。 |
+| include_req_body | boolean | 否 | | [false, true] | 当设置为 `true`
时,日志中将包含请求体。 |
+| include_req_body_expr | array | 否 | | | 当 `include_req_body`
属性设置为 `true` 时的过滤器。只有当此处设置的表达式求值为 `true` 时,才会记录请求体。有关更多信息,请参阅
[lua-resty-expr](https://github.com/api7/lua-resty-expr) 。 |
+| include_resp_body | boolean | 否 | false | [false, true]| 当设置为 `true`
时,日志中将包含响应体。 |
+| include_resp_body_expr | array | 否 | | | 当
`include_resp_body` 属性设置为 `true` 时进行过滤响应体,并且只有当此处设置的表达式计算结果为 `true`
时,才会记录响应体。更多信息,请参考 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。 |
该插件支持使用批处理器来聚合并批量处理条目(日志/数据)。这样可以避免插件频繁地提交数据,默认情况下批处理器每 `5` 秒钟或队列中的数据达到 `1000`
条时提交数据,如需了解批处理器相关参数设置,请参考 [Batch-Processor](../batch-processor.md#配置)。
diff --git a/docs/zh/latest/plugins/tencent-cloud-cls.md
b/docs/zh/latest/plugins/tencent-cloud-cls.md
index 88bff5b06..0e45141d3 100644
--- a/docs/zh/latest/plugins/tencent-cloud-cls.md
+++ b/docs/zh/latest/plugins/tencent-cloud-cls.md
@@ -42,7 +42,9 @@ description: API 网关 Apache APISIX tencent-cloud-cls 插件可用于将日志
| secret_key | string | 是 | | | 云 API 密钥的 key。
|
| sample_ratio | number | 否 | 1 | [0.00001, 1] | 采样的比例。设置为 `1`
时,将对所有请求进行采样。 |
| include_req_body | boolean | 否 | false | [false, true]| 当设置为 `true`
时,日志中将包含请求体。 |
+| include_req_body_expr | array | 否 | | | 当 `include_req_body`
属性设置为 `true` 时的过滤器。只有当此处设置的表达式求值为 `true` 时,才会记录请求体。有关更多信息,请参阅
[lua-resty-expr](https://github.com/api7/lua-resty-expr) 。 |
| include_resp_body | boolean | 否 | false | [false, true]| 当设置为 `true`
时,日志中将包含响应体。 |
+| include_resp_body_expr | array | 否 | | | 当
`include_resp_body` 属性设置为 `true` 时进行过滤响应体,并且只有当此处设置的表达式计算结果为 `true`
时,才会记录响应体。更多信息,请参考 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。 |
| global_tag | object | 否 | | | kv 形式的 JSON
数据,可以写入每一条日志,便于在 CLS 中检索。 |
| log_format | object | 否 | | | 以 JSON
格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 [APISIX
变量](../apisix-variable.md) 或 [NGINX
内置变量](http://nginx.org/en/docs/varindex.html)。 |
diff --git a/docs/zh/latest/plugins/udp-logger.md
b/docs/zh/latest/plugins/udp-logger.md
index 00f00d641..a8ca60778 100644
--- a/docs/zh/latest/plugins/udp-logger.md
+++ b/docs/zh/latest/plugins/udp-logger.md
@@ -42,7 +42,10 @@ description: 本文介绍了 API 网关 Apache APISIX 如何使用 udp-logger
| timeout | integer | 否 | 1000 | [1,...] | 发送数据超时间。
|
| log_format | object | 否 | | | 以 JSON
格式的键值对来声明日志格式。对于值部分,仅支持字符串。如果是以 `$` 开头,则表明是要获取 [APISIX
变量](../apisix-variable.md) 或 [NGINX
内置变量](http://nginx.org/en/docs/varindex.html)。 |
| name | string | 否 | "udp logger" | | 标识 logger
的唯一标识符。如果您使用 Prometheus 监视 APISIX 指标,名称将以 `apisix_batch_process_entries` 导出。
|
-| include_req_body | boolean | 否 | | | 当设置为 `true`
时,日志中将包含请求体。 |
+| include_req_body | boolean | 否 | | [false, true] | 当设置为
`true` 时,日志中将包含请求体。 |
+| include_req_body_expr | array | 否 | | | 当 `include_req_body`
属性设置为 `true` 时的过滤器。只有当此处设置的表达式求值为 `true` 时,才会记录请求体。有关更多信息,请参阅
[lua-resty-expr](https://github.com/api7/lua-resty-expr) 。 |
+| include_resp_body | boolean | 否 | false | [false, true]| 当设置为 `true`
时,日志中将包含响应体。 |
+| include_resp_body_expr | array | 否 | | | 当
`include_resp_body` 属性设置为 `true` 时进行过滤响应体,并且只有当此处设置的表达式计算结果为 `true`
时,才会记录响应体。更多信息,请参考 [lua-resty-expr](https://github.com/api7/lua-resty-expr)。 |
该插件支持使用批处理器来聚合并批量处理条目(日志和数据)。这样可以避免插件频繁地提交数据,默认情况下批处理器每 `5` 秒钟或队列中的数据达到 `1000`
条时提交数据,如需了解批处理器相关参数设置,请参考 [Batch-Processor](../batch-processor.md#配置)。
diff --git a/t/plugin/elasticsearch-logger.t b/t/plugin/elasticsearch-logger.t
index 40ac5f2e2..83960fbac 100644
--- a/t/plugin/elasticsearch-logger.t
+++ b/t/plugin/elasticsearch-logger.t
@@ -720,3 +720,84 @@ GET /hello
hello world
--- no_error_log
Action/metadata line [1] contains an unknown parameter [_type]
+
+
+
+=== TEST 19: add plugin with 'include_req_body' setting, collect request log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/elasticsearch-logger',
ngx.HTTP_DELETE)
+
+ local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, {
+ uri = "/hello",
+ upstream = {
+ type = "roundrobin",
+ nodes = {
+ ["127.0.0.1:1980"] = 1
+ }
+ },
+ plugins = {
+ ["elasticsearch-logger"] = {
+ endpoint_addr = "http://127.0.0.1:9201",
+ field = {
+ index = "services"
+ },
+ batch_max_size = 1,
+ inactive_timeout = 1,
+ include_req_body = true
+ }
+ }
+ })
+
+ if code >= 300 then
+ ngx.status = code
+ end
+
+ local code, _, body = t("/hello", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- error_log
+"body":"{\"sample_payload\":\"hello\"}"
+
+
+
+=== TEST 20: add plugin with 'include_resp_body' setting, collect response log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/elasticsearch-logger',
ngx.HTTP_DELETE)
+
+ local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, {
+ uri = "/hello",
+ upstream = {
+ type = "roundrobin",
+ nodes = {
+ ["127.0.0.1:1980"] = 1
+ }
+ },
+ plugins = {
+ ["elasticsearch-logger"] = {
+ endpoint_addr = "http://127.0.0.1:9201",
+ field = {
+ index = "services"
+ },
+ batch_max_size = 1,
+ inactive_timeout = 1,
+ include_req_body = true,
+ include_resp_body = true
+ }
+ }
+ })
+
+ if code >= 300 then
+ ngx.status = code
+ end
+
+ local code, _, body = t("/hello", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- error_log
+"body":"hello world\n"
diff --git a/t/plugin/skywalking-logger.t b/t/plugin/skywalking-logger.t
index 900c5a07a..6ab87be26 100644
--- a/t/plugin/skywalking-logger.t
+++ b/t/plugin/skywalking-logger.t
@@ -33,7 +33,10 @@ add_block_preprocessor(sub {
location /v3/logs {
content_by_lua_block {
local core = require("apisix.core")
-
+ ngx.req.read_body()
+ local data = ngx.req.get_body_data()
+ local headers = ngx.req.get_headers()
+ ngx.log(ngx.WARN, "skywalking-logger body: ", data)
core.log.warn(core.json.encode(core.request.get_body(), true))
}
}
@@ -294,3 +297,90 @@ opentracing
qr/\\\"serviceInstance\\\":\\\"\$hostname\\\"/
qr/\\\"serviceInstance\\\":\\\"\\\"/
--- wait: 0.5
+
+
+
+=== TEST 13: add plugin with 'include_req_body' setting, collect request log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/skywalking-logger',
ngx.HTTP_DELETE)
+
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "skywalking-logger": {
+ "endpoint_addr": "http://127.0.0.1:1986",
+ "batch_max_size": 1,
+ "max_retry_count": 1,
+ "retry_delay": 2,
+ "buffer_duration": 2,
+ "inactive_timeout": 2,
+ "include_req_body": true
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1982": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/opentracing"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+
+ local code, _, body = t("/opentracing", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- error_log
+\"body\":\"{\\\"sample_payload\\\":\\\"hello\\\"}\"
+
+
+
+=== TEST 14: add plugin with 'include_resp_body' setting, collect response log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/skywalking-logger',
ngx.HTTP_DELETE)
+
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "skywalking-logger": {
+ "endpoint_addr": "http://127.0.0.1:1986",
+ "batch_max_size": 1,
+ "max_retry_count": 1,
+ "retry_delay": 2,
+ "buffer_duration": 2,
+ "inactive_timeout": 2,
+ "include_req_body": true,
+ "include_resp_body": true
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1982": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/opentracing"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+
+ local code, _, body = t("/opentracing", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- error_log
+\"body\":\"opentracing\\n\"
diff --git a/t/plugin/sls-logger.t b/t/plugin/sls-logger.t
index 940ddf6a2..af6ae667c 100644
--- a/t/plugin/sls-logger.t
+++ b/t/plugin/sls-logger.t
@@ -385,3 +385,90 @@ passed
GET /hello
--- response_body
hello world
+
+
+
+=== TEST 14: add plugin with 'include_req_body' setting, collect request log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/sls-logger', ngx.HTTP_DELETE)
+
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "sls-logger": {
+ "host": "127.0.0.1",
+ "port": 10009,
+ "project": "your_project",
+ "logstore": "your_logstore",
+ "access_key_id": "your_access_key_id",
+ "access_key_secret": "your_access_key_secret",
+ "timeout": 30000,
+ "include_req_body": true
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+
+ local code, _, body = t("/hello", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- error_log
+"body":"{\"sample_payload\":\"hello\"}
+
+
+
+=== TEST 15: add plugin with 'include_resp_body' setting, collect response log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/sls-logger', ngx.HTTP_DELETE)
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "sls-logger": {
+ "host": "127.0.0.1",
+ "port": 10009,
+ "project": "your_project",
+ "logstore": "your_logstore",
+ "access_key_id": "your_access_key_id",
+ "access_key_secret": "your_access_key_secret",
+ "timeout": 30000,
+ "include_resp_body": true
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+
+ local code, _, body = t("/hello", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- error_log
+"body":"hello world\n"
diff --git a/t/plugin/syslog.t b/t/plugin/syslog.t
index 5e13aa301..9dbb03af8 100644
--- a/t/plugin/syslog.t
+++ b/t/plugin/syslog.t
@@ -559,3 +559,95 @@ GET /hello
tail -n 1 ci/pod/vector/syslog-udp.log
--- response_body eval
qr/.*upstream.*/
+
+
+
+=== TEST 20: add plugin with 'include_req_body' setting, collect request log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/syslog', ngx.HTTP_DELETE)
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "syslog": {
+ "batch_max_size": 1,
+ "flush_limit": 1,
+ "host" : "127.0.0.1",
+ "port" : 5140,
+ "include_req_body": true
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ ngx.say(body)
+
+ local code, _, body = t("/hello", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- request
+GET /t
+--- error_log
+"body":"{\"sample_payload\":\"hello\"}"
+
+
+
+=== TEST 21: add plugin with 'include_resp_body' setting, collect response log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/syslog', ngx.HTTP_DELETE)
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "syslog": {
+ "batch_max_size": 1,
+ "flush_limit": 1,
+ "host" : "127.0.0.1",
+ "port" : 5140,
+ "include_resp_body": true
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ ngx.say(body)
+
+ local code, _, body = t("/hello", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- request
+GET /t
+--- error_log
+"body":"hello world\n"
diff --git a/t/plugin/tcp-logger.t b/t/plugin/tcp-logger.t
index 3ef774f81..b3c29ee51 100644
--- a/t/plugin/tcp-logger.t
+++ b/t/plugin/tcp-logger.t
@@ -518,3 +518,91 @@ opentracing
tail -n 1 ci/pod/vector/tls-datas.log
--- response_body eval
qr/.*route_id.*1.*/
+
+
+
+=== TEST 16: add plugin with 'include_req_body' setting, collect request log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/tcp-logger', ngx.HTTP_DELETE)
+ local code, body1 = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "tcp-logger": {
+ "host": "127.0.0.1",
+ "port": 43000,
+ "tls": true,
+ "batch_max_size": 1,
+ "include_req_body": true
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1982": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/opentracing"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say("fail")
+ return
+ end
+
+ local code, _, body = t("/opentracing", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- request
+GET /t
+--- error_log
+"body":"{\"sample_payload\":\"hello\"}"
+
+
+
+=== TEST 17: add plugin with 'include_resp_body' setting, collect request log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/tcp-logger', ngx.HTTP_DELETE)
+ local code, body1 = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "tcp-logger": {
+ "host": "127.0.0.1",
+ "port": 43000,
+ "tls": true,
+ "batch_max_size": 1,
+ "include_resp_body": true
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1982": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/opentracing"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say("fail")
+ return
+ end
+
+ local code, _, body = t("/opentracing", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- request
+GET /t
+--- error_log
+"body":"opentracing\n"
diff --git a/t/plugin/udp-logger.t b/t/plugin/udp-logger.t
index 447448236..b20248b19 100644
--- a/t/plugin/udp-logger.t
+++ b/t/plugin/udp-logger.t
@@ -445,3 +445,95 @@ passed
tail -n 1 ci/pod/vector/udp.log
--- response_body eval
qr/.*logger format in plugin.*/
+
+
+
+=== TEST 13: add plugin with 'include_req_body' setting, collect request log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/udp-logger', ngx.HTTP_DELETE)
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "udp-logger": {
+ "host": "127.0.0.1",
+ "port": 8127,
+ "tls": false,
+ "batch_max_size": 1,
+ "inactive_timeout": 1,
+ "include_req_body": true
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+
+ local code, _, body = t("/hello", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- request
+GET /t
+--- error_log
+"body":"{\"sample_payload\":\"hello\"}"
+
+
+
+=== TEST 14: add plugin with 'include_resp_body' setting, collect request log
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ t('/apisix/admin/plugin_metadata/udp-logger', ngx.HTTP_DELETE)
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "udp-logger": {
+ "host": "127.0.0.1",
+ "port": 8127,
+ "tls": false,
+ "batch_max_size": 1,
+ "inactive_timeout": 1,
+ "include_resp_body": true
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/hello"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+
+ local code, _, body = t("/hello", "POST",
"{\"sample_payload\":\"hello\"}")
+ }
+ }
+--- request
+GET /t
+--- error_log
+"body":"hello world\n"