-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: file logger plugin support response body in variable #8711
feat: file logger plugin support response body in variable #8711
Conversation
t/plugin/file-logger3.t
Outdated
@@ -0,0 +1,124 @@ | |||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move these tests under https://github.com/apache/apisix/blob/master/t/plugin/file-logger2.t? That file is still small and doesn't have special setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to file-logger2
apisix/plugins/file-logger.lua
Outdated
@@ -59,6 +59,9 @@ local _M = { | |||
metadata_schema = metadata_schema | |||
} | |||
|
|||
core.ctx.register_var("resp_body", function(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to put it in https://github.com/apache/apisix/blob/master/apisix/core/ctx.lua so other loggers can use it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this var should be put into the ctx.lua
file. Because the value of resp_body comes from ctx.resp_body
, which is set by file-logger
when include_resp_body = true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not only one logger plugin will support recording the response body. file-logger.lua
is not an appropriate place.
| path | string | True | Log file path. | | ||
| include_resp_body | boolean | False | When set to `true` includes the response body in the log file. | | ||
| include_resp_body | boolean | False | When set to `true` includes the response body in the log file. If format is set, you can use the variable $resp_body to get the response body. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to put it in https://github.com/apache/apisix/blob/master/docs/en/latest/apisix-variable.md, instead of modifying each logger's doc.
Note that we need to mean that this variable is only for logger and requires the logger to have a special configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1.
apisix/core/ctx.lua
Outdated
@@ -213,6 +213,10 @@ do | |||
route_name = true, | |||
service_id = true, | |||
service_name = true, | |||
resp_body = function(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 206 in c8d5afb
-- sort in alphabetical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
apisix/core/ctx.lua
Outdated
@@ -213,6 +213,10 @@ do | |||
route_name = true, | |||
service_id = true, | |||
service_name = true, | |||
resp_body = function(ctx) | |||
-- only work when file-logger set include_resp_body = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is incorrect. See #8711 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
docs/en/latest/apisix-variable.md
Outdated
@@ -49,5 +49,6 @@ additional variables. | |||
| service_name | core | Name of Service. | | | |||
| redis_cmd_line | Redis | The content of Redis command. | | | |||
| rpc_time | xRPC | Time spent at the rpc request level. | | | |||
| resp_body | core | This variable is only for logger and requires the logger to have a special configuration. | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which special configuration? I'm afraid that such a description is not useful for users to use this variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was update it
apisix/core/ctx.lua
Outdated
route_id = true, | ||
route_name = true, | ||
service_id = true, | ||
service_name = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the comma?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I readded it
docs/zh/latest/apisix-variable.md
Outdated
@@ -48,5 +48,6 @@ APISIX 除了支持 [NGINX 变量](http://nginx.org/en/docs/varindex.html)外, | |||
| service_name | core | APISIX 服务的名称。 | | | |||
| redis_cmd_line | Redis | Redis 命令的内容。 | | | |||
| rpc_time | xRPC | 在 RPC 请求级别所花费的时间。 | | | |||
| resp_body | core | 此变量仅用于 Logger,并要求对应的 Logger 需要具备某些配置。 | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put it in alphabetical order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
docs/en/latest/apisix-variable.md
Outdated
@@ -49,5 +49,6 @@ additional variables. | |||
| service_name | core | Name of Service. | | | |||
| redis_cmd_line | Redis | The content of Redis command. | | | |||
| rpc_time | xRPC | Time spent at the rpc request level. | | | |||
| resp_body | core | This variable is only for logger and requires the logger plugin to have a special configuration like `include_resp_body`. | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should explain what this variable is, and what decides its value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Co-authored-by: 罗泽轩 <spacewanderlzx@gmail.com>
* upstream/master: docs: change the file name to 'create-ssl.py'.If 'ssl.py' is used as … (apache#8623) feat: Body transformer plugin (apache#8766) fix: mocking plugin panic when response_example contain $ (apache#8810) (apache#8816) feat: file logger plugin support response body in variable (apache#8711) docs(getting-started): rewrite the install section (apache#8807) feat: allow each logger to define custom log format in its conf (apache#8806) fix(etcd): reloaded data may be in res.body.node (apache#8736) fix: fix fetch all service info from consul (apache#8651) docs: fix global-rule.md wrong curl address (apache#8793) feat: stream subsystem support consul service discovery (apache#8696) chore(kafka-logger): support configuration `meta_refresh_interval` parameter (apache#8762) feat: ready to release 2.15.2 (apache#8783)
Description
We need to add a new var resp_body to let the user put it in a log format which let the user use the response in the way there want.
Fixes #8705
Checklist