Skip to content

Commit

Permalink
fix(plugins/datadog): add return value for log function in batch queue (
Browse files Browse the repository at this point in the history
#10044)

The log function in Datadog is called by the batch
queue when a batch is processed, and batch queue relys
on the return value of the callback. The return value of log
function in Datadog always return `nil`, this makes batch queue consider
the result of processing as failed. In this commit, the correct return value
indicating the success in processing to fix this bug.
  • Loading branch information
liverpool8056 authored and windmgc committed Jan 17, 2023
1 parent 87d7106 commit 70273a4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Table of Contents

- [3.1.2](#312)
- [3.1.1](#311)
- [3.1.0](#310)
- [3.0.0](#300)
Expand Down Expand Up @@ -67,6 +68,18 @@
- [0.9.9 and prior](#099---20170202)


## [3.1.2]

> Released TBD
### Fixes

##### Plugins

- **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)


## [3.1.1]

> Released 2022/12/09
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

0 comments on commit 70273a4

Please sign in to comment.