Skip to content

Commit

Permalink
fix(log-serializer): do not add receive time to latencies.kong
Browse files Browse the repository at this point in the history
  • Loading branch information
flrgh committed Mar 27, 2024
1 parent 6d31868 commit 78f0c68
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 10 additions & 0 deletions changelog/unreleased/kong/log-serializer-kong-latency.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
message: |
The value of `latencies.kong` in the log serializer payload no longer includes
the response receive time, so it now has the same value as the
`X-Kong-Proxy-Latency` response header. Response receive time is recorded in
the new `latencies.receive` metric, so if desired, the old value can be
calculated as `latencies.kong + latencies.receive`. **Note:** this also
affects payloads from all logging plugins that use the log serializer:
`file-log`, `tcp-log`, `udp-log`,`http-log`, `syslog`, and `loggly`.
type: bugfix
scope: PDK
3 changes: 1 addition & 2 deletions kong/pdk/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,7 @@ do
size = to_decimal(var.bytes_sent),
},
latencies = {
kong = (ctx.KONG_PROXY_LATENCY or ctx.KONG_RESPONSE_LATENCY or 0) +
(ctx.KONG_RECEIVE_TIME or 0),
kong = ctx.KONG_PROXY_LATENCY or ctx.KONG_RESPONSE_LATENCY or 0,
proxy = ctx.KONG_WAITING_TIME or -1,
request = tonumber(var.request_time) * 1000,
receive = ctx.KONG_RECEIVE_TIME or 0,
Expand Down
6 changes: 4 additions & 2 deletions spec/01-unit/10-log_serializer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ describe("kong.log.serialize", function()
},
},
KONG_PROXIED = true,
KONG_RECEIVE_TIME = 100,
KONG_PROXY_LATENCY = 200,
},
var = {
kong_request_id = "1234",
Expand Down Expand Up @@ -73,10 +75,10 @@ describe("kong.log.serialize", function()

-- Latencies
assert.is_table(res.latencies)
assert.equal(0, res.latencies.kong)
assert.equal(200, res.latencies.kong)
assert.equal(-1, res.latencies.proxy)
assert.equal(2000, res.latencies.request)
assert.equal(0, res.latencies.receive)
assert.equal(100, res.latencies.receive)

-- Request
assert.is_table(res.request)
Expand Down

0 comments on commit 78f0c68

Please sign in to comment.