-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datadog) new metrics and more flexible configuration
- Now each metric supports configurable stat type, sample rate and customer identifier if applicable. - Custom prefix for stats's name - Custom tags for Datadog. - New metrics `upstream_latency`, `kong_latency` and `status_count_per_user`. - Code style format
- Loading branch information
Shashi Ranjan
committed
Jun 6, 2017
1 parent
9e7506e
commit cd1864d
Showing
8 changed files
with
805 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
return { | ||
{ | ||
name = "2017-02-09-160000_datadog_schema_changes", | ||
up = function(_, _, factory) | ||
|
||
local plugins, err = factory.plugins:find_all { name = "datadog" } | ||
if err then | ||
return err | ||
end | ||
|
||
local default_metrics = { | ||
request_count = { | ||
name = "request_count", | ||
stat_type = "counter", | ||
sample_rate = 1, | ||
tags = { "app:kong" }, | ||
}, | ||
latency = { | ||
name = "latency", | ||
stat_type = "timer", | ||
tags = { "app:kong" }, | ||
}, | ||
request_size = { | ||
name = "request_size", | ||
stat_type = "timer", | ||
tags = { "app:kong" }, | ||
}, | ||
status_count = { | ||
name = "status_count", | ||
stat_type = "counter", | ||
sample_rate = 1, | ||
tags = { "app:kong" }, | ||
}, | ||
response_size = { | ||
name = "response_size", | ||
stat_type = "timer", | ||
tags = { "app:kong" }, | ||
}, | ||
unique_users = { | ||
name = "unique_users", | ||
stat_type = "set", | ||
consumer_identifier = "custom_id", | ||
tags = { "app:kong" }, | ||
}, | ||
request_per_user = { | ||
name = "request_per_user", | ||
stat_type = "counter", | ||
sample_rate = 1, | ||
consumer_identifier = "custom_id", | ||
tags = { "app:kong" }, | ||
}, | ||
upstream_latency = { | ||
name = "upstream_latency", | ||
stat_type = "timer", | ||
tags = { "app:kong" }, | ||
}, | ||
kong_latency = { | ||
name = "kong_latency", | ||
stat_type = "timer", | ||
tags = {"app:kong"}, | ||
}, | ||
status_count_per_user = { | ||
name = "status_count_per_user", | ||
stat_type = "counter", | ||
sample_rate = 1, | ||
consumer_identifier = "custom_id", | ||
tags = { "app:kong" }, | ||
} | ||
} | ||
|
||
for _, plugin in ipairs(plugins) do | ||
local new_metrics = {} | ||
plugin.config.tags = nil | ||
plugin.config.timeout = nil | ||
|
||
if plugin.config.metrics then | ||
for _, metric in ipairs(plugin.config.metrics) do | ||
table.insert(new_metrics, default_metrics[metric]) | ||
end | ||
|
||
plugin.config.metrics = new_metrics | ||
plugin.config.timeout = nil | ||
plugin.config.prefix = "kong" | ||
|
||
local _, err = factory.plugins:update(plugin, plugin, { full = true }) | ||
if err then | ||
return err | ||
end | ||
end | ||
end | ||
end | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
return { | ||
{ | ||
name = "2017-02-09-160000_datadog_schema_changes", | ||
up = function(_, _, dao) | ||
local rows, err = dao.plugins:find_all {name = "datadog"} | ||
if err then | ||
return err | ||
end | ||
|
||
local default_metrics = { | ||
request_count = { | ||
name = "request_count", | ||
stat_type = "counter", | ||
sample_rate = 1, | ||
tags = { "app:kong" }, | ||
}, | ||
latency = { | ||
name = "latency", | ||
stat_type = "timer", | ||
tags = { "app:kong" }, | ||
}, | ||
request_size = { | ||
name = "request_size", | ||
stat_type = "timer", | ||
tags = { "app:kong" }, | ||
}, | ||
status_count = { | ||
name = "status_count", | ||
stat_type = "counter", | ||
sample_rate = 1, | ||
tags = { "app:kong" }, | ||
}, | ||
response_size = { | ||
name = "response_size", | ||
stat_type = "timer", | ||
tags = { "app:kong" }, | ||
}, | ||
unique_users = { | ||
name = "unique_users", | ||
stat_type = "set", | ||
consumer_identifier = "custom_id", | ||
tags = { "app:kong" }, | ||
}, | ||
request_per_user = { | ||
name = "request_per_user", | ||
stat_type = "counter", | ||
sample_rate = 1, | ||
consumer_identifier = "custom_id", | ||
tags = { "app:kong" }, | ||
}, | ||
upstream_latency = { | ||
name = "upstream_latency", | ||
stat_type = "timer", | ||
tags = { "app:kong" } | ||
}, | ||
kong_latency = { | ||
name = "kong_latency", | ||
stat_type = "timer", | ||
tags = { "app:kong" }, | ||
}, | ||
status_count_per_user = { | ||
name = "status_count_per_user", | ||
stat_type = "counter", | ||
sample_rate = 1, | ||
consumer_identifier = "custom_id", | ||
tags = { "app:kong" }, | ||
}, | ||
} | ||
|
||
for i = 1, #rows do | ||
local row = rows[i] | ||
|
||
local _, err = dao.plugins:delete(row) | ||
if err then return err end | ||
local new_metrics = {} | ||
if row.config.metrics then | ||
for _, metric in ipairs(row.config.metrics) do | ||
table.insert(new_metrics, default_metrics[metric]) | ||
end | ||
end | ||
|
||
local _, err = dao.plugins:insert { | ||
name = "datadog", | ||
api_id = row.api_id, | ||
enabled = row.enabled, | ||
config = { | ||
host = row.config.host, | ||
port = row.config.port, | ||
metrics = new_metrics, | ||
prefix = "kong", | ||
}, | ||
} | ||
|
||
if err then | ||
return err | ||
end | ||
end | ||
end | ||
} | ||
} |
Oops, something went wrong.