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

feature: PostgreSQL support #1054

Merged
merged 54 commits into from
Mar 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f1834da
feat(postgres) create default postgres config opts
thibaultcha Jan 19, 2016
1b2bf79
wip(postgres) setting up Abstract classes
thibaultcha Jan 20, 2016
660c059
wip(postgres) unifying the DAOs interfaces
thibaultcha Jan 23, 2016
72a900f
[wip] refactor(dao) new architecture, drop abstract pattern
thibaultcha Jan 26, 2016
44d9765
[wip] refactor(dao) full support for migrations
thibaultcha Jan 28, 2016
eba2d90
[wip] feat(dao) first db-agnostic insert
thibaultcha Feb 5, 2016
2934a1b
feat(dao) find() selects by PRIMARY KEY
thibaultcha Feb 8, 2016
9852da2
feat(dao) find_all() and count()
thibaultcha Feb 9, 2016
4e7ba42
feat(dao) find_page()
thibaultcha Feb 9, 2016
fcf16d3
feat(dao) update() support for Postgres
thibaultcha Feb 11, 2016
831c293
feat(dao) update() for Cassandra
thibaultcha Feb 11, 2016
837ee0d
refactor(dao) extract_keys() from DAO/Model
thibaultcha Feb 11, 2016
59102f2
feat(dao) delete() without CASCADING
thibaultcha Feb 11, 2016
59d576d
feat(dao) foreign and unique constraints checks
thibaultcha Feb 17, 2016
6889daa
feat(dao) CASCADE delete support for Cassandra
thibaultcha Feb 18, 2016
d67a6ff
feat(dao) real_use_cases_spec
thibaultcha Feb 18, 2016
c60c5a5
feat(dao) Compat with /apis/
thibaultcha Feb 22, 2016
7047cc1
specs(dao) fix pagination spec
thibaultcha Feb 23, 2016
32f0f4d
feat(dao) compatible /consumers/
thibaultcha Feb 23, 2016
e3f8d71
feat(dao) compatibility for /plugins/
thibaultcha Feb 23, 2016
2c25fc7
feat(dao) cache tests fixed for new DAO
thibaultcha Feb 23, 2016
7b26133
feat(dao) all plugins migrations + key-auth daos_specs
thibaultcha Feb 23, 2016
14827ae
feat(dao) making API and access specs pass for most plugins
thibaultcha Feb 23, 2016
00dabd9
fix(specs) fixes due to recent changes
thibaultcha Feb 24, 2016
8f35994
Fixing cluster
subnetmarco Feb 24, 2016
84c17c5
Sending events for associated entities on a delete
subnetmarco Feb 24, 2016
a0246be
Test
subnetmarco Feb 24, 2016
6415809
feat(dao) postgres rate-limiting
thibaultcha Feb 25, 2016
83aec54
feat(dao) postgres response-ratelimiting
thibaultcha Feb 25, 2016
44533a9
fix(dao) count for rate limiting tables
thibaultcha Feb 25, 2016
9b8806a
specs: fixinf a few tests broken with DAO changes
thibaultcha Feb 26, 2016
340965d
feat(dao) remove old hack involving a "nil uuid" for plugins
thibaultcha Feb 26, 2016
7083fbd
drop outdated 'queryable' schema property
thibaultcha Feb 26, 2016
dcee584
style(lint) fix all linting errors and improve migrations cmd
thibaultcha Feb 26, 2016
badfecb
fix: updating unit specs and rockspec
thibaultcha Feb 26, 2016
2de49e7
chore(ci) postgres travis-ci
thibaultcha Feb 29, 2016
4f0ea5e
Cassandra TTL
subnetmarco Mar 1, 2016
e77dda6
Properly handle timestamps in Postgres
subnetmarco Mar 2, 2016
6e9b57e
Enforcing TTL on SELECT
subnetmarco Mar 2, 2016
149fc47
cleanup: linting, inspect and tests failures
thibaultcha Mar 2, 2016
2a47ba9
Finalizing TTL
subnetmarco Mar 3, 2016
47a22e7
Making UPSERT 9.4.x compatible
subnetmarco Mar 3, 2016
00949ae
fix(plugins_iter) deterministic plugin retrieval with C*
thibaultcha Mar 4, 2016
85a60d9
Fixing tests
subnetmarco Mar 4, 2016
6cccd81
Fixing tests, part 1
subnetmarco Mar 5, 2016
a77ca12
Fixing migration script
subnetmarco Mar 5, 2016
f66f063
fix(dao) check for primary keys before cascade deleting
thibaultcha Mar 5, 2016
ec0755e
chore(ci) purge tree before installing Kong
thibaultcha Mar 7, 2016
1b0237d
chore(ci) always run Postgres db initialization
thibaultcha Mar 7, 2016
dcece51
Fixing OAuth 2.0 tests
subnetmarco Mar 7, 2016
be11cbc
Fixing rate-limiting tests
subnetmarco Mar 7, 2016
f141eb7
Wait for processes to exit in specs
subnetmarco Mar 8, 2016
ae4bc10
Fixing specs for both Cassandra and Postgres
subnetmarco Mar 8, 2016
f28d4da
docs(changelog) add unreleased changes for 0.8.0
thibaultcha Mar 10, 2016
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
9 changes: 9 additions & 0 deletions .ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

set -e

if [ "$TEST_SUITE" == "unit" ]; then
kong config -c kong.yml -e TEST -s TEST
else
kong config -c kong.yml -d $DATABASE -e TEST -s TEST
fi

createuser --createdb kong
createdb -U kong kong_tests

CMD="busted -v -o gtest --exclude-tags=ci"

if [ "$TEST_SUITE" == "unit" ]; then
Expand Down
2 changes: 1 addition & 1 deletion .ci/setup_cassandra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

if [ "$TEST_SUITE" == "unit" ]; then
echo "Exiting, no integration tests"
echo "Exiting, no need for Cassandra"
exit
fi

Expand Down
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
redefined = false
unused_args = false
globals = {"ngx", "dao", "app", "configuration", "events", "serf"}
globals = {"ngx", "app"}

files["kong/"] = {
std = "luajit"
Expand Down
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ sudo: false
notifications:
email: false
addons:
postgresql: "9.4"
apt:
packages:
- sed
Expand All @@ -27,16 +28,22 @@ env:
matrix:
- TEST_SUITE=unit
- TEST_SUITE=integration
DATABASE=cassandra
- TEST_SUITE=plugins
DATABASE=cassandra
- TEST_SUITE=integration
DATABASE=postgres
- TEST_SUITE=plugins
DATABASE=postgres
before_install:
- source .ci/setenv_kong.sh
- bash .ci/setup_cassandra.sh
install:
- luarocks purge --tree=$LUAROCKS_DIR
- luarocks install busted
- luarocks install luacov-coveralls
- luarocks install luacheck
- luarocks make kong-*.rockspec
- "kong config -c kong.yml -e TEST"
- luarocks make
script:
- make lint
- .ci/run_tests.sh
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## [Unreleased][unreleased]

### Added

- Support for PostgreSQL as Kong's primary datastore. [#331](https://github.com/Mashape/kong/issues/331) [#1054](https://github.com/Mashape/kong/issues/1054)
- Configurable Cassandra reading/writing consistency. [#1026](https://github.com/Mashape/kong/pull/1026)
- Admin API: oncluding pending and running timers count in the response to `/`. [#992](https://github.com/Mashape/kong/pull/992)

## [0.7.0] - 2016/02/24

### Breaking changes
Expand Down Expand Up @@ -526,4 +532,4 @@ First version running with Cassandra.
[0.2.0-2]: https://github.com/mashape/kong/compare/0.1.1beta-2...0.2.0-2
[0.1.1beta-2]: https://github.com/mashape/kong/compare/0.1.0beta-3...0.1.1beta-2
[0.1.0beta-3]: https://github.com/mashape/kong/compare/2236374d5624ad98ea21340ca685f7584ec35744...0.1.0beta-3
[0.0.1alpha-1]: https://github.com/mashape/kong/compare/ffd70b3101ba38d9acc776038d124f6e2fccac3c...2236374d5624ad98ea21340ca685f7584ec35744
[0.0.1alpha-1]: https://github.com/mashape/kong/compare/ffd70b3101ba38d9acc776038d124f6e2fccac3c...2236374d5624ad98ea21340ca685f7584ec35744
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ test-plugins:
test-all:
@busted -v spec/

test-model:
@busted -v -o gtest spec/integration/model

test-model-only:
@busted -v -o gtest --tags=only spec/integration/model

coverage:
@rm -f luacov.*
@busted --coverage spec/
@luacov -c spec/.luacov
@tail -n 1 luacov.report.out | awk '{ print $$3 }'
@tail -n 1 luacov.report.out | awk '{ print $$3 }'
51 changes: 30 additions & 21 deletions kong-0.7.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = {
"lapis ~> 1.3.1-1",
"stringy ~> 0.4-1",
"lua-cassandra ~> 0.5.0",
"pgmoon ~> 1.4.0",
"multipart ~> 0.2-1",
"lua-path ~> 0.2.3-1",
"lua-cjson ~> 2.1.0-1",
Expand Down Expand Up @@ -75,7 +76,6 @@ build = {
["kong.tools.cluster"] = "kong/tools/cluster.lua",
["kong.tools.responses"] = "kong/tools/responses.lua",
["kong.tools.timestamp"] = "kong/tools/timestamp.lua",
["kong.tools.migrations"] = "kong/tools/migrations.lua",
["kong.tools.http_client"] = "kong/tools/http_client.lua",
["kong.tools.database_cache"] = "kong/tools/database_cache.lua",
["kong.tools.config_defaults"] = "kong/tools/config_defaults.lua",
Expand All @@ -92,21 +92,20 @@ build = {
["kong.core.events"] = "kong/core/events.lua",
["kong.core.error_handlers"] = "kong/core/error_handlers.lua",

["kong.dao.cassandra.schema.migrations"] = "kong/dao/cassandra/schema/migrations.lua",
["kong.dao.error"] = "kong/dao/error.lua",
["kong.dao.errors"] = "kong/dao/errors.lua",
["kong.dao.schemas_validation"] = "kong/dao/schemas_validation.lua",
["kong.dao.schemas.apis"] = "kong/dao/schemas/apis.lua",
["kong.dao.schemas.nodes"] = "kong/dao/schemas/nodes.lua",
["kong.dao.schemas.consumers"] = "kong/dao/schemas/consumers.lua",
["kong.dao.schemas.plugins"] = "kong/dao/schemas/plugins.lua",
["kong.dao.cassandra.factory"] = "kong/dao/cassandra/factory.lua",
["kong.dao.cassandra.query_builder"] = "kong/dao/cassandra/query_builder.lua",
["kong.dao.cassandra.base_dao"] = "kong/dao/cassandra/base_dao.lua",
["kong.dao.cassandra.migrations"] = "kong/dao/cassandra/migrations.lua",
["kong.dao.cassandra.apis"] = "kong/dao/cassandra/apis.lua",
["kong.dao.cassandra.nodes"] = "kong/dao/cassandra/nodes.lua",
["kong.dao.cassandra.consumers"] = "kong/dao/cassandra/consumers.lua",
["kong.dao.cassandra.plugins"] = "kong/dao/cassandra/plugins.lua",
["kong.dao.base_db"] = "kong/dao/base_db.lua",
["kong.dao.cassandra_db"] = "kong/dao/cassandra_db.lua",
["kong.dao.postgres_db"] = "kong/dao/postgres_db.lua",
["kong.dao.dao"] = "kong/dao/dao.lua",
["kong.dao.factory"] = "kong/dao/factory.lua",
["kong.dao.model_factory"] = "kong/dao/model_factory.lua",
["kong.dao.migrations.cassandra"] = "kong/dao/migrations/cassandra.lua",
["kong.dao.migrations.postgres"] = "kong/dao/migrations/postgres.lua",

["kong.api.app"] = "kong/api/app.lua",
["kong.api.crud_helpers"] = "kong/api/crud_helpers.lua",
Expand All @@ -119,7 +118,8 @@ build = {

["kong.plugins.base_plugin"] = "kong/plugins/base_plugin.lua",

["kong.plugins.basic-auth.schema.migrations"] = "kong/plugins/basic-auth/schema/migrations.lua",
["kong.plugins.basic-auth.migrations.cassandra"] = "kong/plugins/basic-auth/migrations/cassandra.lua",
["kong.plugins.basic-auth.migrations.postgres"] = "kong/plugins/basic-auth/migrations/postgres.lua",
["kong.plugins.basic-auth.crypto"] = "kong/plugins/basic-auth/crypto.lua",
["kong.plugins.basic-auth.handler"] = "kong/plugins/basic-auth/handler.lua",
["kong.plugins.basic-auth.access"] = "kong/plugins/basic-auth/access.lua",
Expand All @@ -128,14 +128,16 @@ build = {
["kong.plugins.basic-auth.api"] = "kong/plugins/basic-auth/api.lua",
["kong.plugins.basic-auth.daos"] = "kong/plugins/basic-auth/daos.lua",

["kong.plugins.key-auth.schema.migrations"] = "kong/plugins/key-auth/schema/migrations.lua",
["kong.plugins.key-auth.migrations.cassandra"] = "kong/plugins/key-auth/migrations/cassandra.lua",
["kong.plugins.key-auth.migrations.postgres"] = "kong/plugins/key-auth/migrations/postgres.lua",
["kong.plugins.key-auth.handler"] = "kong/plugins/key-auth/handler.lua",
["kong.plugins.key-auth.hooks"] = "kong/plugins/key-auth/hooks.lua",
["kong.plugins.key-auth.schema"] = "kong/plugins/key-auth/schema.lua",
["kong.plugins.key-auth.api"] = "kong/plugins/key-auth/api.lua",
["kong.plugins.key-auth.daos"] = "kong/plugins/key-auth/daos.lua",

["kong.plugins.oauth2.schema.migrations"] = "kong/plugins/oauth2/schema/migrations.lua",
["kong.plugins.oauth2.migrations.cassandra"] = "kong/plugins/oauth2/migrations/cassandra.lua",
["kong.plugins.oauth2.migrations.postgres"] = "kong/plugins/oauth2/migrations/postgres.lua",
["kong.plugins.oauth2.handler"] = "kong/plugins/oauth2/handler.lua",
["kong.plugins.oauth2.access"] = "kong/plugins/oauth2/access.lua",
["kong.plugins.oauth2.hooks"] = "kong/plugins/oauth2/hooks.lua",
Expand Down Expand Up @@ -168,18 +170,22 @@ build = {
["kong.plugins.mashape-analytics.schema"] = "kong/plugins/mashape-analytics/schema.lua",
["kong.plugins.mashape-analytics.buffer"] = "kong/plugins/mashape-analytics/buffer.lua",

["kong.plugins.rate-limiting.schema.migrations"] = "kong/plugins/rate-limiting/schema/migrations.lua",
["kong.plugins.rate-limiting.migrations.cassandra"] = "kong/plugins/rate-limiting/migrations/cassandra.lua",
["kong.plugins.rate-limiting.migrations.postgres"] = "kong/plugins/rate-limiting/migrations/postgres.lua",
["kong.plugins.rate-limiting.handler"] = "kong/plugins/rate-limiting/handler.lua",
["kong.plugins.rate-limiting.schema"] = "kong/plugins/rate-limiting/schema.lua",
["kong.plugins.rate-limiting.daos"] = "kong/plugins/rate-limiting/daos.lua",
["kong.plugins.rate-limiting.dao.cassandra"] = "kong/plugins/rate-limiting/dao/cassandra.lua",
["kong.plugins.rate-limiting.dao.postgres"] = "kong/plugins/rate-limiting/dao/postgres.lua",

["kong.plugins.response-ratelimiting.schema.migrations"] = "kong/plugins/response-ratelimiting/schema/migrations.lua",
["kong.plugins.response-ratelimiting.migrations.cassandra"] = "kong/plugins/response-ratelimiting/migrations/cassandra.lua",
["kong.plugins.response-ratelimiting.migrations.postgres"] = "kong/plugins/response-ratelimiting/migrations/postgres.lua",
["kong.plugins.response-ratelimiting.handler"] = "kong/plugins/response-ratelimiting/handler.lua",
["kong.plugins.response-ratelimiting.access"] = "kong/plugins/response-ratelimiting/access.lua",
["kong.plugins.response-ratelimiting.header_filter"] = "kong/plugins/response-ratelimiting/header_filter.lua",
["kong.plugins.response-ratelimiting.log"] = "kong/plugins/response-ratelimiting/log.lua",
["kong.plugins.response-ratelimiting.schema"] = "kong/plugins/response-ratelimiting/schema.lua",
["kong.plugins.response-ratelimiting.daos"] = "kong/plugins/response-ratelimiting/daos.lua",
["kong.plugins.response-ratelimiting.dao.cassandra"] = "kong/plugins/response-ratelimiting/dao/cassandra.lua",
["kong.plugins.response-ratelimiting.dao.postgres"] = "kong/plugins/response-ratelimiting/dao/postgres.lua",

["kong.plugins.request-size-limiting.handler"] = "kong/plugins/request-size-limiting/handler.lua",
["kong.plugins.request-size-limiting.schema"] = "kong/plugins/request-size-limiting/schema.lua",
Expand All @@ -203,7 +209,8 @@ build = {
["kong.plugins.ip-restriction.handler"] = "kong/plugins/ip-restriction/handler.lua",
["kong.plugins.ip-restriction.schema"] = "kong/plugins/ip-restriction/schema.lua",

["kong.plugins.acl.schema.migrations"] = "kong/plugins/acl/schema/migrations.lua",
["kong.plugins.acl.migrations.cassandra"] = "kong/plugins/acl/migrations/cassandra.lua",
["kong.plugins.acl.migrations.postgres"] = "kong/plugins/acl/migrations/postgres.lua",
["kong.plugins.acl.handler"] = "kong/plugins/acl/handler.lua",
["kong.plugins.acl.schema"] = "kong/plugins/acl/schema.lua",
["kong.plugins.acl.hooks"] = "kong/plugins/acl/hooks.lua",
Expand All @@ -220,15 +227,17 @@ build = {
["kong.api.routes.cache"] = "kong/api/routes/cache.lua",
["kong.api.routes.cluster"] = "kong/api/routes/cluster.lua",

["kong.plugins.jwt.schema.migrations"] = "kong/plugins/jwt/schema/migrations.lua",
["kong.plugins.jwt.migrations.cassandra"] = "kong/plugins/jwt/migrations/cassandra.lua",
["kong.plugins.jwt.migrations.postgres"] = "kong/plugins/jwt/migrations/postgres.lua",
["kong.plugins.jwt.handler"] = "kong/plugins/jwt/handler.lua",
["kong.plugins.jwt.schema"] = "kong/plugins/jwt/schema.lua",
["kong.plugins.jwt.hooks"] = "kong/plugins/jwt/hooks.lua",
["kong.plugins.jwt.api"] = "kong/plugins/jwt/api.lua",
["kong.plugins.jwt.daos"] = "kong/plugins/jwt/daos.lua",
["kong.plugins.jwt.jwt_parser"] = "kong/plugins/jwt/jwt_parser.lua",

["kong.plugins.hmac-auth.schema.migrations"] = "kong/plugins/hmac-auth/schema/migrations.lua",
["kong.plugins.hmac-auth.migrations.cassandra"] = "kong/plugins/hmac-auth/migrations/cassandra.lua",
["kong.plugins.hmac-auth.migrations.postgres"] = "kong/plugins/hmac-auth/migrations/postgres.lua",
["kong.plugins.hmac-auth.handler"] = "kong/plugins/hmac-auth/handler.lua",
["kong.plugins.hmac-auth.access"] = "kong/plugins/hmac-auth/access.lua",
["kong.plugins.hmac-auth.schema"] = "kong/plugins/hmac-auth/schema.lua",
Expand Down
10 changes: 9 additions & 1 deletion kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@
## Specify which database to use. Only "cassandra" is currently available.
# database: cassandra

######
## PostgreSQL configuration
# postgres:
# host: "127.0.0.1"
# port: 5432
# user: kong
# database: kong

######
## Cassandra configuration (keyspace, authentication, client-to-node encryption)
# cassandra:
Expand Down Expand Up @@ -130,7 +138,7 @@
#####
## Consistency level to use.
## See http://docs.datastax.com/en/cassandra/2.0/cassandra/dml/dml_config_consistency_c.html
# consistency: ONE
# consistency: ONE

#####
## Client-to-node TLS options.
Expand Down
14 changes: 6 additions & 8 deletions kong/api/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,17 @@ local function normalize_nested_params(obj)
return new_obj
end

local function default_on_error(self)
local function on_error(self)
local err = self.errors[1]
if type(err) == "table" then
if err.database then
if err.db then
return responses.send_HTTP_INTERNAL_SERVER_ERROR(err.message)
elseif err.unique then
return responses.send_HTTP_CONFLICT(err.message)
return responses.send_HTTP_CONFLICT(err.tbl)
elseif err.foreign then
return responses.send_HTTP_NOT_FOUND(err.message)
elseif err.invalid_type and err.message.id then
return responses.send_HTTP_BAD_REQUEST(err.message)
return responses.send_HTTP_NOT_FOUND(err.tbl)
else
return responses.send_HTTP_BAD_REQUEST(err.message)
return responses.send_HTTP_BAD_REQUEST(err.tbl or err.message)
end
end
end
Expand Down Expand Up @@ -126,7 +124,7 @@ local handler_helpers = {
local function attach_routes(routes)
for route_path, methods in pairs(routes) do
if not methods.on_error then
methods.on_error = default_on_error
methods.on_error = on_error
end

for k, v in pairs(methods) do
Expand Down
Loading