Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(db) connector:close and connector:setkeepalive cleanup #4218

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Table of Contents

- [1.0.2](#102)
- [1.0.1](#101)
- [1.0.0](#100)
- [0.15.0](#0150)
Expand All @@ -21,6 +22,31 @@
- [0.10.0](#0100---20170307)
- [0.9.9 and prior](#099---20170202)

## [1.0.2]

> Released on: 2019/01/17

This is a hotfix release fixing an issue when connecting to Cassandra over TLS.

### Fixes

##### Core

- Fix an issue that would prevent Kong from starting when connecting to
Cassandra over TLS. [#4214](https://github.com/Kong/kong/pull/4214)

##### Plugins

- zipkin
- Fix a logging failure when DNS is not resolved.
[kong-plugin-zipkin@a563f51](https://github.com/Kong/kong-plugin-zipkin/commit/a563f513f943ba0a30f3c69373d9092680a8f670)
- Avoid sending redundant tags.
[kong-plugin-zipkin/pull/28](https://github.com/Kong/kong-plugin-zipkin/pull/28)
- Move `run_on` field to top level plugin schema instead of its config.
[kong-plugin-zipkin/pull/38](https://github.com/Kong/kong-plugin-zipkin/pull/38)

[Back to TOC](#table-of-contents)

## [1.0.1]

> Released on: 2019/01/16
Expand Down Expand Up @@ -3307,6 +3333,7 @@ First version running with Cassandra.

[Back to TOC](#table-of-contents)

[1.0.2]: https://github.com/Kong/kong/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/Kong/kong/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/Kong/kong/compare/0.15.0...1.0.0
[0.15.0]: https://github.com/Kong/kong/compare/0.14.1...0.15.0
Expand Down
6 changes: 3 additions & 3 deletions kong-1.0.1-0.rockspec → kong-1.0.2-0.rockspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package = "kong"
version = "1.0.1-0"
version = "1.0.2-0"
supported_platforms = {"linux", "macosx"}
source = {
url = "git://github.com/Kong/kong",
tag = "1.0.1"
tag = "1.0.2"
}
description = {
summary = "Kong is a scalable and customizable API Management Layer built on top of Nginx.",
Expand Down Expand Up @@ -34,7 +34,7 @@ dependencies = {
"lua-resty-mediador == 0.1.2",
"lua-resty-healthcheck == 0.6.0",
"lua-resty-cookie == 0.1.0",
"lua-resty-mlcache == 2.2.0",
"lua-resty-mlcache == 2.3.0",
-- external Kong plugins
"kong-plugin-azure-functions ~> 0.3",
"kong-plugin-zipkin ~> 0.1",
Expand Down
130 changes: 98 additions & 32 deletions kong/api/endpoints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ local kong = kong
local escape_uri = ngx.escape_uri
local unescape_uri = ngx.unescape_uri
local tonumber = tonumber
local tostring = tostring
local select = select
local concat = table.concat
local null = ngx.null
local type = type
local fmt = string.format
Expand All @@ -29,10 +32,74 @@ local ERRORS_HTTP_CODES = {
}


local function get_message(default, ...)
local message
local n = select("#", ...)
if n > 0 then
if n == 1 then
local arg = select(1, ...)
if type(arg) == "table" then
message = arg
elseif arg ~= nil then
message = tostring(arg)
end

else
message = {}
for i = 1, n do
local arg = select(i, ...)
message[i] = tostring(arg)
end
message = concat(message)
end
end

if not message then
message = default
end

if type(message) == "string" then
message = { message = message }
end

return message
end


local function ok(...)
return kong.response.exit(200, get_message(nil, ...))
end


local function created(...)
return kong.response.exit(201, get_message(nil, ...))
end


local function no_content()
return kong.response.exit(204)
end


local function not_found(...)
return kong.response.exit(404, get_message("Not found", ...))
end


local function method_not_allowed(...)
return kong.response.exit(405, get_message("Method not allowed", ...))
end


local function unexpected(...)
return kong.response.exit(500, get_message("An unexpected error occurred", ...))
end


local function handle_error(err_t)
if type(err_t) ~= "table" then
kong.log.err(err_t)
kong.response.exit(500, { message = "An unexpected error occurred" })
return unexpected()
end

if err_t.strategy then
Expand Down Expand Up @@ -191,19 +258,20 @@ local function get_collection_endpoint(schema, foreign_schema, foreign_field_nam
schema.name,
escape_uri(offset)) or null

return kong.response.exit(200, {
return ok {
data = data,
offset = offset,
next = next_page,
})
}

end or function(self, db, helpers)
local foreign_entity, _, err_t = select_entity(self, db, foreign_schema)
if err_t then
return handle_error(err_t)
end

if not foreign_entity then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

self.params[schema.name] = foreign_schema:extract_pk_values(foreign_entity)
Expand All @@ -219,11 +287,11 @@ local function get_collection_endpoint(schema, foreign_schema, foreign_field_nam
foreign_key, schema.name, escape_uri(offset)) or null


return kong.response.exit(200, {
return ok {
data = data,
offset = offset,
next = next_page,
})
}
end
end

Expand All @@ -247,7 +315,7 @@ local function post_collection_endpoint(schema, foreign_schema, foreign_field_na
end

if not foreign_entity then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

self.args.post[foreign_field_name] = foreign_schema:extract_pk_values(foreign_entity)
Expand All @@ -265,7 +333,7 @@ local function post_collection_endpoint(schema, foreign_schema, foreign_field_na
end
end

return kong.response.exit(201, entity)
return created(entity)
end
end

Expand Down Expand Up @@ -294,13 +362,13 @@ local function get_entity_endpoint(schema, foreign_schema, foreign_field_name, m
end

if not entity then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

if foreign_schema then
local pk = entity[foreign_field_name]
if not pk or pk == null then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

self.params[foreign_schema.name] = pk
Expand All @@ -311,11 +379,11 @@ local function get_entity_endpoint(schema, foreign_schema, foreign_field_name, m
end

if not entity then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end
end

return kong.response.exit(200, entity)
return ok(entity)
end
end

Expand All @@ -338,10 +406,10 @@ local function put_entity_endpoint(schema, foreign_schema, foreign_field_name, m
end

if not entity then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

return kong.response.exit(200, entity)
return ok(entity)

end or function(self, db, helpers)
local entity, _, err_t = select_entity(self, db, schema)
Expand All @@ -350,12 +418,12 @@ local function put_entity_endpoint(schema, foreign_schema, foreign_field_name, m
end

if not entity then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

local pk = entity[foreign_field_name]
if not pk or pk == null then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

self.params[foreign_schema.name] = pk
Expand All @@ -366,10 +434,10 @@ local function put_entity_endpoint(schema, foreign_schema, foreign_field_name, m
end

if not entity then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

return kong.response.exit(200, entity)
return ok(entity)
end
end

Expand All @@ -392,10 +460,10 @@ local function patch_entity_endpoint(schema, foreign_schema, foreign_field_name,
end

if not entity then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

return kong.response.exit(200, entity)
return ok(entity)

end or function(self, db, helpers)
local entity, _, err_t = select_entity(self, db, schema)
Expand All @@ -404,12 +472,12 @@ local function patch_entity_endpoint(schema, foreign_schema, foreign_field_name,
end

if not entity then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

local pk = entity[foreign_field_name]
if not pk or pk == null then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

self.params[foreign_schema.name] = pk
Expand All @@ -420,10 +488,10 @@ local function patch_entity_endpoint(schema, foreign_schema, foreign_field_name,
end

if not entity then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

return kong.response.exit(200, entity)
return ok(entity)
end
end

Expand All @@ -445,7 +513,7 @@ local function delete_entity_endpoint(schema, foreign_schema, foreign_field_name
return handle_error(err_t)
end

return kong.response.exit(204)
return no_content()

end or function(self, db, helpers)
local entity, _, err_t = select_entity(self, db, schema)
Expand All @@ -455,10 +523,10 @@ local function delete_entity_endpoint(schema, foreign_schema, foreign_field_name

local id = entity and entity[foreign_field_name]
if not id or id == null then
return kong.response.exit(404, { message = "Not found" })
return not_found()
end

return kong.response.exit(405, { message = "Method not allowed" })
return method_not_allowed()
end
end

Expand Down Expand Up @@ -547,15 +615,13 @@ end

-- A reusable handler for endpoints that are deactivated
-- (e.g. /targets/:targets)
local not_found = {
before = function()
return kong.response.exit(404, { message = "Not found" })
end
local disable = {
before = not_found
}


local Endpoints = {
not_found = not_found,
disable = disable,
handle_error = handle_error,
get_page_size = get_page_size,
extract_options = extract_options,
Expand Down
15 changes: 8 additions & 7 deletions kong/api/routes/cache.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local singletons = require "kong.singletons"
local kong = kong


return {
["/cache/:key"] = {
GET = function(self, _, helpers)
GET = function(self)
-- probe the cache to see if a key has been requested before

local ttl, err, value = singletons.cache:probe(self.params.key)
local ttl, err, value = kong.cache:probe(self.params.key)
if err then
kong.log.err(err)
return kong.response.exit(500, { message = "An unexpected error happened" })
Expand All @@ -18,16 +19,16 @@ return {
return kong.response.exit(404, { message = "Not found" })
end,

DELETE = function(self, _, helpers)
singletons.cache:invalidate_local(self.params.key)
DELETE = function(self)
kong.cache:invalidate_local(self.params.key)

return kong.response.exit(204) -- no content
end,
},

["/cache"] = {
DELETE = function(self, _, helpers)
singletons.cache:purge()
DELETE = function()
kong.cache:purge()

return kong.response.exit(204) -- no content
end,
Expand Down
Loading