From 4a24e091414edfabdae17d69cfbc0bf16f19da24 Mon Sep 17 00:00:00 2001 From: James Callahan Date: Fri, 4 May 2018 10:03:32 +1000 Subject: [PATCH] feat(runloop) add ngx.ctx.KONG_BODY_FILTER_ENDED_AT From #3434 Signed-off-by: Thibault Charbonnier --- kong/runloop/handler.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/kong/runloop/handler.lua b/kong/runloop/handler.lua index b963496e150d..3a586682335e 100644 --- a/kong/runloop/handler.lua +++ b/kong/runloop/handler.lua @@ -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 },