-
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(kafka-logger): add max req/resp body size attributes #11133
feat(kafka-logger): add max req/resp body size attributes #11133
Conversation
apisix/plugins/kafka-logger.lua
Outdated
@@ -22,6 +23,7 @@ local bp_manager_mod = require("apisix.utils.batch-processor-manager") | |||
local math = math | |||
local pairs = pairs | |||
local type = type | |||
local req_body = ngx.req.read_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.
local req_body = ngx.req.read_body | |
local req_read_body = ngx.req.read_body |
apisix/core/response.lua
Outdated
ctx._body_buffer[ctx._plugin_name] = nil | ||
return body_buffer | ||
if max_resp_body_bytes and #body_data >= max_resp_body_bytes then | ||
body_data = str_sub(body_data, 1, max_resp_body_bytes) |
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 do we need to sub the body_data again here?
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.
in 213, we just sub the chunk this happens in the case when this is the first and last chunk of body_filter phase. (since eof == true and body_buffer is nil).
in 221 we need to sub because it is the last chunk but not the very first one.
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 think if it's the first chunk, it will be dealed in line ~202
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.
hmm now it makes sense but I think we are calling sub on 213 on chunk
because body_buffer
is nil. And on 221 we are calling it on body data formed after concat_tab
the body_buffer
table.
Description
In cases where the req/response body is very large and when include_req_body/resp_body is enabled this leads to very high CPU usage and can even cause unavailability. To fix such event, two new attributes are introduced:
Checklist