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

feat(init) checking that core shared dictionaries exist #2466

Closed
wants to merge 4 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
- Serf commands executed by a running Kong node are now logged in the Nginx
error logs with a `DEBUG` level.
[#2410](https://github.com/Mashape/kong/pull/2410)
- Checking that core Lua shared dictionaries are declared in the configuration.
[#2466](https://github.com/Mashape/kong/pull/2466)
- Plugins:
- :fireworks: **New Request termination plugin**. This plugin allows to
temporarily disable an API and return a pre-configured response status and
Expand Down
3 changes: 2 additions & 1 deletion kong/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ return {
},
CACHE = {
CLUSTER = "cluster"
}
},
DICTS = { "kong", "cache", "cache_locks", "process_events", "cassandra"}
}
9 changes: 9 additions & 0 deletions kong/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ end
local Kong = {}

function Kong.init()
-- Check shared dictionaries
for _, dict in ipairs(constants.DICTS) do
if not ngx.shared[dict] then
error("missing shared dict in Nginx configuration, are you "..
"using a custom template? Make sure the 'lua_shared_dict "..
dict.." [SIZE];' directive is defined.")
end
end

local pl_path = require "pl.path"
local conf_loader = require "kong.conf_loader"

Expand Down
23 changes: 23 additions & 0 deletions spec/02-integration/01-cmd/02-start_stop_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,28 @@ describe("kong start/stop", function()

assert(kill.is_running(helpers.test_conf.nginx_pid))
end)
it("checks that the shared dictionaries exist", function()
local constants = require "kong.constants"
local pl_file = require "pl.file"

local templ_fixture = "spec/fixtures/custom_nginx.template"
local new_templ_fixture = "spec/fixtures/custom_nginx.template.tmp"

for _, dict in ipairs(constants.DICTS) do
-- Remove shared dictionary entry
assert(os.execute(
"sed '/lua_shared_dict "..dict.." .*;/d' "..templ_fixture.." > "
..new_templ_fixture))

local _, stderr = helpers.kong_exec("start --nginx-conf "
..new_templ_fixture)
assert.matches(
"missing shared dict in Nginx configuration, "..
"are you using a custom template? Make sure the 'lua_shared_dict "
..dict.." [SIZE];' directive is defined.", stderr, nil, true)
end

pl_file.delete(new_templ_fixture)
end)
end)
end)