-
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
Merged
moonming
merged 8 commits into
apache:master
from
shreemaan-abhishek:fix/kfk-logger-large-body-high-cpu
Apr 16, 2024
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7dc8cc6
feat(kfk-logger): add max req/resp body size attributes
shreemaan-abhishek a9fe9cc
fix lint
shreemaan-abhishek bb6812d
fix test lint
shreemaan-abhishek b179638
add doc
shreemaan-abhishek b32ca2c
code review
shreemaan-abhishek 4109d4d
return nil when no body
shreemaan-abhishek 22fc4f6
remove not needed chunk processing
shreemaan-abhishek 1f775c8
fix test
shreemaan-abhishek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,7 @@ | |||||
-- See the License for the specific language governing permissions and | ||||||
-- limitations under the License. | ||||||
-- | ||||||
local expr = require("resty.expr.v1") | ||||||
local core = require("apisix.core") | ||||||
local log_util = require("apisix.utils.log-util") | ||||||
local producer = require ("resty.kafka.producer") | ||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
local plugin_name = "kafka-logger" | ||||||
local batch_processor_manager = bp_manager_mod.new("kafka logger") | ||||||
|
||||||
|
@@ -115,6 +117,8 @@ local schema = { | |||||
type = "array" | ||||||
} | ||||||
}, | ||||||
max_req_body_bytes = {type = "integer", minimum = 1, default = 524288}, | ||||||
max_resp_body_bytes = {type = "integer", minimum = 1, default = 524288}, | ||||||
-- in lua-resty-kafka, cluster_name is defined as number | ||||||
-- see https://github.com/doujiang24/lua-resty-kafka#new-1 | ||||||
cluster_name = {type = "integer", minimum = 1, default = 1}, | ||||||
|
@@ -210,6 +214,32 @@ local function send_kafka_data(conf, log_message, prod) | |||||
end | ||||||
|
||||||
|
||||||
function _M.access(conf, ctx) | ||||||
if conf.include_req_body then | ||||||
local read_req_body = true | ||||||
if conf.include_req_body_expr then | ||||||
if not conf.request_expr then | ||||||
local request_expr, err = expr.new(conf.include_req_body_expr) | ||||||
if not request_expr then | ||||||
core.log.error('generate request expr err ', err) | ||||||
return | ||||||
end | ||||||
conf.request_expr = request_expr | ||||||
end | ||||||
|
||||||
local result = conf.request_expr:eval(ctx.var) | ||||||
|
||||||
if not result then | ||||||
read_req_body = false | ||||||
end | ||||||
end | ||||||
if read_req_body then | ||||||
req_body() | ||||||
end | ||||||
end | ||||||
end | ||||||
|
||||||
|
||||||
function _M.body_filter(conf, ctx) | ||||||
log_util.collect_body(conf, ctx) | ||||||
end | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
becausebody_buffer
is nil. And on 221 we are calling it on body data formed afterconcat_tab
thebody_buffer
table.