Skip to content

Commit

Permalink
perf(alf_serializer) globals optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Oct 15, 2015
1 parent 731e203 commit 956f94d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions kong/plugins/log-serializers/alf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
-- - ngx_http_core_module: http://wiki.nginx.org/HttpCoreModule#.24http_HEADER

local stringy = require "stringy"
local table_insert = table.insert
local tostring = tostring
local pairs = pairs
local ipairs = ipairs
local type = type
local tonumber = tonumber
local string_len = string.len
local os_date = os.date


local EMPTY_ARRAY_PLACEHOLDER = "__empty_array_placeholder__"

Expand All @@ -38,7 +47,7 @@ local function dic_to_array(hash, fn)
for _, val in ipairs(v) do
k = tostring(k)
val = tostring(val)
table.insert(arr, {name = k, value = val})
table_insert(arr, {name = k, value = val})
fn(k, val)
end
end
Expand Down Expand Up @@ -128,15 +137,15 @@ function _M.serialize_entry(ngx)

local alf_req_headers_arr = dic_to_array(req_headers, function(k, v) req_headers_str = req_headers_str..k..v end)
local alf_res_headers_arr = dic_to_array(res_headers, function(k, v) res_headers_str = res_headers_str..k..v end)
local alf_req_headers_size = string.len(req_headers_str)
local alf_res_headers_size = string.len(res_headers_str)
local alf_req_headers_size = string_len(req_headers_str)
local alf_res_headers_size = string_len(res_headers_str)

-- mimeType, defaulting to "application/octet-stream"
local alf_req_mimeType = get_header(req_headers, "Content-Type", "application/octet-stream")
local alf_res_mimeType = get_header(res_headers, "Content-Type", "application/octet-stream")

return {
startedDateTime = os.date("!%Y-%m-%dT%TZ", alf_started_at),
startedDateTime = os_date("!%Y-%m-%dT%TZ", alf_started_at),
time = alf_time,
request = {
method = ngx.req.get_method(),
Expand All @@ -146,7 +155,7 @@ function _M.serialize_entry(ngx)
headers = alf_req_headers_arr,
headersSize = alf_req_headers_size,
cookies = {EMPTY_ARRAY_PLACEHOLDER},
bodySize = string.len(alf_req_body),
bodySize = string_len(alf_req_body),
postData = {
mimeType = alf_req_mimeType,
params = dic_to_array(alf_req_post_args),
Expand Down

0 comments on commit 956f94d

Please sign in to comment.