Skip to content

Commit

Permalink
Merge pull request #306 from 3scale/loading-configuration-log
Browse files Browse the repository at this point in the history
[configuration] print better error messages on loading
  • Loading branch information
mikz authored Mar 16, 2017
2 parents 643a58c + c944a88 commit 4934fb8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Use per request configuration when cache is disabled [PR #289](https://github.com/3scale/apicast/pull/289)
- Automatically expose all environment variables starting with `APICAST_` or `THREESCALE_` to nginx [PR #292](https://github.com/3scale/apicast/pull/292)
- Error log to show why downloading configuration failed [PR #306](https://github.com/3scale/apicast/pull/306)

### Added

Expand Down
11 changes: 5 additions & 6 deletions apicast/src/configuration_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ local util = require 'util'
local env = require('resty.env')
local synchronization = require('resty.synchronization').new(1)

local tostring = tostring
local error = error
local len = string.len
local assert = assert
Expand Down Expand Up @@ -77,10 +76,10 @@ function _M.init(cwd)
return config
elseif err then
if code then
ngx.log(ngx.ERR, 'boot could not get configuration, ' .. tostring(err) .. ': '.. tostring(code))
ngx.log(ngx.ERR, 'boot could not get configuration (exit ', code, ')\n', err)
return nil, err
else
ngx.log(ngx.ERR, 'boot failed read: '.. tostring(err))
ngx.log(ngx.ERR, 'boot failed read: ', err)
return nil, err
end
end
Expand All @@ -92,13 +91,13 @@ local boot = {
}

function boot.init(configuration)
local config, err = _M.init()
local init, conferr = _M.configure(configuration, config)
local config = _M.init()
local init = _M.configure(configuration, config)

if config and init then
ngx.log(ngx.DEBUG, 'downloaded configuration: ', config)
else
ngx.log(ngx.EMERG, 'failed to load configuration, exiting: ', err or conferr)
ngx.log(ngx.EMERG, 'failed to load configuration, exiting')
os.exit(1)
end

Expand Down
7 changes: 7 additions & 0 deletions apicast/src/configuration_loader/remote_v2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function _M:call(environment)
local res, err = self:services()

if not res and err then
ngx.log(ngx.WARN, 'failed to get list of services: ', err)
return nil, err
end

Expand Down Expand Up @@ -88,9 +89,12 @@ function _M:services()
local res, err = http_client.get(url)

if not res and err then
ngx.log(ngx.DEBUG, 'services get error: ', err, ' url: ', url)
return nil, err
end

ngx.log(ngx.DEBUG, 'services get status: ', res.status, ' url: ', url)

if res.status == 200 then
local json = cjson.decode(res.body)

Expand Down Expand Up @@ -122,9 +126,12 @@ function _M:config(service, environment, version)
local res, err = http_client.get(url)

if not res and err then
ngx.log(ngx.DEBUG, 'services get error: ', err, ' url: ', url)
return nil, err
end

ngx.log(ngx.DEBUG, 'services get status: ', res.status, ' url: ', url)

if res.status == 200 then
local json = cjson.decode(res.body)

Expand Down
4 changes: 2 additions & 2 deletions t/012-configuration-loading-boot-with-config.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env_to_nginx(
'THREESCALE_CONFIG_FILE'
);

log_level('error');
log_level('warn');
repeat_each(2);
no_root_location();
run_tests();
Expand Down Expand Up @@ -47,7 +47,7 @@ should exit when the file has invalid json
--- request
GET
--- error_log
failed to load configuration, exiting: Expected value but found invalid token at character 1
Expected value but found invalid token at character 1
--- user_files
>>> config.json
not valid json
Expand Down

0 comments on commit 4934fb8

Please sign in to comment.