Skip to content

Commit

Permalink
feat(runloop) add ngx.ctx.KONG_BODY_FILTER_ENDED_AT
Browse files Browse the repository at this point in the history
From #3434

Signed-off-by: Thibault Charbonnier <[email protected]>
  • Loading branch information
james-callahan authored and thibaultcha committed May 31, 2018
1 parent a1201bc commit 4a24e09
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions kong/runloop/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -750,11 +750,16 @@ return {
},
body_filter = {
after = function(ctx)
if ngx.arg[2] and ctx.KONG_PROXIED then
-- time spent receiving the response (header_filter + body_filter)
-- we could use $upstream_response_time but we need to distinguish the waiting time
-- from the receiving time in our logging plugins (especially ALF serializer).
ctx.KONG_RECEIVE_TIME = get_now() - ctx.KONG_HEADER_FILTER_STARTED_AT
if ngx.arg[2] then
local now = get_now()
ctx.KONG_BODY_FILTER_ENDED_AT = now

if ctx.KONG_PROXIED then
-- time spent receiving the response (header_filter + body_filter)
-- we could use $upstream_response_time but we need to distinguish the waiting time
-- from the receiving time in our logging plugins (especially ALF serializer).
ctx.KONG_RECEIVE_TIME = now - ctx.KONG_HEADER_FILTER_STARTED_AT
end
end
end
},
Expand Down

0 comments on commit 4a24e09

Please sign in to comment.