Skip to content
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/datadog): add return value for log function in batch queue #10044

Merged
merged 6 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
[#9877](https://github.com/Kong/kong/pull/9877)
- **JWT**: Deny requests that have different tokens in the jwt token search locations. Thanks Jackson 'Che-Chun' Kuo from Latacora for reporting this issue.
[#9946](https://github.com/Kong/kong/pull/9946)
- **Datadog**: Fix a bug in the Datadog plugin batch queue processing where metrics are published multiple times.
[#10044](https://github.com/Kong/kong/pull/10044)

#### Core

Expand Down
3 changes: 2 additions & 1 deletion kong/plugins/datadog/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ local function log(conf, messages)
local logger, err = statsd_logger:new(conf)
if err then
kong.log.err("failed to create Statsd logger: ", err)
return
return false, err
end

for _, message in ipairs(messages) do
Expand Down Expand Up @@ -103,6 +103,7 @@ local function log(conf, messages)
end

logger:close_socket()
return true
end


Expand Down
19 changes: 19 additions & 0 deletions spec/03-plugins/08-datadog/01-log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,25 @@ for _, strategy in helpers.each_strategy() do
assert.contains("kong.kong_latency:%d*|ms|#name:dd7,status:200,consumer:bar,app:kong", gauges, true)
end)

-- the purpose of this test case is to test the batch queue
-- finish processing messages in one time(no retries)
it("no more messages than expected", function()
local thread = helpers.udp_server(9999, 10, 10)

local res = assert(proxy_client:send {
method = "GET",
path = "/status/200?apikey=kong",
headers = {
["Host"] = "datadog7.com"
}
})
assert.res_status(200, res)

local ok, gauges = thread:join()
assert.True(ok)
assert.equal(6, #gauges)
end)

it("should not return a runtime error (regression)", function()
local thread = helpers.udp_server(9999, 1, 1)

Expand Down