-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(plugins/http-log): improve concurrency when max_batch_size is set to 1 #13384
Closed
Closed
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
message: | | ||
**HTTP-Log**: When `queue.max_batch_size` is 1, log entries are now sent in separate, parallel HTTP requests. Previously, they were sent sequentially in FIFO order. | ||
type: bugfix | ||
scope: Plugin |
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 @@ local tonumber = tonumber | |
local fmt = string.format | ||
local pairs = pairs | ||
local max = math.max | ||
local timer_at = ngx.timer.at | ||
|
||
|
||
local sandbox_opts = { env = { kong = kong, ngx = ngx } } | ||
|
@@ -189,12 +190,27 @@ function HttpLogHandler:log(conf) | |
|
||
local queue_conf = Queue.get_plugin_params("http-log", conf, make_queue_name(conf)) | ||
kong.log.debug("Queue name automatically configured based on configuration parameters to: ", queue_conf.name) | ||
local entry = cjson.encode(kong.log.serialize()) | ||
|
||
if queue_conf.max_batch_size == 1 then | ||
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. This is a hidden feature. We can update the official doc https://docs.konghq.com/gateway/latest/kong-plugins/queue. |
||
local queue = Queue.create(queue_conf, send_entries, conf) | ||
local ok, err = timer_at(0, function(premature) | ||
if premature then | ||
return | ||
end | ||
queue:handle({ entry }) | ||
end) | ||
if not ok then | ||
kong.log.err("failed to create timer: ", err) | ||
end | ||
return | ||
end | ||
|
||
local ok, err = Queue.enqueue( | ||
queue_conf, | ||
send_entries, | ||
conf, | ||
cjson.encode(kong.log.serialize()) | ||
entry | ||
) | ||
if not ok then | ||
kong.log.err("Failed to enqueue log entry to log server: ", err) | ||
|
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
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.
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.
Pay attention to @chronolaw PR: #13421
We now use the
clustering_utils.json_decode
orclustering_utils.json_encode
.