Skip to content

Commit

Permalink
Revert "enhancement(plugin/datadog) Added response size as metric"
Browse files Browse the repository at this point in the history
This reverts commit 30756e8.
  • Loading branch information
thibaultcha committed Jan 30, 2016
1 parent f666566 commit ad22cd0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 52 deletions.
55 changes: 30 additions & 25 deletions kong/plugins/datadog/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,25 @@ local string_gsub = string.gsub
local pairs = pairs
local NGX_ERR = ngx.ERR

local gauges = {
request_size = function (api_name, message, logger)
local stat = api_name..".request.size"
logger:gauge(stat, message.request.size, 1)
end,
response_size = function (api_name, message, logger)
local stat = api_name..".response.size"
logger:gauge(stat, message.response.size, 1)
end,
status_count = function (api_name, message, logger)
local stat = api_name..".request.status."..message.response.status
logger:counter(stat, 1, 1)
end,
latency = function (api_name, message, logger)
local stat = api_name..".latency"
logger:gauge(stat, message.latencies.request, 1)
end,
request_count = function (api_name, message, logger)
local stat = api_name..".request.count"
logger:counter(stat, 1, 1)
end
}
local function request_counter(api_name, logger)
local stat = api_name..".request.count"
logger:counter(stat, 1, 1)
end

local function status_counter(api_name, message, logger)
local stat = api_name..".request.status."..message.response.status
logger:counter(stat, 1, 1)
end

local function request_size_gauge(api_name, message, logger)
local stat = api_name..".request.size"
logger:gauge(stat, message.request.size, 1)
end

local function latency_gauge(api_name, message, logger)
local stat = api_name..".latency"
logger:gauge(stat, message.latencies.request, 1)
end

local function log(premature, conf, message)
if premature then return end
Expand All @@ -46,9 +43,17 @@ local function log(premature, conf, message)

local api_name = string_gsub(message.api.name, "%.", "_")
for _, metric in pairs(conf.metrics) do
local gauge = gauges[metric]
if gauge ~= nil then
gauge(api_name, message, logger)
if metric == "request_size" then
request_size_gauge(api_name, message, logger)
end
if metric == "status_count" then
status_counter(api_name, message, logger)
end
if metric == "latency" then
latency_gauge(api_name, message, logger)
end
if metric == "request_count" then
request_counter(api_name, logger)
end
end

Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/datadog/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ return {
fields = {
host = {required = true, type = "string", default = "localhost"},
port = {required = true, type = "number", default = 8125},
metrics = {required = true, type = "array", enum = {"request_count", "latency", "request_size", "status_count", "response_size"}, default = {"request_count", "latency", "request_size", "status_count", "response_size"}},
metrics = {required = true, type = "array", enum = {"request_count", "latency", "request_size", "status_count"}, default = {"request_count", "latency", "request_size", "status_count"}},
timeout = {type = "number", default = 10000}
}
}
31 changes: 5 additions & 26 deletions spec/plugins/datadog/log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ describe("Datadog Plugin", function()
{request_host = "logging2.com", upstream_url = "http://mockbin.com"},
{request_host = "logging3.com", upstream_url = "http://mockbin.com"},
{request_host = "logging4.com", upstream_url = "http://mockbin.com"},
{request_host = "logging5.com", upstream_url = "http://mockbin.com"},
{request_host = "logging6.com", upstream_url = "http://mockbin.com"},
{request_host = "logging5.com", upstream_url = "http://mockbin.com"}
},
plugin = {
{name = "datadog", config = {host = "127.0.0.1", port = UDP_PORT, metrics = {"request_count"}}, __api = 1},
{name = "datadog", config = {host = "127.0.0.1", port = UDP_PORT, metrics = {"latency"}}, __api = 2},
{name = "datadog", config = {host = "127.0.0.1", port = UDP_PORT, metrics = {"status_count"}}, __api = 3},
{name = "datadog", config = {host = "127.0.0.1", port = UDP_PORT, metrics = {"request_size"}}, __api = 4},
{name = "datadog", config = {host = "127.0.0.1", port = UDP_PORT}, __api = 5},
{name = "datadog", config = {host = "127.0.0.1", port = UDP_PORT, metrics = {"response_size"}}, __api = 6},
{name = "datadog", config = {host = "127.0.0.1", port = UDP_PORT}, __api = 5}
}
}
spec_helper.start_kong()
Expand Down Expand Up @@ -58,7 +56,7 @@ describe("Datadog Plugin", function()
assert.equal("kong.logging3_com.request.status.200:1|c", res)
end)

it("should log to UDP when metrics is request_size", function()
pending("should log to UDP when metrics is request_size", function()
local thread = spec_helper.start_udp_server(UDP_PORT) -- Starting the mock UDP server

local _, status = http_client.get(STUB_GET_URL, nil, {host = "logging4.com"})
Expand All @@ -67,11 +65,8 @@ describe("Datadog Plugin", function()
local ok, res = thread:join()
assert.True(ok)
assert.truthy(res)
local message = {}
for w in string.gmatch(res,"kong.logging4_com.request.size:%d*|g") do
table.insert(message, w)
end
assert.equal(1, #message)
-- 113 locally but 111 on travis
assert.equal("kong.logging4_com.request.size:113|g", res)
end)

it("should log to UDP when metrics is latency", function()
Expand Down Expand Up @@ -103,20 +98,4 @@ describe("Datadog Plugin", function()
assert.truthy(res)
assert.equal("kong.logging5_com.request.count:1|c", res)
end)

it("should log to UDP when metrics is response_size", function()
local thread = spec_helper.start_udp_server(UDP_PORT) -- Starting the mock UDP server

local _, status = http_client.get(STUB_GET_URL, nil, {host = "logging6.com"})
assert.equal(200, status)

local ok, res = thread:join()
assert.True(ok)
assert.truthy(res)
local message = {}
for w in string.gmatch(res,"kong.logging6_com.response.size:%d*|g") do
table.insert(message, w)
end
assert.equal(1, #message)
end)
end)

0 comments on commit ad22cd0

Please sign in to comment.