Skip to content

Commit

Permalink
Merge release/0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Apr 27, 2016
2 parents a9ac7a1 + afa2ff6 commit faaa422
Show file tree
Hide file tree
Showing 28 changed files with 203 additions and 74 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
## [Unreleased][unreleased]

## [0.8.1] - 2016/04/27

This release includes some fixes and minor updates:

### Added

- Adds `X-Forwarded-Host` and `X-Forwarded-Prefix` to the upstream request headers. [#1180](https://github.com/Mashape/kong/pull/1180)
- Plugins:
- Datadog: Added two new metrics, `unique_users` and `request_per_user`, that log the consumer information. [#1179](https://github.com/Mashape/kong/pull/1179)

### Fixed

- Fixed a DAO bug that affected full entity updates. [#1163](https://github.com/Mashape/kong/pull/1163)
- Fixed a bug when setting the authentication provider in Cassandra.
- Updated the Cassandra driver to v0.5.2.
- Properly enforcing required fields in PUT requests. [#1177](https://github.com/Mashape/kong/pull/1177)
- Fixed a bug that prevented to retrieve the hostname of the local machine on certain systems. [#1178](https://github.com/Mashape/kong/pull/1178)

## [0.8.0] - 2016/04/18

This release includes support for PostgreSQL as Kong's primary datastore!
Expand Down Expand Up @@ -543,7 +561,8 @@ First version running with Cassandra.
- CLI `bin/kong` script.
- Database migrations (using `db.lua`).

[unreleased]: https://github.com/mashape/kong/compare/0.8.0...next
[unreleased]: https://github.com/mashape/kong/compare/0.8.1...next
[0.8.1]: https://github.com/mashape/kong/compare/0.8.0...0.8.1
[0.8.0]: https://github.com/mashape/kong/compare/0.7.0...0.8.0
[0.7.0]: https://github.com/mashape/kong/compare/0.6.1...0.7.0
[0.6.1]: https://github.com/mashape/kong/compare/0.6.0...0.6.1
Expand Down
4 changes: 2 additions & 2 deletions kong-0.8.0-0.rockspec → kong-0.8.1-0.rockspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package = "kong"
version = "0.8.0-0"
version = "0.8.1-0"
supported_platforms = {"linux", "macosx"}
source = {
url = "git://github.com/Mashape/kong",
tag = "0.8.0"
tag = "0.8.1"
}
description = {
summary = "Kong is a scalable and customizable API Management Layer built on top of Nginx.",
Expand Down
2 changes: 1 addition & 1 deletion kong/api/crud_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function _M.put(params, dao_collection)
end
else
-- If entity body has primary key, deal with update
new_entity, err = dao_collection:update(params, true)
new_entity, err = dao_collection:update(params, params, {full = true})
if not err then
return responses.send_HTTP_OK(new_entity)
end
Expand Down
4 changes: 3 additions & 1 deletion kong/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ return {
CREDENTIAL_USERNAME = "X-Credential-Username",
RATELIMIT_LIMIT = "X-RateLimit-Limit",
RATELIMIT_REMAINING = "X-RateLimit-Remaining",
CONSUMER_GROUPS = "X-Consumer-Groups"
CONSUMER_GROUPS = "X-Consumer-Groups",
FORWARDED_HOST = "X-Forwarded-Host",
FORWARDED_PREFIX = "X-Forwarded-Prefix"
},
RATELIMIT = {
PERIODS = {
Expand Down
2 changes: 2 additions & 0 deletions kong/core/resolver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ local function find_api(uri, headers)
api, matched_host, hosts_list = _M.find_api_by_request_host(headers, apis_dics)
-- If it was found by Host, return
if api then
ngx.req.set_header(constants.HEADERS.FORWARDED_HOST, matched_host)
return nil, api, matched_host, hosts_list
end

Expand Down Expand Up @@ -240,6 +241,7 @@ function _M.execute(request_uri, request_headers)
-- If API was retrieved by request_path and the request_path needs to be stripped
if strip_request_path_pattern and api.strip_request_path then
uri = _M.strip_request_path(uri, strip_request_path_pattern, url_has_path(upstream_url))
ngx.req.set_header(constants.HEADERS.FORWARDED_PREFIX, api.request_path)
end

upstream_url = upstream_url..uri
Expand Down
24 changes: 10 additions & 14 deletions kong/dao/dao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,25 @@ end
-- be updated. If asked, can perform a "full" update, replacing the entire entity (assuming it is valid)
-- with the one specified in `tbl` at once.
-- @param[type=table] tbl A table containing the new values for this row.
-- @param[tye=table] filter_keys A table containing the values to select the row to be updated.
-- @param[tye=table] filter_keys A table which must contain the primary key(s) to select the row to be updated.
-- @param[type=table] options Options to use for this update. (`full`: performs a full update of the entity).
-- @treturn table res A table representing the updated entity.
-- @treturn table err If an error occured, a table describing the issue.
function DAO:update(tbl, filter_keys, options)
check_arg(tbl, 1, "table")
check_not_empty(tbl, 1)
check_arg(filter_keys, 2, "table")
check_not_empty(filter_keys, 2)
options = options or {}

local full_update = false
if type(filter_keys) ~= "boolean" then
check_arg(filter_keys, 2, "table")
check_not_empty(filter_keys, 2)
for k, v in pairs(filter_keys) do
if tbl[k] == nil then
tbl[k] = v
end
for k, v in pairs(filter_keys) do
if tbl[k] == nil then
tbl[k] = v
end
else
full_update = filter_keys
end

local model = self.model_mt(tbl)
local ok, err = model:validate {dao = self, update = true, full_update = full_update}
local ok, err = model:validate {dao = self, update = true, full_update = options.full}
if not ok then
return nil, err
end
Expand All @@ -261,11 +257,11 @@ function DAO:update(tbl, filter_keys, options)
return
end

if not full_update then
if not options.full then
fix(old, values, self.schema)
end

local res, err = self.db:update(self.table, self.schema, self.constraints, primary_keys, values, nils, full_update, model, options)
local res, err = self.db:update(self.table, self.schema, self.constraints, primary_keys, values, nils, options.full, model, options)
if err then
return nil, err
elseif res then
Expand Down
2 changes: 1 addition & 1 deletion kong/dao/migrations/cassandra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ return {

for _, row in ipairs(rows) do
row.consumer_id = nil
local _, err = dao.plugins:update(row, true)
local _, err = dao.plugins:update(row, row, {full = true})
if err then
return err
end
Expand Down
4 changes: 2 additions & 2 deletions kong/dao/schemas/apis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ return {
table = "apis",
primary_key = {"id"},
fields = {
id = {type = "id", dao_insert_value = true},
created_at = {type = "timestamp", immutable = true, dao_insert_value = true},
id = {type = "id", dao_insert_value = true, required = true},
created_at = {type = "timestamp", immutable = true, dao_insert_value = true, required = true},
name = {type = "string", unique = true, default = default_name, func = check_name},
request_host = {type = "string", unique = true, func = check_request_host},
request_path = {type = "string", unique = true, func = check_request_path},
Expand Down
8 changes: 4 additions & 4 deletions kong/dao/schemas/consumers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ return {
table = "consumers",
primary_key = {"id"},
fields = {
id = { type = "id", dao_insert_value = true },
created_at = { type = "timestamp", immutable = true, dao_insert_value = true },
custom_id = { type = "string", unique = true, func = check_custom_id_and_username },
username = { type = "string", unique = true, func = check_custom_id_and_username }
id = {type = "id", dao_insert_value = true, required = true},
created_at = {type = "timestamp", immutable = true, dao_insert_value = true, required = true},
custom_id = {type = "string", unique = true, func = check_custom_id_and_username},
username = {type = "string", unique = true, func = check_custom_id_and_username}
},
marshall_event = function(self, t)
return { id = t.id }
Expand Down
6 changes: 3 additions & 3 deletions kong/dao/schemas/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ return {
table = "nodes",
primary_key = {"name"},
fields = {
name = { type = "string" },
created_at = { type = "timestamp", dao_insert_value = true },
cluster_listening_address = { type = "string", required = true }
name = {type = "string"},
created_at = {type = "timestamp", dao_insert_value = true,required = true},
cluster_listening_address = {type = "string", required = true}
},
marshall_event = function(self, t)
return { name = t.name }
Expand Down
6 changes: 4 additions & 2 deletions kong/dao/schemas/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ return {
fields = {
id = {
type = "id",
dao_insert_value = true
dao_insert_value = true,
required = true
},
created_at = {
type = "timestamp",
immutable = true,
dao_insert_value = true
dao_insert_value = true,
required = true
},
api_id = {
type = "id",
Expand Down
13 changes: 9 additions & 4 deletions kong/dao/schemas_validation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function _M.validate_entity(tbl, schema, options)

-- Check the given table against a given schema
for column, v in pairs(schema.fields) do
-- [TYPE] Check if type is valid. Booleans and Numbers as strings are accepted and converted
-- [TYPE] Check if type is valid. Booleans and Numbers as strings are accepted and converted
if t[column] ~= nil and v.type ~= nil then
local is_valid_type
-- ALIASES: number, timestamp, boolean and array can be passed as strings and will be converted
Expand Down Expand Up @@ -171,7 +171,7 @@ function _M.validate_entity(tbl, schema, options)
for sub_field_k, sub_field in pairs(sub_schema.fields) do
if sub_field.default ~= nil then -- Sub-value has a default, be polite and pre-assign the sub-value
t[column] = {}
elseif sub_field.required then -- Only check required if field doesn't have a default
elseif sub_field.required then -- Only check required if field doesn't have a default and dao_insert_value
errors = utils.add_error(errors, error_prefix..column, column.."."..sub_field_k.." is required")
end
end
Expand All @@ -193,10 +193,15 @@ function _M.validate_entity(tbl, schema, options)
end
end

-- Check that full updates still meet the REQUIRED contraints
if options.full_update and v.required and (t[column] == nil or t[column] == "") then
errors = utils.add_error(errors, error_prefix..column, column.." is required")
end

if not partial_update or t[column] ~= nil then
-- [REQUIRED] Check that required fields are set.
-- Now that default and most other checks have been run.
if v.required and (t[column] == nil or t[column] == "") then
if v.required and not v.dao_insert_value and (t[column] == nil or t[column] == "") then
errors = utils.add_error(errors, error_prefix..column, column.." is required")
end

Expand Down Expand Up @@ -262,4 +267,4 @@ function _M.is_schema_subset(tbl, schema)
return errors == nil, errors
end

return _M
return _M
2 changes: 1 addition & 1 deletion kong/meta.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local version = setmetatable({
major = 0,
minor = 8,
patch = 0,
patch = 1,
--pre_release = "alpha"
}, {
__tostring = function(t)
Expand Down
12 changes: 12 additions & 0 deletions kong/plugins/datadog/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ local gauges = {
request_count = function (api_name, message, logger)
local stat = api_name..".request.count"
logger:counter(stat, 1, 1)
end,
unique_users = function (api_name, message, logger)
if message.authenticated_entity ~= nil and message.authenticated_entity.consumer_id ~= nil then
local stat = api_name..".user.uniques"
logger:set(stat, message.authenticated_entity.consumer_id)
end
end,
request_per_user = function (api_name, message, logger)
if message.authenticated_entity ~= nil and message.authenticated_entity.consumer_id ~= nil then
local stat = api_name.."."..string_gsub(message.authenticated_entity.consumer_id, "-", "_")..".request.count"
logger:counter(stat, 1, 1)
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", "response_size", "unique_users", "request_per_user"}, default = {"request_count", "latency", "request_size", "status_count", "response_size", "unique_users", "request_per_user"}},
timeout = {type = "number", default = 10000}
}
}
3 changes: 3 additions & 0 deletions kong/plugins/datadog/statsd_logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ local ngx_log = ngx.log
local table_concat = table.concat
local setmetatable = setmetatable
local NGX_ERR = ngx.ERR
local NGX_DEBUG = ngx.DEBUG
local tostring = tostring

local statsd_mt = {}
statsd_mt.__index = statsd_mt
Expand Down Expand Up @@ -51,6 +53,7 @@ end

function statsd_mt:send_statsd(stat, delta, kind, sample_rate)
local udp_message = self:create_statsd_message(stat, delta, kind, sample_rate)
ngx_log(NGX_DEBUG, "Sending data to statsd server: "..udp_message)
local ok, err = self.socket:send(udp_message)
if not ok then
ngx_log(NGX_ERR, "failed to send data to "..self.host..":"..tostring(self.port)..": ", err)
Expand Down
4 changes: 2 additions & 2 deletions kong/plugins/mashape-analytics/migrations/cassandra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ return {
plugin.config.port = plugin.config.port or schema.fields.port.default
plugin.config.path = plugin.config.path or schema.fields.path.default
plugin.config.max_sending_queue_size = plugin.config.max_sending_queue_size or schema.fields.max_sending_queue_size.default
local _, err = factory.plugins:update(plugin, plugin, true)
local _, err = factory.plugins:update(plugin, plugin, {full = true})
if err then
return err
end
Expand All @@ -31,7 +31,7 @@ return {
plugin.config.port = nil
plugin.config.path = nil
plugin.config.max_sending_queue_size = nil
local _, err = factory.plugins:update(plugin, plugin, true)
local _, err = factory.plugins:update(plugin, plugin, {full = true})
if err then
return err
end
Expand Down
4 changes: 2 additions & 2 deletions kong/plugins/request-transformer/migrations/cassandra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ return {
plugin.config[action].form = nil
end
end
local _, err = factory.plugins:update(plugin, plugin, true)
local _, err = factory.plugins:update(plugin, plugin, {full = true})
if err then
return err
end
Expand Down Expand Up @@ -54,7 +54,7 @@ return {
plugin.config[action] = nil
end
end
local _, err = factory.plugins:update(plugin, plugin, true)
local _, err = factory.plugins:update(plugin, plugin, {full = true})
if err then
return err
end
Expand Down
2 changes: 2 additions & 0 deletions kong/plugins/response-ratelimiting/header_filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ local function parse_header(header_value, limits)
end

function _M.execute(conf)
ngx.ctx.increments = {}

if utils.table_size(conf.limits) <= 0 then
return
end
Expand Down
4 changes: 2 additions & 2 deletions kong/plugins/response-transformer/migrations/cassandra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ return {
plugin.config[action][location] = plugin.config[action][location] or {}
end
end
local _, err = factory.plugins:update(plugin, plugin, true)
local _, err = factory.plugins:update(plugin, plugin, {full = true})
if err then
return err
end
Expand Down Expand Up @@ -44,7 +44,7 @@ return {
end
end

local _, err = factory.plugins:update(plugin, true)
local _, err = factory.plugins:update(plugin, plugin, {full = true})
if err then
return err
end
Expand Down
3 changes: 3 additions & 0 deletions kong/tools/ngx_stub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ _G.ngx = {
req = {
get_headers = function()
return {}
end,
set_header = function()
return {}
end
},
ctx = {},
Expand Down
Loading

0 comments on commit faaa422

Please sign in to comment.