Skip to content

Commit

Permalink
Adds upstream_latency as a potential value for the Statsd plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Van Winkle committed Aug 5, 2016
1 parent 1b39b91 commit a639640
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
6 changes: 5 additions & 1 deletion kong/plugins/statsd/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ local gauges = {
local stat = api_name.."."..string_gsub(message.authenticated_entity.consumer_id, "-", "_")..".request.count"
logger:counter(stat, 1, 1)
end
end
end,
upstream_latency = function (api_name, message, logger)
local stat = api_name..".upstream_latency"
logger:gauge(stat, message.latencies.proxy, 1)
end,
}

local function log(premature, conf, message)
Expand Down
3 changes: 2 additions & 1 deletion kong/plugins/statsd/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ local metrics = {
"status_count",
"response_size",
"unique_users",
"request_per_user"
"request_per_user",
"upstream_latency"
}

return {
Expand Down
29 changes: 29 additions & 0 deletions spec/03-plugins/006-statsd/01-log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ describe("Plugin: statsd (log)", function()
request_host = "logging6.com",
upstream_url = "http://mockbin.com"
})
local api7 = assert(helpers.dao.apis:insert {
request_host = "logging7.com",
upstream_url = "http://mockbin.com"
})

assert(helpers.dao.plugins:insert {
api_id = api1.id,
Expand Down Expand Up @@ -85,6 +89,15 @@ describe("Plugin: statsd (log)", function()
metrics = {"response_size"}
}
})
assert(helpers.dao.plugins:insert {
api_id = api7.id,
name = "statsd",
config = {
host = "127.0.0.1",
port = UDP_PORT,
metrics = {"upstream_latency"}
}
})
end)

teardown(function()
Expand Down Expand Up @@ -128,6 +141,7 @@ describe("Plugin: statsd (log)", function()
assert.contains("kong.logging1_com.request.size:98|g", metrics)
assert.contains("kong.logging1_com.request.status.200:1|c", metrics)
assert.contains("kong%.logging1_com%.response%.size:%d+|g", metrics, true)
assert.contains("kong%.logging1_com%.upstream_latency:%d+|g", metrics, true)
end)

describe("metrics", function()
Expand Down Expand Up @@ -206,5 +220,20 @@ describe("Plugin: statsd (log)", function()
assert.True(ok)
assert.matches("kong.logging6_com.response.size:%d+|g", res)
end)
it("upstream_latency", function()
local thread = helpers.udp_server(UDP_PORT)
local response = assert(client:send {
method = "GET",
path = "/request",
headers = {
host = "logging7.com"
}
})
assert.res_status(200, response)

local ok, res = thread:join()
assert.True(ok)
assert.matches("kong.logging7_com.upstream_latency:.*|g", res)
end)
end)
end)

0 comments on commit a639640

Please sign in to comment.